From 6171920df2f880303b54c19d7c5169c64b485585 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 22 Sep 2014 12:29:06 +0300 Subject: [PATCH] Added parser factories. Conflicts: projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h --- .../plugins/configuration/sgconfig/parser.h | 5 ++ .../configuration/sgconfig/parser_admins.cpp | 8 +- .../configuration/sgconfig/parser_admins.h | 56 ++++++++++++- .../configuration/sgconfig/parser_auth_by.h | 16 +++- .../configuration/sgconfig/parser_message.h | 16 +++- .../configuration/sgconfig/parser_tariffs.h | 53 ++++++++++++- .../configuration/sgconfig/parser_users.h | 79 ++++++++++++++++++- 7 files changed, 217 insertions(+), 16 deletions(-) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.h b/projects/stargazer/plugins/configuration/sgconfig/parser.h index 035dae8f..0cda75b6 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.h @@ -28,6 +28,11 @@ class ADMIN; class BASE_PARSER { public: + struct FACTORY + { + virtual BASE_PARSER * create() = 0; + }; + BASE_PARSER(const ADMIN & admin, const std::string & t) : m_currAdmin(admin), m_depth(0), diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp index 01ae9e81..60ceaaa8 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp @@ -65,7 +65,7 @@ int DEL_ADMIN::Start(void *, const char * el, const char ** attr) { if (strcasecmp(el, m_tag.c_str()) == 0) { - admin = attr[1]; + m_admin = attr[1]; return 0; } return -1; @@ -73,7 +73,7 @@ int DEL_ADMIN::Start(void *, const char * el, const char ** attr) void DEL_ADMIN::CreateAnswer() { - if (m_admins.Del(admin, &m_currAdmin) == 0) + if (m_admins.Del(m_admin, &m_currAdmin) == 0) m_answer = "<" + m_tag + " Result=\"Ok\"/>"; else m_answer = "<" + m_tag + " Result=\"Error. " + m_admins.GetStrError() + "\"/>"; @@ -83,7 +83,7 @@ int ADD_ADMIN::Start(void *, const char *el, const char **attr) { if (strcasecmp(el, m_tag.c_str()) == 0) { - admin = attr[1]; + m_admin = attr[1]; return 0; } return -1; @@ -91,7 +91,7 @@ int ADD_ADMIN::Start(void *, const char *el, const char **attr) void ADD_ADMIN::CreateAnswer() { - if (m_admins.Add(admin, &m_currAdmin) == 0) + if (m_admins.Add(m_admin, &m_currAdmin) == 0) m_answer = "<" + m_tag + " Result=\"Ok\"/>"; else m_answer = "<" + m_tag + " Result=\"Error. " + m_admins.GetStrError() + "\"/>"; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h index 63ee6278..7cce32ad 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h @@ -39,6 +39,18 @@ namespace PARSER class GET_ADMINS: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, const ADMINS & admins) + : m_admin(admin), m_admins(admins) + {} + virtual BASE_PARSER * create() { return new GET_ADMINS(m_admin, m_admins); } + private: + const ADMIN & m_admin; + const ADMINS & m_admins; + }; + GET_ADMINS(const ADMIN & admin, const ADMINS & admins) : BASE_PARSER(admin, "GetAdmins"), m_admins(admins) {} @@ -51,12 +63,24 @@ class GET_ADMINS: public BASE_PARSER class ADD_ADMIN: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, ADMINS & admins) + : m_admin(admin), m_admins(admins) + {} + virtual BASE_PARSER * create() { return new ADD_ADMIN(m_admin, m_admins); } + private: + const ADMIN & m_admin; + ADMINS & m_admins; + }; + ADD_ADMIN(const ADMIN & admin, ADMINS & admins) : BASE_PARSER(admin, "AddAdmin"), m_admins(admins) {} int Start(void * data, const char * el, const char ** attr); private: - std::string admin; + std::string m_admin; ADMINS & m_admins; void CreateAnswer(); @@ -65,12 +89,24 @@ class ADD_ADMIN: public BASE_PARSER class DEL_ADMIN: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, ADMINS & admins) + : m_admin(admin), m_admins(admins) + {} + virtual BASE_PARSER * create() { return new DEL_ADMIN(m_admin, m_admins); } + private: + const ADMIN & m_admin; + ADMINS & m_admins; + }; + DEL_ADMIN(const ADMIN & admin, ADMINS & admins) : BASE_PARSER(admin, "DelAdmin"), m_admins(admins) {} int Start(void * data, const char * el, const char ** attr); private: - std::string admin; + std::string m_admin; ADMINS & m_admins; void CreateAnswer(); @@ -79,6 +115,18 @@ class DEL_ADMIN: public BASE_PARSER class CHG_ADMIN: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, ADMINS & admins) + : m_admin(admin), m_admins(admins) + {} + virtual BASE_PARSER * create() { return new CHG_ADMIN(m_admin, m_admins); } + private: + const ADMIN & m_admin; + ADMINS & m_admins; + }; + CHG_ADMIN(const ADMIN & admin, ADMINS & admins) : BASE_PARSER(admin, "ChgAdmin"), m_admins(admins) {} int Start(void * data, const char * el, const char ** attr); @@ -92,7 +140,7 @@ class CHG_ADMIN: public BASE_PARSER void CreateAnswer(); }; -} -} +} // namespace PARSER +} // namespace STG #endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h index c103147e..61d25e4d 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h @@ -36,6 +36,18 @@ namespace PARSER class AUTH_BY : public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, const USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new AUTH_BY(m_admin, m_users); } + private: + const ADMIN & m_admin; + const USERS & m_users; + }; + AUTH_BY(const ADMIN & admin, const USERS & users) : BASE_PARSER(admin, "GetUserAuthBy"), m_users(users) {} int Start(void * data, const char * el, const char ** attr); @@ -47,7 +59,7 @@ class AUTH_BY : public BASE_PARSER void CreateAnswer(); }; -} -} +} // namespace PARSER +} // namespace STG #endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_message.h b/projects/stargazer/plugins/configuration/sgconfig/parser_message.h index e7c12f4f..2df1edc8 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_message.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_message.h @@ -40,6 +40,18 @@ namespace PARSER class SEND_MESSAGE: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new SEND_MESSAGE(m_admin, m_users); } + private: + const ADMIN & m_admin; + USERS & m_users; + }; + SEND_MESSAGE(const ADMIN & admin, USERS & users) : BASE_PARSER(admin, "Message"), m_users(users), m_result(res_ok), m_user(NULL) {} int Start(void *data, const char *el, const char **attr); @@ -56,7 +68,7 @@ class SEND_MESSAGE: public BASE_PARSER void CreateAnswer(); }; -} -} +} // namespace PARSER +} // namespace STG #endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h index 4e0f4b0b..f31257df 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h @@ -40,6 +40,18 @@ namespace PARSER class GET_TARIFFS: public BASE_PARSER { public: + 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); } + private: + const ADMIN & m_admin; + const TARIFFS & m_tariffs; + }; + GET_TARIFFS(const ADMIN & admin, const TARIFFS & tariffs) : BASE_PARSER(admin, "GetTariffs"), m_tariffs(tariffs) {} @@ -52,6 +64,18 @@ class GET_TARIFFS: public BASE_PARSER class ADD_TARIFF: public BASE_PARSER { public: + 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); } + private: + const ADMIN & m_admin; + TARIFFS & m_tariffs; + }; + ADD_TARIFF(const ADMIN & admin, TARIFFS & tariffs) : BASE_PARSER(admin, "AddTariff"), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); @@ -66,6 +90,19 @@ class ADD_TARIFF: public BASE_PARSER class DEL_TARIFF: public BASE_PARSER { public: + 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); } + private: + const ADMIN & m_admin; + 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) {} int Start(void * data, const char * el, const char ** attr); @@ -81,6 +118,18 @@ class DEL_TARIFF: public BASE_PARSER class CHG_TARIFF: public BASE_PARSER { public: + 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); } + private: + const ADMIN & m_admin; + TARIFFS & m_tariffs; + }; + CHG_TARIFF(const ADMIN & admin, TARIFFS & tariffs) : BASE_PARSER(admin, "SetTariff"), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); @@ -93,7 +142,7 @@ class CHG_TARIFF: public BASE_PARSER void CreateAnswer(); }; -} -} +} // namespace PARSER +} // namespace STG #endif diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h index bd758f5a..f5db4e7b 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h @@ -44,6 +44,18 @@ namespace PARSER class GET_USERS: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new GET_USERS(m_admin, m_users); } + private: + const ADMIN & m_admin; + USERS & m_users; + }; + GET_USERS(const ADMIN & admin, USERS & users) : BASE_PARSER(admin, "GetUsers"), m_users(users), m_lastUserUpdateTime(0) {} @@ -59,6 +71,18 @@ class GET_USERS: public BASE_PARSER class GET_USER: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, const USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new GET_USER(m_admin, m_users); } + private: + const ADMIN & m_admin; + const USERS & m_users; + }; + GET_USER(const ADMIN & admin, const USERS & users) : BASE_PARSER(admin, "GetUser"), m_users(users) {} int Start(void * data, const char * el, const char ** attr); @@ -73,6 +97,18 @@ class GET_USER: public BASE_PARSER class ADD_USER: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new ADD_USER(m_admin, m_users); } + private: + const ADMIN & m_admin; + USERS & m_users; + }; + ADD_USER(const ADMIN & admin, USERS & users) : BASE_PARSER(admin, "AddUser"), m_users(users) {} int Start(void * data, const char * el, const char ** attr); @@ -87,6 +123,20 @@ class ADD_USER: public BASE_PARSER class CHG_USER: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, USERS & users, STORE & store, const TARIFFS & tariffs) + : m_admin(admin), m_users(users), m_store(store), m_tariffs(tariffs) + {} + virtual BASE_PARSER * create() { return new CHG_USER(m_admin, m_users, m_store, m_tariffs); } + private: + const ADMIN & m_admin; + USERS & m_users; + STORE & m_store; + const TARIFFS & m_tariffs; + }; + CHG_USER(const ADMIN & admin, USERS & users, STORE & store, const TARIFFS & tariffs) : BASE_PARSER(admin, "SetUser"), @@ -118,6 +168,18 @@ class CHG_USER: public BASE_PARSER class DEL_USER: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new DEL_USER(m_admin, m_users); } + private: + const ADMIN & m_admin; + USERS & m_users; + }; + DEL_USER(const ADMIN & admin, USERS & users) : BASE_PARSER(admin, "DelUser"), m_users(users), res(0), u(NULL) {} int Start(void * data, const char * el, const char ** attr); @@ -134,6 +196,18 @@ class DEL_USER: public BASE_PARSER class CHECK_USER: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const ADMIN & admin, const USERS & users) + : m_admin(admin), m_users(users) + {} + virtual BASE_PARSER * create() { return new CHECK_USER(m_admin, m_users); } + private: + const ADMIN & m_admin; + const USERS & m_users; + }; + CHECK_USER(const ADMIN & admin, const USERS & users) : BASE_PARSER(admin, "CheckUser"), m_users(users) {} int Start(void * data, const char * el, const char ** attr); @@ -143,9 +217,10 @@ class CHECK_USER: public BASE_PARSER const USERS & m_users; void CreateAnswer(const char * error); + void CreateAnswer() {} // dummy }; -} -} +} // namespace PARSER +} // namespace STG #endif -- 2.44.2