]> git.stg.codes - stg.git/blob - include/stg/tariff_conf.h
Added parser factories.
[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         dd.hDay        = hDay.data();
102         dd.hNight      = hNight.data();
103         dd.mDay        = mDay.data();
104         dd.mNight      = mNight.data();
105         dd.noDiscount  = noDiscount.data();
106         dd.priceDayA   = priceDayA.data();
107         dd.priceDayB   = priceDayB.data();
108
109         dd.priceNightA = priceNightA.data();
110         dd.priceNightB = priceNightB.data();
111         dd.singlePrice = singlePrice.data();
112         dd.threshold   = threshold.data();
113         return dd;
114         }
115
116     void Splice(const DIRPRICE_DATA_RES & rhs)
117         {
118         hDay.splice(rhs.hDay);
119         mDay.splice(rhs.mDay);
120         hNight.splice(rhs.hNight);
121         mNight.splice(rhs.mNight);
122         priceDayA.splice(rhs.priceDayA);
123         priceNightA.splice(rhs.priceNightA);
124         priceDayB.splice(rhs.priceDayB);
125         priceNightB.splice(rhs.priceNightB);
126         threshold.splice(rhs.threshold);
127         singlePrice.splice(rhs.singlePrice);
128         noDiscount.splice(rhs.noDiscount);
129         }
130
131     RESETABLE<int>    hDay;
132     RESETABLE<int>    mDay;
133     RESETABLE<int>    hNight;
134     RESETABLE<int>    mNight;
135     RESETABLE<double> priceDayA;
136     RESETABLE<double> priceNightA;
137     RESETABLE<double> priceDayB;
138     RESETABLE<double> priceNightB;
139     RESETABLE<int>    threshold;
140     RESETABLE<int>    singlePrice;
141     RESETABLE<int>    noDiscount;
142 };
143 //-----------------------------------------------------------------------------
144 struct TARIFF_CONF
145 {
146     double             fee;
147     double             free;
148     TARIFF::TRAFF_TYPE traffType;
149     double             passiveCost;
150     std::string        name;
151     TARIFF::PERIOD     period;
152
153     TARIFF_CONF()
154         : fee(0),
155           free(0),
156           traffType(TARIFF::TRAFF_UP_DOWN),
157           passiveCost(0),
158           name(),
159           period(TARIFF::MONTH)
160         {}
161
162     TARIFF_CONF(const std::string & n)
163         : fee(0),
164           free(0),
165           traffType(TARIFF::TRAFF_UP_DOWN),
166           passiveCost(0),
167           name(n),
168           period(TARIFF::MONTH)
169         {}
170 };
171 //-----------------------------------------------------------------------------
172 struct TARIFF_CONF_RES
173 {
174     TARIFF_CONF_RES()
175         : fee(),
176           free(),
177           traffType(),
178           passiveCost(),
179           name(),
180           period()
181         {}
182
183     TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc)
184         {
185         fee         = tc.fee;
186         free        = tc.free;
187         traffType   = tc.traffType;
188         passiveCost = tc.passiveCost;
189         name        = tc.name;
190         period      = tc.period;
191         return *this;
192         }
193
194     TARIFF_CONF GetData() const
195         {
196         TARIFF_CONF tc;
197         tc.fee         = fee.data();
198         tc.free        = free.data();
199         tc.name        = name.data();
200         tc.passiveCost = passiveCost.data();
201         tc.traffType   = traffType.data();
202         tc.period      = period.data();
203         return tc;
204         }
205
206     RESETABLE<double>             fee;
207     RESETABLE<double>             free;
208     RESETABLE<TARIFF::TRAFF_TYPE> traffType;
209     RESETABLE<double>             passiveCost;
210     RESETABLE<std::string>        name;
211     RESETABLE<TARIFF::PERIOD>     period;
212 };
213 //-----------------------------------------------------------------------------
214 struct TARIFF_DATA
215 {
216     TARIFF_CONF                tariffConf;
217     std::vector<DIRPRICE_DATA> dirPrice;
218
219     TARIFF_DATA()
220         : tariffConf(),
221           dirPrice(DIR_NUM)
222         {}
223
224     TARIFF_DATA(const std::string & name)
225         : tariffConf(name),
226           dirPrice(DIR_NUM)
227         {}
228
229     TARIFF_DATA(const TARIFF_DATA & td)
230         : tariffConf(td.tariffConf),
231           dirPrice(td.dirPrice)
232         {}
233
234     TARIFF_DATA & operator=(const TARIFF_DATA & td)
235         {
236         tariffConf = td.tariffConf;
237         dirPrice = td.dirPrice;
238         return *this;
239         }
240 };
241 //-----------------------------------------------------------------------------
242 struct TARIFF_DATA_RES
243 {
244     TARIFF_CONF_RES                tariffConf;
245     std::vector<DIRPRICE_DATA_RES> dirPrice;
246
247     TARIFF_DATA_RES()
248         : tariffConf(),
249           dirPrice(DIR_NUM)
250         {}
251
252     TARIFF_DATA GetData() const
253         {
254         TARIFF_DATA td;
255         td.tariffConf = tariffConf.GetData();
256         for (size_t i = 0; i < DIR_NUM; i++)
257             td.dirPrice[i] = dirPrice[i].GetData();
258         return td;
259         }
260 };
261 //-----------------------------------------------------------------------------
262 #endif