]> git.stg.codes - stg.git/blob - include/stg/tariff_conf.h
Target-specific, compiler-aware warnings.
[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 struct DIRPRICE_DATA
39 {
40     DIRPRICE_DATA()
41         : hDay(0),
42           mDay(0),
43           hNight(0),
44           mNight(0),
45           priceDayA(0),
46           priceNightA(0),
47           priceDayB(0),
48           priceNightB(0),
49           threshold(0),
50           singlePrice(0),
51           noDiscount(0)
52         {}
53     int    hDay;
54     int    mDay;
55     int    hNight;
56     int    mNight;
57     double priceDayA;
58     double priceNightA;
59     double priceDayB;
60     double priceNightB;
61     int    threshold;
62     int    singlePrice; // Do not use day/night division
63     int    noDiscount; // Do not use threshold
64 };
65 //-----------------------------------------------------------------------------
66 struct DIRPRICE_DATA_RES
67 {
68     DIRPRICE_DATA_RES()
69         : hDay(),
70           mDay(),
71           hNight(),
72           mNight(),
73           priceDayA(),
74           priceNightA(),
75           priceDayB(),
76           priceNightB(),
77           threshold(),
78           singlePrice(),
79           noDiscount()
80         {}
81
82     DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & rvalue)
83         {
84         hDay        = rvalue.hDay;
85         mDay        = rvalue.mDay;
86         hNight      = rvalue.hNight;
87         mNight      = rvalue.mNight;
88         priceDayA   = rvalue.priceDayA;
89         priceNightA = rvalue.priceNightA;
90         priceDayB   = rvalue.priceDayB;
91         priceNightB = rvalue.priceNightB;
92         threshold   = rvalue.threshold;
93         singlePrice = rvalue.singlePrice;
94         noDiscount  = rvalue.noDiscount;
95         return *this;
96         }
97
98     DIRPRICE_DATA GetData() const
99         {
100         DIRPRICE_DATA dd;
101         hDay.maybeSet(dd.hDay);
102         hNight.maybeSet(dd.hNight);
103         mDay.maybeSet(dd.mDay);
104         mNight.maybeSet(dd.mNight);
105         noDiscount.maybeSet(dd.noDiscount);
106         priceDayA.maybeSet(dd.priceDayA);
107         priceDayB.maybeSet(dd.priceDayB);
108         priceNightA.maybeSet(dd.priceNightA);
109         priceNightB.maybeSet(dd.priceNightB);
110         singlePrice.maybeSet(dd.singlePrice);
111         threshold.maybeSet(dd.threshold);
112         return dd;
113         }
114
115     void Splice(const DIRPRICE_DATA_RES & rhs)
116         {
117         hDay.splice(rhs.hDay);
118         mDay.splice(rhs.mDay);
119         hNight.splice(rhs.hNight);
120         mNight.splice(rhs.mNight);
121         priceDayA.splice(rhs.priceDayA);
122         priceNightA.splice(rhs.priceNightA);
123         priceDayB.splice(rhs.priceDayB);
124         priceNightB.splice(rhs.priceNightB);
125         threshold.splice(rhs.threshold);
126         singlePrice.splice(rhs.singlePrice);
127         noDiscount.splice(rhs.noDiscount);
128         }
129
130     RESETABLE<int>    hDay;
131     RESETABLE<int>    mDay;
132     RESETABLE<int>    hNight;
133     RESETABLE<int>    mNight;
134     RESETABLE<double> priceDayA;
135     RESETABLE<double> priceNightA;
136     RESETABLE<double> priceDayB;
137     RESETABLE<double> priceNightB;
138     RESETABLE<int>    threshold;
139     RESETABLE<int>    singlePrice;
140     RESETABLE<int>    noDiscount;
141 };
142 //-----------------------------------------------------------------------------
143 struct TARIFF_CONF
144 {
145     double             fee;
146     double             free;
147     TARIFF::TRAFF_TYPE traffType;
148     double             passiveCost;
149     std::string        name;
150     TARIFF::PERIOD     period;
151     TARIFF::CHANGE_POLICY changePolicy;
152     time_t changePolicyTimeout;
153
154     TARIFF_CONF()
155         : fee(0),
156           free(0),
157           traffType(TARIFF::TRAFF_UP_DOWN),
158           passiveCost(0),
159           name(),
160           period(TARIFF::MONTH),
161           changePolicy(TARIFF::ALLOW),
162           changePolicyTimeout(0)
163         {}
164
165     explicit TARIFF_CONF(const std::string & n)
166         : fee(0),
167           free(0),
168           traffType(TARIFF::TRAFF_UP_DOWN),
169           passiveCost(0),
170           name(n),
171           period(TARIFF::MONTH),
172           changePolicy(TARIFF::ALLOW),
173           changePolicyTimeout(0)
174         {}
175 };
176 //-----------------------------------------------------------------------------
177 struct TARIFF_CONF_RES
178 {
179     TARIFF_CONF_RES()
180         : fee(),
181           free(),
182           traffType(),
183           passiveCost(),
184           name(),
185           period(),
186           changePolicy(),
187           changePolicyTimeout()
188         {}
189
190     TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc)
191         {
192         fee         = tc.fee;
193         free        = tc.free;
194         traffType   = tc.traffType;
195         passiveCost = tc.passiveCost;
196         name        = tc.name;
197         period      = tc.period;
198         changePolicy = tc.changePolicy;
199         changePolicyTimeout = tc.changePolicyTimeout;
200         return *this;
201         }
202
203     TARIFF_CONF GetData() const
204         {
205         TARIFF_CONF tc;
206         fee.maybeSet(tc.fee);
207         free.maybeSet(tc.free);
208         name.maybeSet(tc.name);
209         passiveCost.maybeSet(tc.passiveCost);
210         traffType.maybeSet(tc.traffType);
211         period.maybeSet(tc.period);
212         changePolicy.maybeSet(tc.changePolicy);
213         changePolicyTimeout.maybeSet(tc.changePolicyTimeout);
214         return tc;
215         }
216
217     RESETABLE<double>             fee;
218     RESETABLE<double>             free;
219     RESETABLE<TARIFF::TRAFF_TYPE> traffType;
220     RESETABLE<double>             passiveCost;
221     RESETABLE<std::string>        name;
222     RESETABLE<TARIFF::PERIOD>     period;
223     RESETABLE<TARIFF::CHANGE_POLICY> changePolicy;
224     RESETABLE<time_t>             changePolicyTimeout;
225 };
226 //-----------------------------------------------------------------------------
227 struct TARIFF_DATA
228 {
229     TARIFF_CONF                tariffConf;
230     std::vector<DIRPRICE_DATA> dirPrice;
231
232     TARIFF_DATA()
233         : tariffConf(),
234           dirPrice(DIR_NUM)
235         {}
236
237     explicit TARIFF_DATA(const std::string & name)
238         : tariffConf(name),
239           dirPrice(DIR_NUM)
240         {}
241 };
242 //-----------------------------------------------------------------------------
243 struct TARIFF_DATA_RES
244 {
245     TARIFF_CONF_RES                tariffConf;
246     std::vector<DIRPRICE_DATA_RES> dirPrice;
247
248     TARIFF_DATA_RES()
249         : tariffConf(),
250           dirPrice(DIR_NUM)
251         {}
252
253     TARIFF_DATA_RES & operator=(const TARIFF_DATA & td)
254         {
255         tariffConf = td.tariffConf;
256         for (size_t i = 0; i < DIR_NUM; ++i)
257             dirPrice[i] = td.dirPrice[i];
258         return *this;
259         }
260
261     TARIFF_DATA GetData() const
262         {
263         TARIFF_DATA td;
264         td.tariffConf = tariffConf.GetData();
265         for (size_t i = 0; i < DIR_NUM; i++)
266             td.dirPrice[i] = dirPrice[i].GetData();
267         return td;
268         }
269 };
270 //-----------------------------------------------------------------------------
271 #endif