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>
33 //-----------------------------------------------------------------------------
36 DirPriceData() noexcept
50 DirPriceData(const DirPriceData&) = default;
51 DirPriceData& operator=(const DirPriceData&) = default;
52 DirPriceData(DirPriceData&&) = default;
53 DirPriceData& operator=(DirPriceData&&) = default;
64 int singlePrice; // Do not use day/night division
65 int noDiscount; // Do not use threshold
67 //-----------------------------------------------------------------------------
68 struct DirPriceDataOpt
70 DirPriceDataOpt() = default;
72 DirPriceDataOpt(const DirPriceData& data) noexcept
77 priceDayA(data.priceDayA),
78 priceNightA(data.priceNightA),
79 priceDayB(data.priceDayB),
80 priceNightB(data.priceNightB),
81 threshold(data.threshold),
82 singlePrice(data.singlePrice),
83 noDiscount(data.noDiscount)
86 DirPriceDataOpt(const DirPriceDataOpt&) = default;
87 DirPriceDataOpt& operator=(const DirPriceDataOpt&) = default;
88 DirPriceDataOpt(DirPriceDataOpt&&) = default;
89 DirPriceDataOpt& operator=(DirPriceDataOpt&&) = default;
91 DirPriceDataOpt & operator=(const DirPriceData& rhs) noexcept
97 priceDayA = rhs.priceDayA;
98 priceNightA = rhs.priceNightA;
99 priceDayB = rhs.priceDayB;
100 priceNightB = rhs.priceNightB;
101 threshold = rhs.threshold;
102 singlePrice = rhs.singlePrice;
103 noDiscount = rhs.noDiscount;
107 void splice(const DirPriceDataOpt & rhs) noexcept
109 STG::splice(hDay, rhs.hDay);
110 STG::splice(mDay, rhs.mDay);
111 STG::splice(hNight, rhs.hNight);
112 STG::splice(mNight, rhs.mNight);
113 STG::splice(priceDayA, rhs.priceDayA);
114 STG::splice(priceNightA, rhs.priceNightA);
115 STG::splice(priceDayB, rhs.priceDayB);
116 STG::splice(priceNightB, rhs.priceNightB);
117 STG::splice(threshold, rhs.threshold);
118 STG::splice(singlePrice, rhs.singlePrice);
119 STG::splice(noDiscount, rhs.noDiscount);
122 DirPriceData get(const DirPriceData& defaultValue) const noexcept
125 res.hDay = hDay.value_or(defaultValue.hDay);
126 res.mDay = mDay.value_or(defaultValue.mDay);
127 res.hNight = hNight.value_or(defaultValue.hNight);
128 res.mNight = mNight.value_or(defaultValue.mNight);
129 res.priceDayA = priceDayA.value_or(defaultValue.priceDayA);
130 res.priceNightA = priceNightA.value_or(defaultValue.priceNightA);
131 res.priceDayB = priceDayB.value_or(defaultValue.priceDayB);
132 res.priceNightB = priceNightB.value_or(defaultValue.priceNightB);
133 res.threshold = threshold.value_or(defaultValue.threshold);
134 res.singlePrice = singlePrice.value_or(defaultValue.singlePrice);
135 res.noDiscount = noDiscount.value_or(defaultValue.noDiscount);
139 std::optional<int> hDay;
140 std::optional<int> mDay;
141 std::optional<int> hNight;
142 std::optional<int> mNight;
143 std::optional<double> priceDayA;
144 std::optional<double> priceNightA;
145 std::optional<double> priceDayB;
146 std::optional<double> priceNightB;
147 std::optional<int> threshold;
148 std::optional<int> singlePrice;
149 std::optional<int> noDiscount;
151 //-----------------------------------------------------------------------------
156 Tariff::TraffType traffType;
159 Tariff::Period period;
160 Tariff::ChangePolicy changePolicy;
161 time_t changePolicyTimeout;
163 TariffConf() noexcept
166 traffType(Tariff::TRAFF_UP_DOWN),
168 period(Tariff::MONTH),
169 changePolicy(Tariff::ALLOW),
170 changePolicyTimeout(0)
173 explicit TariffConf(const std::string & n) noexcept
176 traffType(Tariff::TRAFF_UP_DOWN),
179 period(Tariff::MONTH),
180 changePolicy(Tariff::ALLOW),
181 changePolicyTimeout(0)
184 TariffConf(const TariffConf&) = default;
185 TariffConf& operator=(const TariffConf&) = default;
186 TariffConf(TariffConf&&) = default;
187 TariffConf& operator=(TariffConf&&) = default;
189 //-----------------------------------------------------------------------------
192 TariffConfOpt() = default;
193 TariffConfOpt(const TariffConf& data) noexcept
196 traffType(data.traffType),
197 passiveCost(data.passiveCost),
200 changePolicy(data.changePolicy),
201 changePolicyTimeout(data.changePolicyTimeout)
203 TariffConfOpt& operator=(const TariffConf & tc) noexcept
207 traffType = tc.traffType;
208 passiveCost = tc.passiveCost;
211 changePolicy = tc.changePolicy;
212 changePolicyTimeout = tc.changePolicyTimeout;
216 TariffConfOpt(const TariffConfOpt&) = default;
217 TariffConfOpt& operator=(const TariffConfOpt&) = default;
218 TariffConfOpt(TariffConfOpt&&) = default;
219 TariffConfOpt& operator=(TariffConfOpt&&) = default;
221 TariffConf get(const TariffConf& defaultValue) const noexcept
224 res.fee = fee.value_or(defaultValue.fee);
225 res.free = free.value_or(defaultValue.free);
226 res.traffType = traffType.value_or(defaultValue.traffType);
227 res.passiveCost = passiveCost.value_or(defaultValue.passiveCost);
228 res.name = name.value_or(defaultValue.name);
229 res.period = period.value_or(defaultValue.period);
230 res.changePolicy = changePolicy.value_or(defaultValue.changePolicy);
231 res.changePolicyTimeout = changePolicyTimeout.value_or(defaultValue.changePolicyTimeout);
235 std::optional<double> fee;
236 std::optional<double> free;
237 std::optional<Tariff::TraffType> traffType;
238 std::optional<double> passiveCost;
239 std::optional<std::string> name;
240 std::optional<Tariff::Period> period;
241 std::optional<Tariff::ChangePolicy> changePolicy;
242 std::optional<time_t> changePolicyTimeout;
244 //-----------------------------------------------------------------------------
247 TariffConf tariffConf;
248 std::vector<DirPriceData> dirPrice;
250 TariffData() noexcept
254 explicit TariffData(const std::string& name) noexcept
259 TariffData(const TariffData&) = default;
260 TariffData& operator=(const TariffData&) = default;
261 TariffData(TariffData&&) = default;
262 TariffData& operator=(TariffData&&) = default;
264 //-----------------------------------------------------------------------------
267 TariffConfOpt tariffConf;
268 std::vector<DirPriceDataOpt> dirPrice;
274 TariffDataOpt(const TariffData& data) noexcept
275 : tariffConf(data.tariffConf),
278 for (size_t i = 0; i < DIR_NUM; ++i)
279 dirPrice[i] = data.dirPrice[i];
282 TariffDataOpt& operator=(const TariffData& td) noexcept
284 tariffConf = td.tariffConf;
285 for (size_t i = 0; i < DIR_NUM; ++i)
286 dirPrice[i] = td.dirPrice[i];
290 TariffDataOpt(const TariffDataOpt&) = default;
291 TariffDataOpt& operator=(const TariffDataOpt&) = default;
292 TariffDataOpt(TariffDataOpt&&) = default;
293 TariffDataOpt& operator=(TariffDataOpt&&) = default;
295 TariffData get(const TariffData& defaultValue) const noexcept
298 res.tariffConf = tariffConf.get(defaultValue.tariffConf);
299 for (size_t i = 0; i < DIR_NUM; ++i)
300 res.dirPrice[i] = dirPrice[i].get(defaultValue.dirPrice[i]);
304 //-----------------------------------------------------------------------------