]> git.stg.codes - stg.git/blob - include/stg/tariff_conf.h
Initial adding of netfilter_queue capturer.
[stg.git] / include / stg / tariff_conf.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Revision: 1.9 $
23  $Date: 2010/10/05 20:41:11 $
24  $Author: faust $
25  */
26
27 #ifndef TARIFF_CONF_H
28 #define TARIFF_CONF_H
29
30 #include "tariff.h"
31 #include "resetable.h"
32 #include "const.h"
33
34 #include <string>
35 #include <vector>
36
37 //-----------------------------------------------------------------------------
38 enum
39 {
40     TRAFF_UP = 0,
41     TRAFF_DOWN,
42     TRAFF_UP_DOWN,
43     TRAFF_MAX
44 };
45 //-----------------------------------------------------------------------------
46 struct DIRPRICE_DATA
47 {
48     DIRPRICE_DATA()
49         : hDay(0),
50           mDay(0),
51           hNight(0),
52           mNight(0),
53           priceDayA(0),
54           priceNightA(0),
55           priceDayB(0),
56           priceNightB(0),
57           threshold(0),
58           singlePrice(0),
59           noDiscount(0)
60         {}
61     int    hDay;
62     int    mDay;
63     int    hNight;
64     int    mNight;
65     double priceDayA;
66     double priceNightA;
67     double priceDayB;
68     double priceNightB;
69     int    threshold;
70     int    singlePrice; // Do not use day/night division
71     int    noDiscount; // Do not use threshold
72 };
73 //-----------------------------------------------------------------------------
74 struct DIRPRICE_DATA_RES
75 {
76     DIRPRICE_DATA_RES()
77         : hDay(),
78           mDay(),
79           hNight(),
80           mNight(),
81           priceDayA(),
82           priceNightA(),
83           priceDayB(),
84           priceNightB(),
85           threshold(),
86           singlePrice(),
87           noDiscount()
88         {}
89
90     DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & rvalue)
91         {
92         hDay        = rvalue.hDay;
93         mDay        = rvalue.mDay;
94         hNight      = rvalue.hNight;
95         mNight      = rvalue.mNight;
96         priceDayA   = rvalue.priceDayA;
97         priceNightA = rvalue.priceNightA;
98         priceDayB   = rvalue.priceDayB;
99         priceNightB = rvalue.priceNightB;
100         threshold   = rvalue.threshold;
101         singlePrice = rvalue.singlePrice;
102         noDiscount  = rvalue.noDiscount;
103         return *this;
104         }
105
106     DIRPRICE_DATA GetData() const
107         {
108         DIRPRICE_DATA dd;
109         dd.hDay        = hDay.data();
110         dd.hNight      = hNight.data();
111         dd.mDay        = mDay.data();
112         dd.mNight      = mNight.data();
113         dd.noDiscount  = noDiscount.data();
114         dd.priceDayA   = priceDayA.data();
115         dd.priceDayB   = priceDayB.data();
116
117         dd.priceNightA = priceNightA.data();
118         dd.priceNightB = priceNightB.data();
119         dd.singlePrice = singlePrice.data();
120         dd.threshold   = threshold.data();
121         return dd;
122         }
123
124     void Splice(const DIRPRICE_DATA_RES & rhs)
125         {
126         hDay.splice(rhs.hDay);
127         mDay.splice(rhs.mDay);
128         hNight.splice(rhs.hNight);
129         mNight.splice(rhs.mNight);
130         priceDayA.splice(rhs.priceDayA);
131         priceNightA.splice(rhs.priceNightA);
132         priceDayB.splice(rhs.priceDayB);
133         priceNightB.splice(rhs.priceNightB);
134         threshold.splice(rhs.threshold);
135         singlePrice.splice(rhs.singlePrice);
136         noDiscount.splice(rhs.noDiscount);
137         }
138
139     RESETABLE<int>    hDay;
140     RESETABLE<int>    mDay;
141     RESETABLE<int>    hNight;
142     RESETABLE<int>    mNight;
143     RESETABLE<double> priceDayA;
144     RESETABLE<double> priceNightA;
145     RESETABLE<double> priceDayB;
146     RESETABLE<double> priceNightB;
147     RESETABLE<int>    threshold;
148     RESETABLE<int>    singlePrice;
149     RESETABLE<int>    noDiscount;
150 };
151 //-----------------------------------------------------------------------------
152 struct TARIFF_CONF
153 {
154     double         fee;
155     double         free;
156     int            traffType;
157     double         passiveCost;
158     std::string    name;
159     TARIFF::PERIOD period;
160
161     TARIFF_CONF()
162         : fee(0),
163           free(0),
164           traffType(TRAFF_UP_DOWN),
165           passiveCost(0),
166           name(),
167           period(TARIFF::MONTH)
168         {}
169
170     TARIFF_CONF(const std::string & n)
171         : fee(0),
172           free(0),
173           traffType(TRAFF_UP_DOWN),
174           passiveCost(0),
175           name(n),
176           period(TARIFF::MONTH)
177         {}
178 };
179 //-----------------------------------------------------------------------------
180 struct TARIFF_CONF_RES
181 {
182     TARIFF_CONF_RES()
183         : fee(),
184           free(),
185           traffType(),
186           passiveCost(),
187           name(),
188           period()
189         {}
190
191     TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc)
192         {
193         fee         = tc.fee;
194         free        = tc.free;
195         traffType   = tc.traffType;
196         passiveCost = tc.passiveCost;
197         name        = tc.name;
198         period      = tc.period;
199         return *this;
200         }
201
202     TARIFF_CONF GetData() const
203         {
204         TARIFF_CONF tc;
205         tc.fee         = fee.data();
206         tc.free        = free.data();
207         tc.name        = name.data();
208         tc.passiveCost = passiveCost.data();
209         tc.traffType   = traffType.data();
210         tc.period      = period.data();
211         return tc;
212         }
213
214     RESETABLE<double>         fee;
215     RESETABLE<double>         free;
216     RESETABLE<int>            traffType;
217     RESETABLE<double>         passiveCost;
218     RESETABLE<std::string>    name;
219     RESETABLE<TARIFF::PERIOD> period;
220 };
221 //-----------------------------------------------------------------------------
222 struct TARIFF_DATA
223 {
224     TARIFF_CONF                tariffConf;
225     std::vector<DIRPRICE_DATA> dirPrice;
226
227     TARIFF_DATA()
228         : tariffConf(),
229           dirPrice(DIR_NUM)
230         {}
231
232     TARIFF_DATA(const std::string & name)
233         : tariffConf(name),
234           dirPrice(DIR_NUM)
235         {}
236
237     TARIFF_DATA(const TARIFF_DATA & td)
238         : tariffConf(td.tariffConf),
239           dirPrice(td.dirPrice)
240         {}
241
242     TARIFF_DATA & operator=(const TARIFF_DATA & td)
243         {
244         tariffConf = td.tariffConf;
245         dirPrice = td.dirPrice;
246         return *this;
247         }
248 };
249 //-----------------------------------------------------------------------------
250 struct TARIFF_DATA_RES
251 {
252     TARIFF_CONF_RES                tariffConf;
253     std::vector<DIRPRICE_DATA_RES> dirPrice;
254
255     TARIFF_DATA_RES()
256         : tariffConf(),
257           dirPrice(DIR_NUM)
258         {}
259
260     TARIFF_DATA GetData() const
261         {
262         TARIFF_DATA td;
263         td.tariffConf = tariffConf.GetData();
264         for (size_t i = 0; i < DIR_NUM; i++)
265             td.dirPrice[i] = dirPrice[i].GetData();
266         return td;
267         }
268 };
269 //-----------------------------------------------------------------------------
270 #endif