]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp
Lots of stylistic fixes.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_tariff.cpp
index e2daa336f45b4410a032e8d091e9607477e7c093..a4531703c54de43765b319b3f6f22f1b015c1267 100644 (file)
@@ -1,8 +1,8 @@
 #include <cstdio> // snprintf
 #include <cstring>
 
+#include "stg/tariffs.h"
 #include "parser.h"
-#include "tariffs.h"
 
 const int pt_mega = 1024 * 1024;
 //-----------------------------------------------------------------------------
@@ -29,7 +29,7 @@ return -1;
 //-----------------------------------------------------------------------------
 void PARSER_GET_TARIFFS::CreateAnswer()
 {
-string s;
+std::string s;
 char vs[100];
 int hd, hn, md, mn;
 
@@ -145,6 +145,8 @@ for (; it != dataList.end(); ++it)
             break;
         }
 
+    answerList->push_back("<Period value=\"" + TARIFF::PeriodToString(it->tariffConf.period) + "\"/>");
+
     answerList->push_back("</tariff>");
     }
 answerList->push_back("</Tariffs>");
@@ -180,13 +182,13 @@ void PARSER_ADD_TARIFF::CreateAnswer()
 //answerList->clear();
 answerList->erase(answerList->begin(), answerList->end());
 
-if (tariffs->Add(tariffToAdd, *currAdmin) == 0)
+if (tariffs->Add(tariffToAdd, currAdmin) == 0)
     {
     answerList->push_back("<AddTariff Result=\"Ok\"/>");
     }
 else
     {
-    string s;
+    std::string s;
     strprintf(&s, "<AddTariff Result=\"Error. %s\"/>", tariffs->GetStrError().c_str());
     answerList->push_back(s);
     }
@@ -222,19 +224,19 @@ answerList->erase(answerList->begin(), answerList->end());
 
 if (users->TariffInUse(tariffToDel))
     {
-    string s;
+    std::string s;
     strprintf(&s, "<DelTariff Result=\"Error. Tariff \'%s\' cannot be deleted. Tariff in use.\"/>", tariffToDel.c_str());
     answerList->push_back(s);
     return;
     }
 
-if (tariffs->Del(tariffToDel, *currAdmin) == 0)
+if (tariffs->Del(tariffToDel, currAdmin) == 0)
     {
     answerList->push_back("<DelTariff Result=\"Ok\"/>");
     }
 else
     {
-    string s;
+    std::string s;
     strprintf(&s, "<DelTariff Result=\"Error. %s\"/>", tariffs->GetStrError().c_str());
     answerList->push_back(s);
     }
@@ -244,7 +246,7 @@ else
 //  CHG TARIFF
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-int PARSER_CHG_TARIFF::ParseSlashedIntParams(int paramsNum, const string & s, int * params)
+int PARSER_CHG_TARIFF::ParseSlashedIntParams(int paramsNum, const std::string & s, int * params)
 {
 char * str = new char[s.size() + 1];
 char * p;
@@ -272,7 +274,7 @@ delete[] str;
 return 0;
 }
 //-----------------------------------------------------------------------------
-int PARSER_CHG_TARIFF::ParseSlashedDoubleParams(int paramsNum, const string & s, double * params)
+int PARSER_CHG_TARIFF::ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params)
 {
 char * str = new char[s.size() + 1];
 char * p;
@@ -302,7 +304,6 @@ return 0;
 //-----------------------------------------------------------------------------
 int PARSER_CHG_TARIFF::ParseStart(void *, const char * el, const char ** attr)
 {
-char st[50];
 double price[DIR_NUM];
 int t[DIR_NUM];
 depth++;
@@ -317,7 +318,7 @@ if (depth == 1)
     }
 else
     {
-    string s;
+    std::string s;
 
     if (strcasecmp(el, "PriceDayA") == 0)
         {
@@ -385,10 +386,14 @@ else
 
     for (int j = 0; j < DIR_NUM; j++)
         {
+        char st[50];
         snprintf(st, 50, "Time%d", j);
         if (strcasecmp(el, st) == 0)
             {
-            int h1, m1, h2, m2;
+            int h1 = 0;
+            int m1 = 0;
+            int h2 = 0;
+            int m2 = 0;
             if (ParseTariffTimeStr(attr[1], h1, m1, h2, m2) == 0)
                 {
                 td.dirPrice[j].hDay = h1;
@@ -448,6 +453,12 @@ else
             }
         return 0;
         }
+
+    if (strcasecmp(el, "Period") == 0)
+        {
+        td.tariffConf.period = TARIFF::StringToPeriod(attr[1]);
+        return 0;
+        }
     }
 return -1;
 }
@@ -475,14 +486,14 @@ answerList->erase(answerList->begin(), answerList->end());
 if (!td.tariffConf.name.data().empty())
     {
     TARIFF_DATA tariffData = td.GetData();
-    if (tariffs->Chg(tariffData, *currAdmin) == 0)
+    if (tariffs->Chg(tariffData, currAdmin) == 0)
         {
         answerList->push_back("<SetTariff Result=\"ok\"/>");
         return;
         }
     else
         {
-        string s;
+        std::string s;
         strprintf(&s, "<SetTariff Result=\"Change tariff error! %s\"/>", tariffs->GetStrError().c_str());
         answerList->push_back(s);
         return;