X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/6171920df2f880303b54c19d7c5169c64b485585..1cb912e4f90473f78d2f0f10ab5c9b2c5bd36440:/projects/stargazer/plugins/configuration/sgconfig/parser_users.h?ds=inline diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h index f5db4e7b..d1e36e8f 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h @@ -19,25 +19,26 @@ * Author : Maxim Mamontov */ -#ifndef __STG_SGCONFIG_PARSER_USERS_H__ -#define __STG_SGCONFIG_PARSER_USERS_H__ +#pragma once #include "parser.h" #include "stg/user_conf.h" #include "stg/user_stat.h" -#include "stg/resetable.h" +#include "stg/common.h" #include - -class USERS; -class USER; -class TARIFFS; -class ADMIN; -class STORE; +#include namespace STG { + +class Users; +class User; +class Tariffs; +class Admin; +struct Store; + namespace PARSER { @@ -47,25 +48,26 @@ class GET_USERS: public BASE_PARSER 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); } + explicit FACTORY(Users & users) : m_users(users) {} + BASE_PARSER * create(const Admin & admin) override { return new GET_USERS(admin, m_users); } + static void Register(REGISTRY & registry, Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } private: - const ADMIN & m_admin; - USERS & m_users; + Users & m_users; }; - GET_USERS(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "GetUsers"), m_users(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); + int Start(void * data, const char * el, const char ** attr) override; private: - USERS & m_users; + Users & m_users; time_t m_lastUserUpdateTime; - void CreateAnswer(); + void CreateAnswer() override; }; class GET_USER: public BASE_PARSER @@ -74,24 +76,25 @@ class GET_USER: public BASE_PARSER 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); } + explicit FACTORY(const Users & users) : m_users(users) {} + BASE_PARSER * create(const Admin & admin) override { return new GET_USER(admin, m_users); } + static void Register(REGISTRY & registry, const Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } private: - const ADMIN & m_admin; - const USERS & m_users; + 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); + 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) override; private: - const USERS & m_users; + const Users & m_users; std::string m_login; - void CreateAnswer(); + void CreateAnswer() override; }; class ADD_USER: public BASE_PARSER @@ -100,24 +103,25 @@ class ADD_USER: public BASE_PARSER 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); } + explicit FACTORY(Users & users) : m_users(users) {} + BASE_PARSER * create(const Admin & admin) override { return new ADD_USER(admin, m_users); } + static void Register(REGISTRY & registry, Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } private: - const ADMIN & m_admin; - USERS & m_users; + 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); + 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) override; private: - USERS & m_users; + Users & m_users; std::string m_login; - void CreateAnswer(); + void CreateAnswer() override; }; class CHG_USER: public BASE_PARSER @@ -126,43 +130,44 @@ class CHG_USER: public BASE_PARSER 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) + FACTORY(Users & users, Store & store, const Tariffs & tariffs) + : 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); } + BASE_PARSER * create(const Admin & admin) override { 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: - const ADMIN & m_admin; - USERS & m_users; - STORE & m_store; - const TARIFFS & m_tariffs; + 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"), + 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), - m_res(0) {} + m_cashMustBeAdded(false) {} - int Start(void * data, const char * el, const char ** attr); + int Start(void * data, const char * el, const char ** attr) override; private: - USERS & m_users; - STORE & m_store; - const TARIFFS & m_tariffs; - USER_STAT_RES m_usr; - USER_CONF_RES m_ucr; - RESETABLE m_upr[DIR_NUM]; - RESETABLE m_downr[DIR_NUM]; + Users & m_users; + Store & m_store; + const Tariffs & m_tariffs; + UserStatOpt m_usr; + UserConfOpt m_ucr; + std::optional m_upr[DIR_NUM]; + std::optional m_downr[DIR_NUM]; std::string m_cashMsg; std::string m_login; bool m_cashMustBeAdded; - int m_res; int ApplyChanges(); - void CreateAnswer(); + void CreateAnswer() override; }; class DEL_USER: public BASE_PARSER @@ -171,26 +176,27 @@ class DEL_USER: public BASE_PARSER 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); } + explicit FACTORY(Users & users) : m_users(users) {} + BASE_PARSER * create(const Admin & admin) override { return new DEL_USER(admin, m_users); } + static void Register(REGISTRY & registry, Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } private: - const ADMIN & m_admin; - USERS & m_users; + 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); - int End(void * data, const char * el); + 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) override; + int End(void * data, const char * el) override; private: - USERS & m_users; + Users & m_users; int res; - USER * u; + User * u; - void CreateAnswer(); + void CreateAnswer() override; }; class CHECK_USER: public BASE_PARSER @@ -199,28 +205,27 @@ class CHECK_USER: public BASE_PARSER 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); } + explicit FACTORY(const Users & users) : m_users(users) {} + BASE_PARSER * create(const Admin & admin) override { return new CHECK_USER(admin, m_users); } + static void Register(REGISTRY & registry, const Users & users) + { registry[ToLower(tag)] = new FACTORY(users); } private: - const ADMIN & m_admin; - const USERS & m_users; + 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); - int End(void * data, const char * el); + 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) override; + int End(void * data, const char * el) override; private: - const USERS & m_users; + const Users & m_users; void CreateAnswer(const char * error); - void CreateAnswer() {} // dummy + void CreateAnswer() override {} // dummy }; } // namespace PARSER } // namespace STG - -#endif