X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/1347f3d1e04bedd1508589173f577673ee2c5554..4243cf76394d6e657a1a8b67645d3d655efd1b07:/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp?ds=sidebyside diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp index 7be1af96..e083f852 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp @@ -1,8 +1,11 @@ -#include // snprintf -#include +#include "parser.h" #include "stg/tariffs.h" -#include "parser.h" +#include "stg/users.h" +#include "stg/common.h" + +#include // snprintf +#include const int pt_mega = 1024 * 1024; //----------------------------------------------------------------------------- @@ -29,125 +32,131 @@ return -1; //----------------------------------------------------------------------------- void PARSER_GET_TARIFFS::CreateAnswer() { -std::string s; -char vs[100]; -int hd, hn, md, mn; - -answerList->erase(answerList->begin(), answerList->end()); - -answerList->push_back(""); +answer = ""; std::list dataList; tariffs->GetTariffsData(&dataList); std::list::const_iterator it = dataList.begin(); for (; it != dataList.end(); ++it) { - s = "tariffConf.name + "\">"; - answerList->push_back(s); + answer += "tariffConf.name + "\">"; - for (int j = 0; j < DIR_NUM; j++) - { - hd = it->dirPrice[j].hDay; - md = it->dirPrice[j].mDay; - - hn = it->dirPrice[j].hNight; - mn = it->dirPrice[j].mNight; - - strprintf(&s, "", j, hd, md, hn, mn); - answerList->push_back(s); - } + for (size_t i = 0; i < DIR_NUM; i++) + answer += "dirPrice[i].hDay) + ":" + x2str(it->dirPrice[i].mDay) + "-" + + x2str(it->dirPrice[i].hNight) + ":" + x2str(it->dirPrice[i].mNight) + "\"/>"; - strprintf(&s, " dirPrice[i].priceDayA * pt_mega, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += x2str(it->dirPrice[i].priceDayA * pt_mega); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " dirPrice[i].priceDayB * pt_mega, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += x2str(it->dirPrice[i].priceDayB * pt_mega); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " dirPrice[i].priceNightA * pt_mega, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += x2str(it->dirPrice[i].priceNightA * pt_mega); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " dirPrice[i].priceNightB * pt_mega, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += x2str(it->dirPrice[i].priceNightB * pt_mega); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " dirPrice[i].threshold, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += x2str(it->dirPrice[i].threshold); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " dirPrice[i].singlePrice, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += (it->dirPrice[i].singlePrice ? "1" : "0"); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " dirPrice[i].noDiscount, i+1 == DIR_NUM?"":"/"); - s += vs; + if (first) + first = false; + else + answer += "/"; + answer += (it->dirPrice[i].noDiscount ? "1" : "0"); } - s += "\"/>"; - answerList->push_back(s); + answer += "\"/>"; - strprintf(&s, " ", it->tariffConf.fee); - answerList->push_back(s); + answer += "tariffConf.fee) + "\"/>"; - strprintf(&s, " ", it->tariffConf.passiveCost); - answerList->push_back(s); + answer += "tariffConf.passiveCost) + "\"/>"; - strprintf(&s, " ", it->tariffConf.free); - answerList->push_back(s); + answer += "tariffConf.free) + "\"/>"; switch (it->tariffConf.traffType) { case TRAFF_UP: - answerList->push_back(""); + answer += ""; break; case TRAFF_DOWN: - answerList->push_back(""); + answer += ""; break; case TRAFF_UP_DOWN: - answerList->push_back(""); + answer += ""; break; case TRAFF_MAX: - answerList->push_back(""); + answer += ""; break; } - answerList->push_back(""); + answer += "tariffConf.period) + "\"/>"; + + answer += ""; } -answerList->push_back(""); +answer += ""; } //----------------------------------------------------------------------------- // ADD TARIFF @@ -177,19 +186,10 @@ return -1; //----------------------------------------------------------------------------- void PARSER_ADD_TARIFF::CreateAnswer() { -//answerList->clear(); -answerList->erase(answerList->begin(), answerList->end()); - if (tariffs->Add(tariffToAdd, currAdmin) == 0) - { - answerList->push_back(""); - } + answer = ""; else - { - std::string s; - strprintf(&s, "", tariffs->GetStrError().c_str()); - answerList->push_back(s); - } + answer = "GetStrError() + "\"/>"; } //----------------------------------------------------------------------------- // DEL TARIFF @@ -217,27 +217,12 @@ return -1; //----------------------------------------------------------------------------- void PARSER_DEL_TARIFF::CreateAnswer() { -//answerList->clear(); -answerList->erase(answerList->begin(), answerList->end()); - if (users->TariffInUse(tariffToDel)) - { - std::string s; - strprintf(&s, "", tariffToDel.c_str()); - answerList->push_back(s); - return; - } - -if (tariffs->Del(tariffToDel, currAdmin) == 0) - { - answerList->push_back(""); - } + answer = ""; +else if (tariffs->Del(tariffToDel, currAdmin) == 0) + answer = ""; else - { - std::string s; - strprintf(&s, "", tariffs->GetStrError().c_str()); - answerList->push_back(s); - } + answer = "GetStrError() + "\"/>"; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -302,7 +287,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++; @@ -385,6 +369,7 @@ else for (int j = 0; j < DIR_NUM; j++) { + char st[50]; snprintf(st, 50, "Time%d", j); if (strcasecmp(el, st) == 0) { @@ -451,6 +436,12 @@ else } return 0; } + + if (strcasecmp(el, "Period") == 0) + { + td.tariffConf.period = TARIFF::StringToPeriod(attr[1]); + return 0; + } } return -1; } @@ -473,24 +464,20 @@ return -1; //----------------------------------------------------------------------------- void PARSER_CHG_TARIFF::CreateAnswer() { -answerList->erase(answerList->begin(), answerList->end()); - if (!td.tariffConf.name.data().empty()) { TARIFF_DATA tariffData = td.GetData(); if (tariffs->Chg(tariffData, currAdmin) == 0) { - answerList->push_back(""); + answer = ""; return; } else { - std::string s; - strprintf(&s, "", tariffs->GetStrError().c_str()); - answerList->push_back(s); + answer = "GetStrError() + "\"/>"; return; } } -answerList->push_back(""); +answer = ""; } //-----------------------------------------------------------------------------