From 25834b12ea3007230b3086f55f908ff582322fa9 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 17 Sep 2014 09:32:40 +0300 Subject: [PATCH] Traff type become an enumeration in scope of TARIFF. --- include/stg/tariff.h | 42 +++++++++++++++++++++++++++++++++++++++ include/stg/tariff_conf.h | 36 +++++++++++++-------------------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/include/stg/tariff.h b/include/stg/tariff.h index d0bf20b6..1b6413b3 100644 --- a/include/stg/tariff.h +++ b/include/stg/tariff.h @@ -26,6 +26,7 @@ #include #include #include +#include struct TARIFF_DATA; @@ -33,9 +34,14 @@ class TARIFF { public: enum PERIOD { DAY = 0, MONTH }; + enum TRAFF_TYPE { TRAFF_UP = 0, TRAFF_DOWN, TRAFF_UP_DOWN, TRAFF_MAX }; + static std::string PeriodToString(PERIOD period); static PERIOD StringToPeriod(const std::string& value); + static std::string TraffTypeToString(TRAFF_TYPE type); + static TRAFF_TYPE StringToTraffType(const std::string& value); + virtual ~TARIFF() {} virtual double GetPriceWithTraffType(uint64_t up, uint64_t down, @@ -75,4 +81,40 @@ if (strcasecmp(value.c_str(), "day") == 0) return MONTH; // Classic behaviour. } +inline +std::string TARIFF::TraffTypeToString(TARIFF::TRAFF_TYPE type) +{ +switch (type) + { + case TRAFF_UP: return "up"; + case TRAFF_DOWN: return "down"; + case TRAFF_UP_DOWN: return "up+down"; + case TRAFF_MAX: return "max"; + } +return "up+down"; +} + +inline +TARIFF::TRAFF_TYPE TARIFF::StringToTraffType(const std::string& value) +{ +if (strcasecmp(value.c_str(), "up") == 0) + return TRAFF_UP; +if (strcasecmp(value.c_str(), "down") == 0) + return TRAFF_DOWN; +if (strcasecmp(value.c_str(), "up+down") == 0) + return TRAFF_UP_DOWN; +if (strcasecmp(value.c_str(), "max") == 0) + return TRAFF_MAX; +return TRAFF_UP_DOWN; +} + +inline +std::istream & operator>>(std::istream & stream, TARIFF::TRAFF_TYPE & traffType) +{ + unsigned val; + stream >> val; + traffType = static_cast(val); + return stream; +} + #endif diff --git a/include/stg/tariff_conf.h b/include/stg/tariff_conf.h index fc9807be..ae40c128 100644 --- a/include/stg/tariff_conf.h +++ b/include/stg/tariff_conf.h @@ -34,14 +34,6 @@ #include #include -//----------------------------------------------------------------------------- -enum -{ - TRAFF_UP = 0, - TRAFF_DOWN, - TRAFF_UP_DOWN, - TRAFF_MAX -}; //----------------------------------------------------------------------------- struct DIRPRICE_DATA { @@ -151,17 +143,17 @@ struct DIRPRICE_DATA_RES //----------------------------------------------------------------------------- struct TARIFF_CONF { - double fee; - double free; - int traffType; - double passiveCost; - std::string name; - TARIFF::PERIOD period; + double fee; + double free; + TARIFF::TRAFF_TYPE traffType; + double passiveCost; + std::string name; + TARIFF::PERIOD period; TARIFF_CONF() : fee(0), free(0), - traffType(TRAFF_UP_DOWN), + traffType(TARIFF::TRAFF_UP_DOWN), passiveCost(0), name(), period(TARIFF::MONTH) @@ -170,7 +162,7 @@ struct TARIFF_CONF TARIFF_CONF(const std::string & n) : fee(0), free(0), - traffType(TRAFF_UP_DOWN), + traffType(TARIFF::TRAFF_UP_DOWN), passiveCost(0), name(n), period(TARIFF::MONTH) @@ -211,12 +203,12 @@ struct TARIFF_CONF_RES return tc; } - RESETABLE fee; - RESETABLE free; - RESETABLE traffType; - RESETABLE passiveCost; - RESETABLE name; - RESETABLE period; + RESETABLE fee; + RESETABLE free; + RESETABLE traffType; + RESETABLE passiveCost; + RESETABLE name; + RESETABLE period; }; //----------------------------------------------------------------------------- struct TARIFF_DATA -- 2.44.2