X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d084d9ae9f7bcd7f7d1926e7eeae921dbad49273..8272f5d139d947fdbe469dfd7afc3ddd6ea7a603:/include/stg/tariff_conf.h?ds=inline diff --git a/include/stg/tariff_conf.h b/include/stg/tariff_conf.h index fc9807be..d7336157 100644 --- a/include/stg/tariff_conf.h +++ b/include/stg/tariff_conf.h @@ -18,34 +18,21 @@ * Author : Boris Mikhailenko */ - /* - $Revision: 1.9 $ - $Date: 2010/10/05 20:41:11 $ - $Author: faust $ - */ - -#ifndef TARIFF_CONF_H -#define TARIFF_CONF_H +#pragma once #include "tariff.h" -#include "resetable.h" +#include "stg/optional.h" #include "const.h" #include #include -//----------------------------------------------------------------------------- -enum +namespace STG { - TRAFF_UP = 0, - TRAFF_DOWN, - TRAFF_UP_DOWN, - TRAFF_MAX -}; //----------------------------------------------------------------------------- -struct DIRPRICE_DATA +struct DirPriceData { - DIRPRICE_DATA() + DirPriceData() noexcept : hDay(0), mDay(0), hNight(0), @@ -57,7 +44,13 @@ struct DIRPRICE_DATA threshold(0), singlePrice(0), noDiscount(0) - {} + {} + + DirPriceData(const DirPriceData&) = default; + DirPriceData& operator=(const DirPriceData&) = default; + DirPriceData(DirPriceData&&) = default; + DirPriceData& operator=(DirPriceData&&) = default; + int hDay; int mDay; int hNight; @@ -71,58 +64,47 @@ struct DIRPRICE_DATA int noDiscount; // Do not use threshold }; //----------------------------------------------------------------------------- -struct DIRPRICE_DATA_RES +struct DirPriceDataOpt { - DIRPRICE_DATA_RES() - : hDay(), - mDay(), - hNight(), - mNight(), - priceDayA(), - priceNightA(), - priceDayB(), - priceNightB(), - threshold(), - singlePrice(), - noDiscount() - {} + DirPriceDataOpt() = default; - DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & rvalue) - { - hDay = rvalue.hDay; - mDay = rvalue.mDay; - hNight = rvalue.hNight; - mNight = rvalue.mNight; - priceDayA = rvalue.priceDayA; - priceNightA = rvalue.priceNightA; - priceDayB = rvalue.priceDayB; - priceNightB = rvalue.priceNightB; - threshold = rvalue.threshold; - singlePrice = rvalue.singlePrice; - noDiscount = rvalue.noDiscount; - return *this; - } + DirPriceDataOpt(const DirPriceData& data) noexcept + : hDay(data.hDay), + mDay(data.mDay), + hNight(data.hNight), + mNight(data.mNight), + priceDayA(data.priceDayA), + priceNightA(data.priceNightA), + priceDayB(data.priceDayB), + priceNightB(data.priceNightB), + threshold(data.threshold), + singlePrice(data.singlePrice), + noDiscount(data.noDiscount) + {} - DIRPRICE_DATA GetData() const - { - DIRPRICE_DATA dd; - dd.hDay = hDay.data(); - dd.hNight = hNight.data(); - dd.mDay = mDay.data(); - dd.mNight = mNight.data(); - dd.noDiscount = noDiscount.data(); - dd.priceDayA = priceDayA.data(); - dd.priceDayB = priceDayB.data(); + DirPriceDataOpt(const DirPriceDataOpt&) = default; + DirPriceDataOpt& operator=(const DirPriceDataOpt&) = default; + DirPriceDataOpt(DirPriceDataOpt&&) = default; + DirPriceDataOpt& operator=(DirPriceDataOpt&&) = default; - dd.priceNightA = priceNightA.data(); - dd.priceNightB = priceNightB.data(); - dd.singlePrice = singlePrice.data(); - dd.threshold = threshold.data(); - return dd; - } + DirPriceDataOpt & operator=(const DirPriceData& rhs) noexcept + { + hDay = rhs.hDay; + mDay = rhs.mDay; + hNight = rhs.hNight; + mNight = rhs.mNight; + priceDayA = rhs.priceDayA; + priceNightA = rhs.priceNightA; + priceDayB = rhs.priceDayB; + priceNightB = rhs.priceNightB; + threshold = rhs.threshold; + singlePrice = rhs.singlePrice; + noDiscount = rhs.noDiscount; + return *this; + } - void Splice(const DIRPRICE_DATA_RES & rhs) - { + void splice(const DirPriceDataOpt & rhs) noexcept + { hDay.splice(rhs.hDay); mDay.splice(rhs.mDay); hNight.splice(rhs.hNight); @@ -134,137 +116,189 @@ struct DIRPRICE_DATA_RES threshold.splice(rhs.threshold); singlePrice.splice(rhs.singlePrice); noDiscount.splice(rhs.noDiscount); - } + } + + DirPriceData get(const DirPriceData& defaultValue) const noexcept + { + DirPriceData res; + res.hDay = hDay.get(defaultValue.hDay); + res.mDay = mDay.get(defaultValue.mDay); + res.hNight = hNight.get(defaultValue.hNight); + res.mNight = mNight.get(defaultValue.mNight); + res.priceDayA = priceDayA.get(defaultValue.priceDayA); + res.priceNightA = priceNightA.get(defaultValue.priceNightA); + res.priceDayB = priceDayB.get(defaultValue.priceDayB); + res.priceNightB = priceNightB.get(defaultValue.priceNightB); + res.threshold = threshold.get(defaultValue.threshold); + res.singlePrice = singlePrice.get(defaultValue.singlePrice); + res.noDiscount = noDiscount.get(defaultValue.noDiscount); + return res; + } - RESETABLE hDay; - RESETABLE mDay; - RESETABLE hNight; - RESETABLE mNight; - RESETABLE priceDayA; - RESETABLE priceNightA; - RESETABLE priceDayB; - RESETABLE priceNightB; - RESETABLE threshold; - RESETABLE singlePrice; - RESETABLE noDiscount; + Optional hDay; + Optional mDay; + Optional hNight; + Optional mNight; + Optional priceDayA; + Optional priceNightA; + Optional priceDayB; + Optional priceNightB; + Optional threshold; + Optional singlePrice; + Optional noDiscount; }; //----------------------------------------------------------------------------- -struct TARIFF_CONF +struct TariffConf { - double fee; - double free; - int traffType; - double passiveCost; - std::string name; - TARIFF::PERIOD period; + double fee; + double free; + Tariff::TraffType traffType; + double passiveCost; + std::string name; + Tariff::Period period; + Tariff::ChangePolicy changePolicy; + time_t changePolicyTimeout; - TARIFF_CONF() + TariffConf() noexcept : fee(0), free(0), - traffType(TRAFF_UP_DOWN), + traffType(Tariff::TRAFF_UP_DOWN), passiveCost(0), - name(), - period(TARIFF::MONTH) - {} + period(Tariff::MONTH), + changePolicy(Tariff::ALLOW), + changePolicyTimeout(0) + {} - TARIFF_CONF(const std::string & n) + explicit TariffConf(const std::string & n) noexcept : fee(0), free(0), - traffType(TRAFF_UP_DOWN), + traffType(Tariff::TRAFF_UP_DOWN), passiveCost(0), name(n), - period(TARIFF::MONTH) - {} + period(Tariff::MONTH), + changePolicy(Tariff::ALLOW), + changePolicyTimeout(0) + {} + + TariffConf(const TariffConf&) = default; + TariffConf& operator=(const TariffConf&) = default; + TariffConf(TariffConf&&) = default; + TariffConf& operator=(TariffConf&&) = default; }; //----------------------------------------------------------------------------- -struct TARIFF_CONF_RES +struct TariffConfOpt { - TARIFF_CONF_RES() - : fee(), - free(), - traffType(), - passiveCost(), - name(), - period() - {} - - TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc) - { + TariffConfOpt() = default; + TariffConfOpt(const TariffConf& data) noexcept + : fee(data.fee), + free(data.free), + traffType(data.traffType), + passiveCost(data.passiveCost), + name(data.name), + period(data.period), + changePolicy(data.changePolicy), + changePolicyTimeout(data.changePolicyTimeout) + {} + TariffConfOpt& operator=(const TariffConf & tc) noexcept + { fee = tc.fee; free = tc.free; traffType = tc.traffType; passiveCost = tc.passiveCost; name = tc.name; period = tc.period; + changePolicy = tc.changePolicy; + changePolicyTimeout = tc.changePolicyTimeout; return *this; - } + } - TARIFF_CONF GetData() const - { - TARIFF_CONF tc; - tc.fee = fee.data(); - tc.free = free.data(); - tc.name = name.data(); - tc.passiveCost = passiveCost.data(); - tc.traffType = traffType.data(); - tc.period = period.data(); - return tc; - } + TariffConfOpt(const TariffConfOpt&) = default; + TariffConfOpt& operator=(const TariffConfOpt&) = default; + TariffConfOpt(TariffConfOpt&&) = default; + TariffConfOpt& operator=(TariffConfOpt&&) = default; - RESETABLE fee; - RESETABLE free; - RESETABLE traffType; - RESETABLE passiveCost; - RESETABLE name; - RESETABLE period; + TariffConf get(const TariffConf& defaultValue) const noexcept + { + TariffConf res; + res.fee = fee.get(defaultValue.fee); + res.free = free.get(defaultValue.free); + res.traffType = traffType.get(defaultValue.traffType); + res.passiveCost = passiveCost.get(defaultValue.passiveCost); + res.name = name.get(defaultValue.name); + res.period = period.get(defaultValue.period); + res.changePolicy = changePolicy.get(defaultValue.changePolicy); + res.changePolicyTimeout = changePolicyTimeout.get(defaultValue.changePolicyTimeout); + return res; + } + + Optional fee; + Optional free; + Optional traffType; + Optional passiveCost; + Optional name; + Optional period; + Optional changePolicy; + Optional changePolicyTimeout; }; //----------------------------------------------------------------------------- -struct TARIFF_DATA +struct TariffData { - TARIFF_CONF tariffConf; - std::vector dirPrice; + TariffConf tariffConf; + std::vector dirPrice; - TARIFF_DATA() - : tariffConf(), - dirPrice(DIR_NUM) - {} + TariffData() noexcept + : dirPrice(DIR_NUM) + {} - TARIFF_DATA(const std::string & name) + explicit TariffData(const std::string& name) noexcept : tariffConf(name), dirPrice(DIR_NUM) - {} - - TARIFF_DATA(const TARIFF_DATA & td) - : tariffConf(td.tariffConf), - dirPrice(td.dirPrice) - {} + {} - TARIFF_DATA & operator=(const TARIFF_DATA & td) - { - tariffConf = td.tariffConf; - dirPrice = td.dirPrice; - return *this; - } + TariffData(const TariffData&) = default; + TariffData& operator=(const TariffData&) = default; + TariffData(TariffData&&) = default; + TariffData& operator=(TariffData&&) = default; }; //----------------------------------------------------------------------------- -struct TARIFF_DATA_RES +struct TariffDataOpt { - TARIFF_CONF_RES tariffConf; - std::vector dirPrice; + TariffConfOpt tariffConf; + std::vector dirPrice; - TARIFF_DATA_RES() - : tariffConf(), + TariffDataOpt() + : dirPrice(DIR_NUM) + {} + + TariffDataOpt(const TariffData& data) noexcept + : tariffConf(data.tariffConf), dirPrice(DIR_NUM) - {} + { + for (size_t i = 0; i < DIR_NUM; ++i) + dirPrice[i] = data.dirPrice[i]; + } + + TariffDataOpt& operator=(const TariffData& td) noexcept + { + tariffConf = td.tariffConf; + for (size_t i = 0; i < DIR_NUM; ++i) + dirPrice[i] = td.dirPrice[i]; + return *this; + } + + TariffDataOpt(const TariffDataOpt&) = default; + TariffDataOpt& operator=(const TariffDataOpt&) = default; + TariffDataOpt(TariffDataOpt&&) = default; + TariffDataOpt& operator=(TariffDataOpt&&) = default; - TARIFF_DATA GetData() const - { - TARIFF_DATA td; - td.tariffConf = tariffConf.GetData(); - for (size_t i = 0; i < DIR_NUM; i++) - td.dirPrice[i] = dirPrice[i].GetData(); - return td; - } + TariffData get(const TariffData& defaultValue) const noexcept + { + TariffData res; + res.tariffConf = tariffConf.get(defaultValue.tariffConf); + for (size_t i = 0; i < DIR_NUM; ++i) + res.dirPrice[i] = dirPrice[i].get(defaultValue.dirPrice[i]); + return res; + } }; //----------------------------------------------------------------------------- -#endif +}