]> git.stg.codes - stg.git/blob - include/stg/service_conf.h
Port to CMake, get rid of os_int.h.
[stg.git] / include / stg / service_conf.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 : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 #ifndef SERVICE_CONF_H
22 #define SERVICE_CONF_H
23
24 #include "resetable.h"
25
26 #include <string>
27 #include <cstdint>
28
29 struct SERVICE_CONF
30 {
31 SERVICE_CONF()
32     : name(), comment(), cost(0), payDay(0)
33 {}
34 explicit SERVICE_CONF(const std::string & n)
35     : name(n), comment(), cost(0), payDay(0)
36 {}
37 SERVICE_CONF(const std::string & n, double c)
38     : name(n), comment(), cost(c), payDay(0)
39 {}
40 SERVICE_CONF(const std::string & n, double c, unsigned p)
41     : name(n), comment(), cost(c), payDay(static_cast<uint8_t>(p))
42 {}
43 SERVICE_CONF(const std::string & n, double c,
44              unsigned p, const std::string & com)
45     : name(n), comment(com), cost(c), payDay(static_cast<uint8_t>(p))
46 {}
47
48 std::string name;
49 std::string comment;
50 double      cost;
51 uint8_t     payDay;
52 };
53
54 struct SERVICE_CONF_RES
55 {
56 SERVICE_CONF_RES()
57     : name(), comment(),
58       cost(), payDay()
59 {}
60
61 explicit SERVICE_CONF_RES(const SERVICE_CONF & rhs)
62     : name(rhs.name), comment(rhs.comment),
63       cost(rhs.cost), payDay(rhs.payDay)
64 {}
65
66 SERVICE_CONF_RES & operator=(const SERVICE_CONF & conf)
67 {
68 name = conf.name;
69 comment = conf.comment;
70 cost = conf.cost;
71 payDay = conf.payDay;
72 return *this;
73 }
74
75 SERVICE_CONF GetData() const
76 {
77 SERVICE_CONF sc;
78 sc.name = name.data();
79 sc.comment = comment.data();
80 sc.cost = cost.data();
81 sc.payDay = payDay.data();
82 return sc;
83 }
84
85 void Splice(const SERVICE_CONF_RES & rhs)
86 {
87 name.splice(rhs.name);
88 comment.splice(rhs.comment);
89 cost.splice(rhs.cost);
90 payDay.splice(rhs.payDay);
91 }
92
93 RESETABLE<std::string> name;
94 RESETABLE<std::string> comment;
95 RESETABLE<double>      cost;
96 RESETABLE<uint8_t>     payDay;
97 };
98
99 inline
100 bool operator==(const SERVICE_CONF & a, const SERVICE_CONF & b)
101 {
102 return a.name == b.name;
103 }
104
105 #endif //SERVICE_CONF_H
106