]> git.stg.codes - stg.git/blobdiff - include/stg/tariff_conf.h
Merge branch 'stg-2.409' into stg-2.409-radius
[stg.git] / include / stg / tariff_conf.h
index 30f1981593392091457a771676058d2b5945bf94..f705d0a0bef90e4e8575791505a76df8cb81934a 100644 (file)
 #ifndef TARIFF_CONF_H
 #define TARIFF_CONF_H
 
 #ifndef TARIFF_CONF_H
 #define TARIFF_CONF_H
 
+#include "tariff.h"
+#include "resetable.h"
+#include "const.h"
+
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
 
-#include "resetable.h"
-#include "stg_const.h"
-
-//-----------------------------------------------------------------------------
-enum
-{
-    TRAFF_UP = 0,
-    TRAFF_DOWN,
-    TRAFF_UP_DOWN,
-    TRAFF_MAX
-};
 //-----------------------------------------------------------------------------
 struct DIRPRICE_DATA
 {
 //-----------------------------------------------------------------------------
 struct DIRPRICE_DATA
 {
@@ -57,95 +50,143 @@ struct DIRPRICE_DATA
           singlePrice(0),
           noDiscount(0)
         {}
           singlePrice(0),
           noDiscount(0)
         {}
-    int     hDay;
-    int     mDay;
-    int     hNight;
-    int     mNight;
-    double  priceDayA;
-    double  priceNightA;
-    double  priceDayB;
-    double  priceNightB;
-    int     threshold;
-    int     singlePrice; // Do not use day/night division
-    int     noDiscount; // Do not use threshold
+    int    hDay;
+    int    mDay;
+    int    hNight;
+    int    mNight;
+    double priceDayA;
+    double priceNightA;
+    double priceDayB;
+    double priceNightB;
+    int    threshold;
+    int    singlePrice; // Do not use day/night division
+    int    noDiscount; // Do not use threshold
 };
 //-----------------------------------------------------------------------------
 struct DIRPRICE_DATA_RES
 {
 };
 //-----------------------------------------------------------------------------
 struct DIRPRICE_DATA_RES
 {
-    DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & dpd)
+    DIRPRICE_DATA_RES()
+        : hDay(),
+          mDay(),
+          hNight(),
+          mNight(),
+          priceDayA(),
+          priceNightA(),
+          priceDayB(),
+          priceNightB(),
+          threshold(),
+          singlePrice(),
+          noDiscount()
+        {}
+
+    DIRPRICE_DATA_RES & operator= (const DIRPRICE_DATA & rvalue)
         {
         {
-        hDay        = dpd.hDay;
-        mDay        = dpd.mDay;
-        hNight      = dpd.hNight;
-        mNight      = dpd.mNight;
-        priceDayA   = dpd.priceDayA;
-        priceNightA = dpd.priceNightA;
-        priceDayB   = dpd.priceDayB;
-        priceNightB = dpd.priceNightB;
-        threshold   = dpd.threshold;
-        singlePrice = dpd.singlePrice;
-        noDiscount  = dpd.noDiscount;
+        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;
         return *this;
-        };
+        }
 
 
-    DIRPRICE_DATA GetData()
+    DIRPRICE_DATA GetData() const
         {
         DIRPRICE_DATA dd;
         {
         DIRPRICE_DATA dd;
-        dd.hDay        = hDay;
-        dd.hNight      = hNight;
-        dd.mDay        = mDay;
-        dd.mNight      = mNight;
-        dd.noDiscount  = noDiscount;
-        dd.priceDayA   = priceDayA;
-        dd.priceDayB   = priceDayB;
-
-        dd.priceNightA = priceNightA;
-        dd.priceNightB = priceNightB;
-        dd.singlePrice = singlePrice;
-        dd.threshold   = threshold;
+        hDay.maybeSet(dd.hDay);
+        hNight.maybeSet(dd.hNight);
+        mDay.maybeSet(dd.mDay);
+        mNight.maybeSet(dd.mNight);
+        noDiscount.maybeSet(dd.noDiscount);
+        priceDayA.maybeSet(dd.priceDayA);
+        priceDayB.maybeSet(dd.priceDayB);
+        priceNightA.maybeSet(dd.priceNightA);
+        priceNightB.maybeSet(dd.priceNightB);
+        singlePrice.maybeSet(dd.singlePrice);
+        threshold.maybeSet(dd.threshold);
         return dd;
         }
 
         return dd;
         }
 
-    RESETABLE<int>     hDay;
-    RESETABLE<int>     mDay;
-    RESETABLE<int>     hNight;
-    RESETABLE<int>     mNight;
-    RESETABLE<double>  priceDayA;
-    RESETABLE<double>  priceNightA;
-    RESETABLE<double>  priceDayB;
-    RESETABLE<double>  priceNightB;
-    RESETABLE<int>     threshold;
-    RESETABLE<int>     singlePrice;
-    RESETABLE<int>     noDiscount;
+    void Splice(const DIRPRICE_DATA_RES & rhs)
+        {
+        hDay.splice(rhs.hDay);
+        mDay.splice(rhs.mDay);
+        hNight.splice(rhs.hNight);
+        mNight.splice(rhs.mNight);
+        priceDayA.splice(rhs.priceDayA);
+        priceNightA.splice(rhs.priceNightA);
+        priceDayB.splice(rhs.priceDayB);
+        priceNightB.splice(rhs.priceNightB);
+        threshold.splice(rhs.threshold);
+        singlePrice.splice(rhs.singlePrice);
+        noDiscount.splice(rhs.noDiscount);
+        }
+
+    RESETABLE<int>    hDay;
+    RESETABLE<int>    mDay;
+    RESETABLE<int>    hNight;
+    RESETABLE<int>    mNight;
+    RESETABLE<double> priceDayA;
+    RESETABLE<double> priceNightA;
+    RESETABLE<double> priceDayB;
+    RESETABLE<double> priceNightB;
+    RESETABLE<int>    threshold;
+    RESETABLE<int>    singlePrice;
+    RESETABLE<int>    noDiscount;
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_CONF
 {
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_CONF
 {
-    double      fee;                 // ÷ÅÌÉÞÉÎÁ ÁÂÏÎÐÌÁÔÙ
-    double      free;                // îÁ ËÁËÕÀ ÓÕÍÍÕ ÄÅÎÅÇ ÀÚÅÒ ËÁÞÁÅÔ ÂÅÓÐÌÁÔÎÏ
-    int         traffType;           // UP, DOWN, UP+DOWN, MAX
-    double      passiveCost;         // óÔÏÉÍÏÓÔØ ÚÁÍÏÒÏÚËÉ
-    std::string name;
+    double             fee;
+    double             free;
+    TARIFF::TRAFF_TYPE traffType;
+    double             passiveCost;
+    std::string        name;
+    TARIFF::PERIOD     period;
+    TARIFF::CHANGE_POLICY changePolicy;
+    time_t changePolicyTimeout;
 
     TARIFF_CONF()
         : fee(0),
           free(0),
 
     TARIFF_CONF()
         : fee(0),
           free(0),
-          traffType(TRAFF_UP_DOWN),              // UP-DOWN
+          traffType(TARIFF::TRAFF_UP_DOWN),
           passiveCost(0),
           passiveCost(0),
-          name()
-        {};
+          name(),
+          period(TARIFF::MONTH),
+          changePolicy(TARIFF::ALLOW),
+          changePolicyTimeout(0)
+        {}
 
 
-    TARIFF_CONF(const std::string & n)
+    explicit TARIFF_CONF(const std::string & n)
         : fee(0),
           free(0),
         : fee(0),
           free(0),
-          traffType(TRAFF_UP_DOWN),              // UP-DOWN
+          traffType(TARIFF::TRAFF_UP_DOWN),
           passiveCost(0),
           passiveCost(0),
-          name(n)
-        {};
+          name(n),
+          period(TARIFF::MONTH),
+          changePolicy(TARIFF::ALLOW),
+          changePolicyTimeout(0)
+        {}
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_CONF_RES
 {
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_CONF_RES
 {
+    TARIFF_CONF_RES()
+        : fee(),
+          free(),
+          traffType(),
+          passiveCost(),
+          name(),
+          period(),
+          changePolicy(),
+          changePolicyTimeout()
+        {}
+
     TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc)
         {
         fee         = tc.fee;
     TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc)
         {
         fee         = tc.fee;
@@ -153,58 +194,55 @@ struct TARIFF_CONF_RES
         traffType   = tc.traffType;
         passiveCost = tc.passiveCost;
         name        = tc.name;
         traffType   = tc.traffType;
         passiveCost = tc.passiveCost;
         name        = tc.name;
+        period      = tc.period;
+        changePolicy = tc.changePolicy;
+        changePolicyTimeout = tc.changePolicyTimeout;
         return *this;
         return *this;
-        };
+        }
 
 
-    TARIFF_CONF GetData()
+    TARIFF_CONF GetData() const
         {
         TARIFF_CONF tc;
         {
         TARIFF_CONF tc;
-        tc.fee         = fee;
-        tc.free        = free;
-        tc.name        = name;
-        tc.passiveCost = passiveCost;
-        tc.traffType   = traffType;
+        fee.maybeSet(tc.fee);
+        free.maybeSet(tc.free);
+        name.maybeSet(tc.name);
+        passiveCost.maybeSet(tc.passiveCost);
+        traffType.maybeSet(tc.traffType);
+        period.maybeSet(tc.period);
+        changePolicy.maybeSet(tc.changePolicy);
+        changePolicyTimeout.maybeSet(tc.changePolicyTimeout);
         return tc;
         }
 
         return tc;
         }
 
-    RESETABLE<double>       fee;
-    RESETABLE<double>       free;
-    RESETABLE<int>          traffType;
-    RESETABLE<double>       passiveCost;
-    RESETABLE<std::string>  name;
+    RESETABLE<double>             fee;
+    RESETABLE<double>             free;
+    RESETABLE<TARIFF::TRAFF_TYPE> traffType;
+    RESETABLE<double>             passiveCost;
+    RESETABLE<std::string>        name;
+    RESETABLE<TARIFF::PERIOD>     period;
+    RESETABLE<TARIFF::CHANGE_POLICY> changePolicy;
+    RESETABLE<time_t>             changePolicyTimeout;
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_DATA
 {
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_DATA
 {
-    TARIFF_CONF                 tariffConf;
-    std::vector<DIRPRICE_DATA>  dirPrice;
+    TARIFF_CONF                tariffConf;
+    std::vector<DIRPRICE_DATA> dirPrice;
 
     TARIFF_DATA()
         : tariffConf(),
           dirPrice(DIR_NUM)
         {}
 
 
     TARIFF_DATA()
         : tariffConf(),
           dirPrice(DIR_NUM)
         {}
 
-    TARIFF_DATA(const std::string & name)
+    explicit TARIFF_DATA(const std::string & name)
         : tariffConf(name),
           dirPrice(DIR_NUM)
         {}
         : 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;
-        };
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_DATA_RES
 {
 };
 //-----------------------------------------------------------------------------
 struct TARIFF_DATA_RES
 {
-    TARIFF_CONF_RES     tariffConf;
+    TARIFF_CONF_RES                tariffConf;
     std::vector<DIRPRICE_DATA_RES> dirPrice;
 
     TARIFF_DATA_RES()
     std::vector<DIRPRICE_DATA_RES> dirPrice;
 
     TARIFF_DATA_RES()
@@ -212,11 +250,19 @@ struct TARIFF_DATA_RES
           dirPrice(DIR_NUM)
         {}
 
           dirPrice(DIR_NUM)
         {}
 
-    TARIFF_DATA GetData()
+    TARIFF_DATA_RES & operator=(const TARIFF_DATA & td)
+        {
+        tariffConf = td.tariffConf;
+        for (size_t i = 0; i < DIR_NUM; ++i)
+            dirPrice[i] = td.dirPrice[i];
+        return *this;
+        }
+
+    TARIFF_DATA GetData() const
         {
         TARIFF_DATA td;
         td.tariffConf = tariffConf.GetData();
         {
         TARIFF_DATA td;
         td.tariffConf = tariffConf.GetData();
-        for (int i = 0; i < DIR_NUM; i++)
+        for (size_t i = 0; i < DIR_NUM; i++)
             td.dirPrice[i] = dirPrice[i].GetData();
         return td;
         }
             td.dirPrice[i] = dirPrice[i].GetData();
         return td;
         }