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.
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.
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
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
24 #include "stg/optional.h"
32 //-----------------------------------------------------------------------------
35 DirPriceData() noexcept
49 DirPriceData(const DirPriceData&) = default;
50 DirPriceData& operator=(const DirPriceData&) = default;
51 DirPriceData(DirPriceData&&) = default;
52 DirPriceData& operator=(DirPriceData&&) = default;
63 int singlePrice; // Do not use day/night division
64 int noDiscount; // Do not use threshold
66 //-----------------------------------------------------------------------------
67 struct DirPriceDataOpt
69 DirPriceDataOpt() = default;
71 DirPriceDataOpt(const DirPriceData& data) noexcept
76 priceDayA(data.priceDayA),
77 priceNightA(data.priceNightA),
78 priceDayB(data.priceDayB),
79 priceNightB(data.priceNightB),
80 threshold(data.threshold),
81 singlePrice(data.singlePrice),
82 noDiscount(data.noDiscount)
85 DirPriceDataOpt(const DirPriceDataOpt&) = default;
86 DirPriceDataOpt& operator=(const DirPriceDataOpt&) = default;
87 DirPriceDataOpt(DirPriceDataOpt&&) = default;
88 DirPriceDataOpt& operator=(DirPriceDataOpt&&) = default;
90 DirPriceDataOpt & operator=(const DirPriceData& rhs) noexcept
96 priceDayA = rhs.priceDayA;
97 priceNightA = rhs.priceNightA;
98 priceDayB = rhs.priceDayB;
99 priceNightB = rhs.priceNightB;
100 threshold = rhs.threshold;
101 singlePrice = rhs.singlePrice;
102 noDiscount = rhs.noDiscount;
106 void splice(const DirPriceDataOpt & rhs) noexcept
108 hDay.splice(rhs.hDay);
109 mDay.splice(rhs.mDay);
110 hNight.splice(rhs.hNight);
111 mNight.splice(rhs.mNight);
112 priceDayA.splice(rhs.priceDayA);
113 priceNightA.splice(rhs.priceNightA);
114 priceDayB.splice(rhs.priceDayB);
115 priceNightB.splice(rhs.priceNightB);
116 threshold.splice(rhs.threshold);
117 singlePrice.splice(rhs.singlePrice);
118 noDiscount.splice(rhs.noDiscount);
121 DirPriceData get(const DirPriceData& defaultValue) const noexcept
124 res.hDay = hDay.get(defaultValue.hDay);
125 res.mDay = mDay.get(defaultValue.mDay);
126 res.hNight = hNight.get(defaultValue.hNight);
127 res.mNight = mNight.get(defaultValue.mNight);
128 res.priceDayA = priceDayA.get(defaultValue.priceDayA);
129 res.priceNightA = priceNightA.get(defaultValue.priceNightA);
130 res.priceDayB = priceDayB.get(defaultValue.priceDayB);
131 res.priceNightB = priceNightB.get(defaultValue.priceNightB);
132 res.threshold = threshold.get(defaultValue.threshold);
133 res.singlePrice = singlePrice.get(defaultValue.singlePrice);
134 res.noDiscount = noDiscount.get(defaultValue.noDiscount);
140 Optional<int> hNight;
141 Optional<int> mNight;
142 Optional<double> priceDayA;
143 Optional<double> priceNightA;
144 Optional<double> priceDayB;
145 Optional<double> priceNightB;
146 Optional<int> threshold;
147 Optional<int> singlePrice;
148 Optional<int> noDiscount;
150 //-----------------------------------------------------------------------------
155 Tariff::TraffType traffType;
158 Tariff::Period period;
159 Tariff::ChangePolicy changePolicy;
160 time_t changePolicyTimeout;
162 TariffConf() noexcept
165 traffType(Tariff::TRAFF_UP_DOWN),
167 period(Tariff::MONTH),
168 changePolicy(Tariff::ALLOW),
169 changePolicyTimeout(0)
172 explicit TariffConf(const std::string & n) noexcept
175 traffType(Tariff::TRAFF_UP_DOWN),
178 period(Tariff::MONTH),
179 changePolicy(Tariff::ALLOW),
180 changePolicyTimeout(0)
183 TariffConf(const TariffConf&) = default;
184 TariffConf& operator=(const TariffConf&) = default;
185 TariffConf(TariffConf&&) = default;
186 TariffConf& operator=(TariffConf&&) = default;
188 //-----------------------------------------------------------------------------
191 TariffConfOpt() = default;
192 TariffConfOpt(const TariffConf& data) noexcept
195 traffType(data.traffType),
196 passiveCost(data.passiveCost),
199 changePolicy(data.changePolicy),
200 changePolicyTimeout(data.changePolicyTimeout)
202 TariffConfOpt& operator=(const TariffConf & tc) noexcept
206 traffType = tc.traffType;
207 passiveCost = tc.passiveCost;
210 changePolicy = tc.changePolicy;
211 changePolicyTimeout = tc.changePolicyTimeout;
215 TariffConfOpt(const TariffConfOpt&) = default;
216 TariffConfOpt& operator=(const TariffConfOpt&) = default;
217 TariffConfOpt(TariffConfOpt&&) = default;
218 TariffConfOpt& operator=(TariffConfOpt&&) = default;
220 TariffConf get(const TariffConf& defaultValue) const noexcept
223 res.fee = fee.get(defaultValue.fee);
224 res.free = free.get(defaultValue.free);
225 res.traffType = traffType.get(defaultValue.traffType);
226 res.passiveCost = passiveCost.get(defaultValue.passiveCost);
227 res.name = name.get(defaultValue.name);
228 res.period = period.get(defaultValue.period);
229 res.changePolicy = changePolicy.get(defaultValue.changePolicy);
230 res.changePolicyTimeout = changePolicyTimeout.get(defaultValue.changePolicyTimeout);
234 Optional<double> fee;
235 Optional<double> free;
236 Optional<Tariff::TraffType> traffType;
237 Optional<double> passiveCost;
238 Optional<std::string> name;
239 Optional<Tariff::Period> period;
240 Optional<Tariff::ChangePolicy> changePolicy;
241 Optional<time_t> changePolicyTimeout;
243 //-----------------------------------------------------------------------------
246 TariffConf tariffConf;
247 std::vector<DirPriceData> dirPrice;
249 TariffData() noexcept
253 explicit TariffData(const std::string& name) noexcept
258 TariffData(const TariffData&) = default;
259 TariffData& operator=(const TariffData&) = default;
260 TariffData(TariffData&&) = default;
261 TariffData& operator=(TariffData&&) = default;
263 //-----------------------------------------------------------------------------
266 TariffConfOpt tariffConf;
267 std::vector<DirPriceDataOpt> dirPrice;
273 TariffDataOpt(const TariffData& data) noexcept
274 : tariffConf(data.tariffConf),
277 for (size_t i = 0; i < DIR_NUM; ++i)
278 dirPrice[i] = data.dirPrice[i];
281 TariffDataOpt& operator=(const TariffData& td) noexcept
283 tariffConf = td.tariffConf;
284 for (size_t i = 0; i < DIR_NUM; ++i)
285 dirPrice[i] = td.dirPrice[i];
289 TariffDataOpt(const TariffDataOpt&) = default;
290 TariffDataOpt& operator=(const TariffDataOpt&) = default;
291 TariffDataOpt(TariffDataOpt&&) = default;
292 TariffDataOpt& operator=(TariffDataOpt&&) = default;
294 TariffData get(const TariffData& defaultValue) const noexcept
297 res.tariffConf = tariffConf.get(defaultValue.tariffConf);
298 for (size_t i = 0; i < DIR_NUM; ++i)
299 res.dirPrice[i] = dirPrice[i].get(defaultValue.dirPrice[i]);
303 //-----------------------------------------------------------------------------