X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/0c9d10cb3d9399280fe5eca715287d2454788654..0907aa4037b12b6b88ee24495d4577a064d4f8db:/projects/stargazer/plugins/configuration/sgconfig/parser_users.h diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h index da4583b1..cdef451e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h @@ -19,37 +19,53 @@ * Author : Maxim Mamontov */ -#ifndef __STG_SGCONFIG_PARSER_USERS_H__ -#define __STG_SGCONFIG_PARSER_USERS_H__ +#pragma once #include "parser.h" -#include "stg/resetable.h" +#include "stg/user_conf.h" +#include "stg/user_stat.h" +#include "stg/common.h" +#include "stg/optional.h" #include -class USERS; -class USER; -class TARIFFS; -class ADMIN; - namespace STG { + +struct Users; +struct User; +struct Tariffs; +struct Admin; +struct Store; + namespace PARSER { class GET_USERS: public BASE_PARSER { public: - GET_USERS(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "GetUsers"), m_users(users), - lastUserUpdateTime(0), lastUpdateFound(false) {} + class FACTORY : public BASE_PARSER::FACTORY + { + public: + explicit FACTORY(Users & users) : m_users(users) {} + virtual BASE_PARSER * create(const Admin & admin) { return new GET_USERS(admin, m_users); } + static void Register(REGISTRY & registry, Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } + private: + Users & m_users; + }; + + static const char * tag; + + GET_USERS(const Admin & admin, Users & users) + : BASE_PARSER(admin, tag), m_users(users), + m_lastUserUpdateTime(0) {} int Start(void * data, const char * el, const char ** attr); private: - USERS & m_users; - time_t lastUserUpdateTime; - bool lastUpdateFound; + Users & m_users; + time_t m_lastUserUpdateTime; void CreateAnswer(); }; @@ -57,13 +73,26 @@ class GET_USERS: public BASE_PARSER class GET_USER: public BASE_PARSER { public: - GET_USER(const ADMIN & admin, const USERS & users) - : BASE_PARSER(admin, "GetUser"), m_users(users) {} + class FACTORY : public BASE_PARSER::FACTORY + { + public: + explicit FACTORY(const Users & users) : m_users(users) {} + virtual BASE_PARSER * create(const Admin & admin) { return new GET_USER(admin, m_users); } + static void Register(REGISTRY & registry, const Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } + private: + const Users & m_users; + }; + + static const char * tag; + + GET_USER(const Admin & admin, const Users & users) + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); private: - const USERS & m_users; - std::string login; + const Users & m_users; + std::string m_login; void CreateAnswer(); }; @@ -71,38 +100,71 @@ class GET_USER: public BASE_PARSER class ADD_USER: public BASE_PARSER { public: - ADD_USER(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "AddUser"), m_users(users) {} + class FACTORY : public BASE_PARSER::FACTORY + { + public: + explicit FACTORY(Users & users) : m_users(users) {} + virtual BASE_PARSER * create(const Admin & admin) { return new ADD_USER(admin, m_users); } + static void Register(REGISTRY & registry, Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } + private: + Users & m_users; + }; + + static const char * tag; + + ADD_USER(const Admin & admin, Users & users) + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); - int End(void * data, const char * el); private: - USERS & m_users; - std::string login; + Users & m_users; + std::string m_login; - int CheckUserData(); void CreateAnswer(); }; class CHG_USER: public BASE_PARSER { public: - CHG_USER(const ADMIN & admin, USERS & users, const TARIFFS & tariffs); - ~CHG_USER(); + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(Users & users, Store & store, const Tariffs & tariffs) + : m_users(users), m_store(store), m_tariffs(tariffs) + {} + virtual BASE_PARSER * create(const Admin & admin) { return new CHG_USER(admin, m_users, m_store, m_tariffs); } + static void Register(REGISTRY & registry, Users & users, Store & store, const Tariffs & tariffs) + { registry[ToLower(tag)] = new FACTORY(users, store, tariffs); } + private: + Users & m_users; + Store & m_store; + const Tariffs & m_tariffs; + }; + + static const char * tag; + + CHG_USER(const Admin & admin, Users & users, + Store & store, const Tariffs & tariffs) + : BASE_PARSER(admin, tag), + m_users(users), + m_store(store), + m_tariffs(tariffs), + m_cashMustBeAdded(false) {} + int Start(void * data, const char * el, const char ** attr); - int End(void * data, const char * el); private: - USERS & m_users; - const TARIFFS & m_tariffs; - USER_STAT_RES * usr; - USER_CONF_RES * ucr; - RESETABLE * upr; - RESETABLE * downr; - std::string cashMsg; - std::string login; - bool cashMustBeAdded; - int res; + Users & m_users; + Store & m_store; + const Tariffs & m_tariffs; + UserStatOpt m_usr; + UserConfOpt m_ucr; + Optional m_upr[DIR_NUM]; + Optional m_downr[DIR_NUM]; + std::string m_cashMsg; + std::string m_login; + bool m_cashMustBeAdded; int ApplyChanges(); void CreateAnswer(); @@ -111,15 +173,28 @@ class CHG_USER: public BASE_PARSER class DEL_USER: public BASE_PARSER { public: - DEL_USER(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "DelUser"), m_users(users), res(0), u(NULL) {} + class FACTORY : public BASE_PARSER::FACTORY + { + public: + explicit FACTORY(Users & users) : m_users(users) {} + virtual BASE_PARSER * create(const Admin & admin) { return new DEL_USER(admin, m_users); } + static void Register(REGISTRY & registry, Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } + private: + Users & m_users; + }; + + static const char * tag; + + DEL_USER(const Admin & admin, Users & users) + : BASE_PARSER(admin, tag), m_users(users), res(0), u(NULL) {} int Start(void * data, const char * el, const char ** attr); int End(void * data, const char * el); private: - USERS & m_users; + Users & m_users; int res; - USER * u; + User * u; void CreateAnswer(); }; @@ -127,18 +202,30 @@ class DEL_USER: public BASE_PARSER class CHECK_USER: public BASE_PARSER { public: - CHECK_USER(const ADMIN & admin, const USERS & users) - : BASE_PARSER(admin, "CheckUser"), m_users(users) {} + class FACTORY : public BASE_PARSER::FACTORY + { + public: + explicit FACTORY(const Users & users) : m_users(users) {} + virtual BASE_PARSER * create(const Admin & admin) { return new CHECK_USER(admin, m_users); } + static void Register(REGISTRY & registry, const Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } + private: + const Users & m_users; + }; + + static const char * tag; + + CHECK_USER(const Admin & admin, const Users & users) + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); int End(void * data, const char * el); private: - const USERS & m_users; + const Users & m_users; void CreateAnswer(const char * error); + void CreateAnswer() {} // dummy }; -} -} - -#endif +} // namespace PARSER +} // namespace STG