]> git.stg.codes - stg.git/blobdiff - include/stg/tariff_conf.h
Various fixes of issues reported by static analyzers.
[stg.git] / include / stg / tariff_conf.h
index fc9807beb88fc13763b1f597a2b7f5e8446f247c..f705d0a0bef90e4e8575791505a76df8cb81934a 100644 (file)
 #include <string>
 #include <vector>
 
-//-----------------------------------------------------------------------------
-enum
-{
-    TRAFF_UP = 0,
-    TRAFF_DOWN,
-    TRAFF_UP_DOWN,
-    TRAFF_MAX
-};
 //-----------------------------------------------------------------------------
 struct DIRPRICE_DATA
 {
@@ -106,18 +98,17 @@ struct DIRPRICE_DATA_RES
     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();
-
-        dd.priceNightA = priceNightA.data();
-        dd.priceNightB = priceNightB.data();
-        dd.singlePrice = singlePrice.data();
-        dd.threshold   = threshold.data();
+        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;
         }
 
@@ -151,29 +142,35 @@ 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::CHANGE_POLICY changePolicy;
+    time_t changePolicyTimeout;
 
     TARIFF_CONF()
         : 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 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)
+          period(TARIFF::MONTH),
+          changePolicy(TARIFF::ALLOW),
+          changePolicyTimeout(0)
         {}
 };
 //-----------------------------------------------------------------------------
@@ -185,7 +182,9 @@ struct TARIFF_CONF_RES
           traffType(),
           passiveCost(),
           name(),
-          period()
+          period(),
+          changePolicy(),
+          changePolicyTimeout()
         {}
 
     TARIFF_CONF_RES & operator=(const TARIFF_CONF & tc)
@@ -196,27 +195,33 @@ struct TARIFF_CONF_RES
         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();
+        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;
         }
 
-    RESETABLE<double>         fee;
-    RESETABLE<double>         free;
-    RESETABLE<int>            traffType;
-    RESETABLE<double>         passiveCost;
-    RESETABLE<std::string>    name;
-    RESETABLE<TARIFF::PERIOD> period;
+    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
@@ -229,22 +234,10 @@ struct TARIFF_DATA
           dirPrice(DIR_NUM)
         {}
 
-    TARIFF_DATA(const std::string & name)
+    explicit TARIFF_DATA(const std::string & name)
         : 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
@@ -257,6 +250,14 @@ struct TARIFF_DATA_RES
           dirPrice(DIR_NUM)
         {}
 
+    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;