From: Maksym Mamontov Date: Mon, 27 Jan 2020 21:20:21 +0000 (+0200) Subject: Remove std::list from tariffs. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/de9e44e256657beb5160021c7e4fd21d8a9a21d2?ds=sidebyside;hp=8337f36907f14b1e9979108800e82b8e0ca47a59 Remove std::list from tariffs. --- diff --git a/include/stg/tariffs.h b/include/stg/tariffs.h index 6a851c5a..51179d2f 100644 --- a/include/stg/tariffs.h +++ b/include/stg/tariffs.h @@ -22,7 +22,7 @@ #define TARIFFS_H #include -#include +#include #include "notifer.h" @@ -32,8 +32,6 @@ struct TARIFF_DATA; class TARIFFS { public: - typedef std::list Tariffs; - virtual ~TARIFFS() {} virtual int ReadTariffs () = 0; virtual const TARIFF * FindByName(const std::string & name) const = 0; @@ -48,7 +46,7 @@ public: virtual void AddNotifierDel(NOTIFIER_BASE * notifier) = 0; virtual void DelNotifierDel(NOTIFIER_BASE * notifier) = 0; - virtual void GetTariffsData(std::list * tdl) const = 0; + virtual void GetTariffsData(std::vector * tdl) const = 0; virtual size_t Count() const = 0; diff --git a/stargazer/plugins/configuration/rpcconfig/tariffs_methods.cpp b/stargazer/plugins/configuration/rpcconfig/tariffs_methods.cpp index 77d73b02..bbb0a5be 100644 --- a/stargazer/plugins/configuration/rpcconfig/tariffs_methods.cpp +++ b/stargazer/plugins/configuration/rpcconfig/tariffs_methods.cpp @@ -107,9 +107,9 @@ if (config->GetAdminInfo(cookie, &adminInfo)) std::vector tariffsInfo; -std::list dataList; +std::vector dataList; tariffs->GetTariffsData(&dataList); -std::list::const_iterator it = dataList.begin(); +auto it = dataList.begin(); for (; it != dataList.end(); ++it) { xmlrpc_c::value info; diff --git a/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index dfe6b552..ae22cf04 100644 --- a/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -90,9 +90,9 @@ void GET_TARIFFS::CreateAnswer() { m_answer = ""; - std::list dataList; + std::vector dataList; m_tariffs.GetTariffsData(&dataList); - std::list::const_iterator it = dataList.begin(); + auto it = dataList.begin(); for (; it != dataList.end(); ++it) { m_answer += "tariffConf.name + "\">"; diff --git a/stargazer/plugins/other/smux/tables.cpp b/stargazer/plugins/other/smux/tables.cpp index c3e3ef54..a9b5e822 100644 --- a/stargazer/plugins/other/smux/tables.cpp +++ b/stargazer/plugins/other/smux/tables.cpp @@ -15,7 +15,7 @@ void TariffUsersTable::UpdateSensors(Sensors & sensors) const { std::map data; -std::list tdl; +std::vector tdl; tariffs.GetTariffsData(&tdl); std::transform(tdl.begin(), tdl.end(), diff --git a/stargazer/tariffs_impl.cpp b/stargazer/tariffs_impl.cpp index d47ecf8f..c8345eb1 100644 --- a/stargazer/tariffs_impl.cpp +++ b/stargazer/tariffs_impl.cpp @@ -99,8 +99,7 @@ if (name == NO_TARIFF_NAME) return &noTariff; STG_LOCKER lock(&mutex); -std::list::const_iterator ti; -ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); +const auto ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) return &(*ti); @@ -123,8 +122,7 @@ if (!priv->tariffChg) STG_LOCKER lock(&mutex); -std::list::iterator ti; -ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(td.tariffConf.name)); +auto ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(td.tariffConf.name)); if (ti == tariffs.end()) { @@ -166,8 +164,7 @@ TARIFF_DATA td; { STG_LOCKER lock(&mutex); - std::list::iterator ti; - ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); + const auto ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti == tariffs.end()) { @@ -188,7 +185,7 @@ TARIFF_DATA td; tariffs.erase(ti); } -std::set *>::iterator ni = onDelNotifiers.begin(); +auto ni = onDelNotifiers.begin(); while (ni != onDelNotifiers.end()) { (*ni)->Notify(td); @@ -217,8 +214,7 @@ if (!priv->tariffChg) { STG_LOCKER lock(&mutex); - std::list::iterator ti; - ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); + const auto ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) { @@ -238,7 +234,7 @@ if (store->AddTariff(name) < 0) } // Fire all "on add" notifiers -std::set *>::iterator ni = onAddNotifiers.begin(); +auto ni = onAddNotifiers.begin(); while (ni != onAddNotifiers.end()) { (*ni)->Notify(tariffs.back().GetTariffData()); @@ -251,12 +247,12 @@ WriteServLog("%s Tariff \'%s\' added.", return 0; } //----------------------------------------------------------------------------- -void TARIFFS_IMPL::GetTariffsData(std::list * tdl) const +void TARIFFS_IMPL::GetTariffsData(std::vector * tdl) const { assert(tdl != NULL && "Tariffs data list is not null"); STG_LOCKER lock(&mutex); -Tariffs::const_iterator it = tariffs.begin(); +auto it = tariffs.begin(); for (; it != tariffs.end(); ++it) { tdl->push_back(it->GetTariffData()); diff --git a/stargazer/tariffs_impl.h b/stargazer/tariffs_impl.h index 55cc49b3..c4f0f883 100644 --- a/stargazer/tariffs_impl.h +++ b/stargazer/tariffs_impl.h @@ -31,7 +31,7 @@ #include "tariff_impl.h" #include -#include +#include #include #include @@ -45,7 +45,7 @@ class ADMIN; class TARIFFS_IMPL : public TARIFFS { public: - typedef std::list Tariffs; + using Tariffs = std::vector; explicit TARIFFS_IMPL(STORE * store); virtual ~TARIFFS_IMPL(); @@ -63,7 +63,7 @@ public: void AddNotifierDel(NOTIFIER_BASE * notifier); void DelNotifierDel(NOTIFIER_BASE * notifier); - void GetTariffsData(std::list * tdl) const; + void GetTariffsData(std::vector * tdl) const; const std::string & GetStrError() const { return strError; } diff --git a/tests/testtariffs.h b/tests/testtariffs.h index f43bc22b..11c4cfff 100644 --- a/tests/testtariffs.h +++ b/tests/testtariffs.h @@ -22,7 +22,7 @@ class TEST_TARIFFS : public TARIFFS { void AddNotifierDel(NOTIFIER_BASE *) {} void DelNotifierDel(NOTIFIER_BASE *) {} - void GetTariffsData(std::list * /*tdl*/) const {} + void GetTariffsData(std::vector * /*tdl*/) const {} size_t Count() const { return 0; }