X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6171920df2f880303b54c19d7c5169c64b485585..acdf6ab94fee26ebc4017bf32cf6171c7d9462e9:/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h index f31257df..9f9c5031 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h @@ -19,21 +19,22 @@ * Author : Maxim Mamontov */ -#ifndef __STG_SGCONFIG_PARSER_TARIFFS_H__ -#define __STG_SGCONFIG_PARSER_TARIFFS_H__ +#pragma once #include "parser.h" #include "stg/tariff_conf.h" +#include "stg/common.h" #include -class TARIFFS; -class USERS; -class ADMIN; - namespace STG { + +struct Tariffs; +struct Users; +struct Admin; + namespace PARSER { @@ -43,20 +44,21 @@ class GET_TARIFFS: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, const TARIFFS & tariffs) - : m_admin(admin), m_tariffs(tariffs) - {} - virtual BASE_PARSER * create() { return new GET_TARIFFS(m_admin, m_tariffs); } + explicit FACTORY(const Tariffs & tariffs) : m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const Admin & admin) { return new GET_TARIFFS(admin, m_tariffs); } + static void Register(REGISTRY & registry, const Tariffs & tariffs) + { registry[ToLower(tag)] = new FACTORY(tariffs); } private: - const ADMIN & m_admin; - const TARIFFS & m_tariffs; + const Tariffs & m_tariffs; }; - GET_TARIFFS(const ADMIN & admin, const TARIFFS & tariffs) - : BASE_PARSER(admin, "GetTariffs"), m_tariffs(tariffs) {} + static const char * tag; + + GET_TARIFFS(const Admin & admin, const Tariffs & tariffs) + : BASE_PARSER(admin, tag), m_tariffs(tariffs) {} private: - const TARIFFS & m_tariffs; + const Tariffs & m_tariffs; void CreateAnswer(); }; @@ -67,22 +69,23 @@ class ADD_TARIFF: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, TARIFFS & tariffs) - : m_admin(admin), m_tariffs(tariffs) - {} - virtual BASE_PARSER * create() { return new ADD_TARIFF(m_admin, m_tariffs); } + explicit FACTORY(Tariffs & tariffs) : m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const Admin & admin) { return new ADD_TARIFF(admin, m_tariffs); } + static void Register(REGISTRY & registry, Tariffs & tariffs) + { registry[ToLower(tag)] = new FACTORY(tariffs); } private: - const ADMIN & m_admin; - TARIFFS & m_tariffs; + Tariffs & m_tariffs; }; - ADD_TARIFF(const ADMIN & admin, TARIFFS & tariffs) - : BASE_PARSER(admin, "AddTariff"), m_tariffs(tariffs) {} + static const char * tag; + + ADD_TARIFF(const Admin & admin, Tariffs & tariffs) + : BASE_PARSER(admin, tag), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); private: std::string tariff; - TARIFFS & m_tariffs; + Tariffs & m_tariffs; void CreateAnswer(); }; @@ -93,24 +96,25 @@ class DEL_TARIFF: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, TARIFFS & tariffs, const USERS & users) - : m_admin(admin), m_tariffs(tariffs), m_users(users) - {} - virtual BASE_PARSER * create() { return new DEL_TARIFF(m_admin, m_users, m_tariffs); } + FACTORY(Tariffs & tariffs, const Users & users) : m_tariffs(tariffs), m_users(users) {} + virtual BASE_PARSER * create(const Admin & admin) { return new DEL_TARIFF(admin, m_users, m_tariffs); } + static void Register(REGISTRY & registry, Tariffs & tariffs, const Users & users) + { registry[ToLower(tag)] = new FACTORY(tariffs, users); } private: - const ADMIN & m_admin; - TARIFFS & m_tariffs; - const USERS & m_users; + Tariffs & m_tariffs; + const Users & m_users; }; - DEL_TARIFF(const ADMIN & admin, const USERS & users, TARIFFS & tariffs) - : BASE_PARSER(admin, "DelTariff"), m_users(users), m_tariffs(tariffs) {} + static const char * tag; + + DEL_TARIFF(const Admin & admin, const Users & users, Tariffs & tariffs) + : BASE_PARSER(admin, tag), m_users(users), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); private: std::string tariff; - const USERS & m_users; - TARIFFS & m_tariffs; + const Users & m_users; + Tariffs & m_tariffs; void CreateAnswer(); }; @@ -121,22 +125,23 @@ class CHG_TARIFF: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, TARIFFS & tariffs) - : m_admin(admin), m_tariffs(tariffs) - {} - virtual BASE_PARSER * create() { return new CHG_TARIFF(m_admin, m_tariffs); } + explicit FACTORY(Tariffs & tariffs) : m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const Admin & admin) { return new CHG_TARIFF(admin, m_tariffs); } + static void Register(REGISTRY & registry, Tariffs & tariffs) + { registry[ToLower(tag)] = new FACTORY(tariffs); } private: - const ADMIN & m_admin; - TARIFFS & m_tariffs; + Tariffs & m_tariffs; }; - CHG_TARIFF(const ADMIN & admin, TARIFFS & tariffs) - : BASE_PARSER(admin, "SetTariff"), m_tariffs(tariffs) {} + static const char * tag; + + CHG_TARIFF(const Admin & admin, Tariffs & tariffs) + : BASE_PARSER(admin, tag), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); private: - TARIFF_DATA_RES td; - TARIFFS & m_tariffs; + TariffDataOpt td; + Tariffs & m_tariffs; int CheckTariffData(); void CreateAnswer(); @@ -144,5 +149,3 @@ class CHG_TARIFF: public BASE_PARSER } // namespace PARSER } // namespace STG - -#endif