]> git.stg.codes - stg.git/blob - stargazer/plugins/configuration/sgconfig/parser_tariffs.h
Port to CMake, get rid of os_int.h.
[stg.git] / stargazer / plugins / configuration / sgconfig / parser_tariffs.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #ifndef __STG_SGCONFIG_PARSER_TARIFFS_H__
23 #define __STG_SGCONFIG_PARSER_TARIFFS_H__
24
25 #include "parser.h"
26
27 #include "stg/tariff_conf.h"
28 #include "stg/common.h"
29
30 #include <string>
31
32 class TARIFFS;
33 class USERS;
34 class ADMIN;
35
36 namespace STG
37 {
38 namespace PARSER
39 {
40
41 class GET_TARIFFS: public BASE_PARSER
42 {
43     public:
44         class FACTORY : public BASE_PARSER::FACTORY
45         {
46             public:
47                 explicit FACTORY(const TARIFFS & tariffs) : m_tariffs(tariffs) {}
48                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_TARIFFS(admin, m_tariffs); }
49                 static void Register(REGISTRY & registry, const TARIFFS & tariffs)
50                 { registry[ToLower(tag)] = new FACTORY(tariffs); }
51             private:
52                 const TARIFFS & m_tariffs;
53         };
54
55         static const char * tag;
56
57         GET_TARIFFS(const ADMIN & admin, const TARIFFS & tariffs)
58             : BASE_PARSER(admin, tag), m_tariffs(tariffs) {}
59
60     private:
61         const TARIFFS & m_tariffs;
62
63         void CreateAnswer();
64 };
65
66 class ADD_TARIFF: public BASE_PARSER
67 {
68     public:
69         class FACTORY : public BASE_PARSER::FACTORY
70         {
71             public:
72                 explicit FACTORY(TARIFFS & tariffs) : m_tariffs(tariffs) {}
73                 virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_TARIFF(admin, m_tariffs); }
74                 static void Register(REGISTRY & registry, TARIFFS & tariffs)
75                 { registry[ToLower(tag)] = new FACTORY(tariffs); }
76             private:
77                 TARIFFS & m_tariffs;
78         };
79
80         static const char * tag;
81
82         ADD_TARIFF(const ADMIN & admin, TARIFFS & tariffs)
83             : BASE_PARSER(admin, tag), m_tariffs(tariffs) {}
84         int Start(void * data, const char * el, const char ** attr);
85
86     private:
87         std::string tariff;
88         TARIFFS & m_tariffs;
89
90         void CreateAnswer();
91 };
92
93 class DEL_TARIFF: public BASE_PARSER
94 {
95     public:
96         class FACTORY : public BASE_PARSER::FACTORY
97         {
98             public:
99                 FACTORY(TARIFFS & tariffs, const USERS & users) : m_tariffs(tariffs), m_users(users) {}
100                 virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_TARIFF(admin, m_users, m_tariffs); }
101                 static void Register(REGISTRY & registry, TARIFFS & tariffs, const USERS & users)
102                 { registry[ToLower(tag)] = new FACTORY(tariffs, users); }
103             private:
104                 TARIFFS & m_tariffs;
105                 const USERS & m_users;
106         };
107
108         static const char * tag;
109
110         DEL_TARIFF(const ADMIN & admin, const USERS & users, TARIFFS & tariffs)
111             : BASE_PARSER(admin, tag), m_users(users), m_tariffs(tariffs) {}
112         int Start(void * data, const char * el, const char ** attr);
113
114     private:
115         std::string tariff;
116         const USERS & m_users;
117         TARIFFS & m_tariffs;
118
119         void CreateAnswer();
120 };
121
122 class CHG_TARIFF: public BASE_PARSER
123 {
124     public:
125         class FACTORY : public BASE_PARSER::FACTORY
126         {
127             public:
128                 explicit FACTORY(TARIFFS & tariffs) : m_tariffs(tariffs) {}
129                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_TARIFF(admin, m_tariffs); }
130                 static void Register(REGISTRY & registry, TARIFFS & tariffs)
131                 { registry[ToLower(tag)] = new FACTORY(tariffs); }
132             private:
133                 TARIFFS & m_tariffs;
134         };
135
136         static const char * tag;
137
138         CHG_TARIFF(const ADMIN & admin, TARIFFS & tariffs)
139             : BASE_PARSER(admin, tag), m_tariffs(tariffs) {}
140         int Start(void * data, const char * el, const char ** attr);
141
142     private:
143         TARIFF_DATA_RES td;
144         TARIFFS & m_tariffs;
145
146         int CheckTariffData();
147         void CreateAnswer();
148 };
149
150 } // namespace PARSER
151 } // namespace STG
152
153 #endif