X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6c05b2e63b58b19df2f35707fa12f238a18458e7..46b0747592074017ff0ea4b33d4a7194235886e5:/stglibs/srvconf.lib/parsers/chg_tariff.cpp diff --git a/stglibs/srvconf.lib/parsers/chg_tariff.cpp b/stglibs/srvconf.lib/parsers/chg_tariff.cpp deleted file mode 100644 index c23cd0cd..00000000 --- a/stglibs/srvconf.lib/parsers/chg_tariff.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Maxim Mamontov - */ - -#include "chg_tariff.h" - -#include "stg/tariff_conf.h" -#include "stg/common.h" - -#include - -#include - -using namespace STG; - -namespace -{ - -template -void appendResetable(std::ostream & stream, const std::string & name, const T & value) -{ -if (!value.empty()) - stream << "<" << name << " value=\"" << value.data() << "\"/>"; -} - -template -void appendSlashedResetable(std::ostream & stream, const std::string & name, const A & array, T A::value_type:: * field) -{ -std::string res; -for (typename A::size_type i = 0; i < array.size(); ++i) - { - if ((array[i].*field).empty()) // All values must be set - return; - if (!res.empty()) - res += "/"; - res += x2str((array[i].*field).data()); - } -stream << "<" << name << " value=\"" << res << "\"/>"; -} - -} // namespace anonymous - -std::string CHG_TARIFF::Serialize(const TARIFF_DATA_RES & data) -{ -std::ostringstream stream; - -appendResetable(stream, "fee", data.tariffConf.fee); -appendResetable(stream, "passiveCost", data.tariffConf.passiveCost); -appendResetable(stream, "free", data.tariffConf.free); - -if (!data.tariffConf.traffType.empty()) - switch (data.tariffConf.traffType.data()) - { - case TRAFF_UP: stream << ""; break; - case TRAFF_DOWN: stream << ""; break; - case TRAFF_UP_DOWN: stream << ""; break; - case TRAFF_MAX: stream << ""; break; - } - -for (size_t i = 0; i < DIR_NUM; ++i) - if (!data.dirPrice[i].hDay.empty() && - !data.dirPrice[i].mDay.empty() && - !data.dirPrice[i].hNight.empty() && - !data.dirPrice[i].mNight.empty()) - stream << ""; - -appendSlashedResetable(stream, "priceDayA", data.dirPrice, &DIRPRICE_DATA_RES::priceDayA); -appendSlashedResetable(stream, "priceDayB", data.dirPrice, &DIRPRICE_DATA_RES::priceDayB); -appendSlashedResetable(stream, "priceNightA", data.dirPrice, &DIRPRICE_DATA_RES::priceNightA); -appendSlashedResetable(stream, "priceNightB", data.dirPrice, &DIRPRICE_DATA_RES::priceNightB); -appendSlashedResetable(stream, "singlePrice", data.dirPrice, &DIRPRICE_DATA_RES::singlePrice); -appendSlashedResetable(stream, "noDiscount", data.dirPrice, &DIRPRICE_DATA_RES::noDiscount); - -return stream.str(); -}