]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h
Various fixes of issues reported by static analyzers.
[stg.git] / projects / stargazer / plugins / configuration / sgconfig / parser_tariffs.h
index c96163fe62310d3b6bfb500731f92c8ea5d65494..418ae45c2ad50396753bce8812e111ca6f670e6f 100644 (file)
@@ -25,6 +25,7 @@
 #include "parser.h"
 
 #include "stg/tariff_conf.h"
+#include "stg/common.h"
 
 #include <string>
 
@@ -40,8 +41,21 @@ namespace PARSER
 class GET_TARIFFS: public BASE_PARSER
 {
     public:
+        class FACTORY : public BASE_PARSER::FACTORY
+        {
+            public:
+                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 TARIFFS & m_tariffs;
+        };
+
+        static const char * tag;
+
         GET_TARIFFS(const ADMIN & admin, const TARIFFS & tariffs)
-            : BASE_PARSER(admin, "GetTariffs"), m_tariffs(tariffs) {}
+            : BASE_PARSER(admin, tag), m_tariffs(tariffs) {}
 
     private:
         const TARIFFS & m_tariffs;
@@ -52,8 +66,21 @@ class GET_TARIFFS: public BASE_PARSER
 class ADD_TARIFF: public BASE_PARSER
 {
     public:
+        class FACTORY : public BASE_PARSER::FACTORY
+        {
+            public:
+                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:
+                TARIFFS & m_tariffs;
+        };
+
+        static const char * tag;
+
         ADD_TARIFF(const ADMIN & admin, TARIFFS & tariffs)
-            : BASE_PARSER(admin, "AddTariff"), m_tariffs(tariffs) {}
+            : BASE_PARSER(admin, tag), m_tariffs(tariffs) {}
         int Start(void * data, const char * el, const char ** attr);
 
     private:
@@ -66,8 +93,22 @@ class ADD_TARIFF: public BASE_PARSER
 class DEL_TARIFF: public BASE_PARSER
 {
     public:
+        class FACTORY : public BASE_PARSER::FACTORY
+        {
+            public:
+                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:
+                TARIFFS & m_tariffs;
+                const USERS & m_users;
+        };
+
+        static const char * tag;
+
         DEL_TARIFF(const ADMIN & admin, const USERS & users, TARIFFS & tariffs)
-            : BASE_PARSER(admin, "DelTariff"), m_users(users), m_tariffs(tariffs) {}
+            : BASE_PARSER(admin, tag), m_users(users), m_tariffs(tariffs) {}
         int Start(void * data, const char * el, const char ** attr);
 
     private:
@@ -81,10 +122,22 @@ class DEL_TARIFF: public BASE_PARSER
 class CHG_TARIFF: public BASE_PARSER
 {
     public:
+        class FACTORY : public BASE_PARSER::FACTORY
+        {
+            public:
+                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:
+                TARIFFS & m_tariffs;
+        };
+
+        static const char * tag;
+
         CHG_TARIFF(const ADMIN & admin, TARIFFS & tariffs)
-            : BASE_PARSER(admin, "SetTariff"), m_tariffs(tariffs) {}
+            : BASE_PARSER(admin, tag), m_tariffs(tariffs) {}
         int Start(void * data, const char * el, const char ** attr);
-        int End(void * data, const char * el);
 
     private:
         TARIFF_DATA_RES td;
@@ -94,7 +147,7 @@ class CHG_TARIFF: public BASE_PARSER
         void CreateAnswer();
 };
 
-}
-}
+} // namespace PARSER
+} // namespace STG
 
 #endif