X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/c65b73de5dfbbb54f7b977a9fcd72d1abbb1e827..8c7e6453aff765245cc5c28f37543f13d92dbe74:/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp?ds=sidebyside diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index 2e8d1ff3..0607db6f 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -23,7 +23,6 @@ #include "stg/tariffs.h" #include "stg/users.h" -#include "stg/common.h" #include "stg/resetable.h" #include // snprintf @@ -34,6 +33,11 @@ using STG::PARSER::ADD_TARIFF; using STG::PARSER::DEL_TARIFF; using STG::PARSER::CHG_TARIFF; +const char * GET_TARIFFS::tag = "GetTariffs"; +const char * ADD_TARIFF::tag = "AddTariff"; +const char * DEL_TARIFF::tag = "DelTariff"; +const char * CHG_TARIFF::tag = "SetTariff"; + namespace { @@ -52,6 +56,16 @@ std::string AOS2String(const A & array, size_t size, const F C::* field, F multi return res; } +template +bool str2res(const std::string& source, RESETABLE& dest, T divisor) +{ + T value = 0; + if (str2x(source, value)) + return false; + dest = value / divisor; + return true; +} + template bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE C::* field, F divisor) { @@ -60,15 +74,13 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE std::string::size_type pos = 0; while (index < size && (pos = source.find('/', from)) != std::string::npos) { - if (str2x(source.substr(from, pos - from), (array[index].*field).data())) + if (!str2res(source.substr(from, pos - from), array[index].*field, divisor)) return false; - (array[index].*field).data() /= divisor; from = pos + 1; ++index; } - if (str2x(source.substr(from), (array[index].*field).data())) + if (str2res(source.substr(from), array[index].*field, divisor)) return false; - (array[index].*field).data() /= divisor; return true; } @@ -76,7 +88,7 @@ bool String2AOS(const std::string & source, A & array, size_t size, RESETABLE void GET_TARIFFS::CreateAnswer() { - m_answer = GetOpenTag(); + m_answer = ""; std::list dataList; m_tariffs.GetTariffsData(&dataList); @@ -105,7 +117,7 @@ void GET_TARIFFS::CreateAnswer() ""; } - m_answer += GetCloseTag(); + m_answer += ""; } int ADD_TARIFF::Start(void *, const char * el, const char ** attr)