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.
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.
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
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 #include "stg/optional.h"
36 explicit ServiceConf(const std::string & n)
37 : name(n), cost(0), payDay(0)
39 ServiceConf(const std::string & n, double c)
40 : name(n), cost(c), payDay(0)
42 ServiceConf(const std::string & n, double c, unsigned p)
43 : name(n), cost(c), payDay(static_cast<uint8_t>(p))
45 ServiceConf(const std::string & n, double c,
46 unsigned p, const std::string & com)
47 : name(n), comment(com), cost(c), payDay(static_cast<uint8_t>(p))
50 ServiceConf(const ServiceConf&) = default;
51 ServiceConf& operator=(const ServiceConf&) = default;
52 ServiceConf(ServiceConf&&) = default;
53 ServiceConf& operator=(ServiceConf&&) = default;
55 bool operator==(const ServiceConf& rhs) const noexcept { return name == rhs.name; }
65 ServiceConfOpt() = default;
67 explicit ServiceConfOpt(const ServiceConf& rhs)
68 : name(rhs.name), comment(rhs.comment),
69 cost(rhs.cost), payDay(rhs.payDay)
72 ServiceConfOpt(const ServiceConfOpt&) = default;
73 ServiceConfOpt& operator=(const ServiceConfOpt&) = default;
74 ServiceConfOpt(ServiceConfOpt&&) = default;
75 ServiceConfOpt& operator=(ServiceConfOpt&&) = default;
77 ServiceConfOpt& operator=(const ServiceConf& conf)
80 comment = conf.comment;
86 void splice(const ServiceConfOpt& rhs)
88 name.splice(rhs.name);
89 comment.splice(rhs.comment);
90 cost.splice(rhs.cost);
91 payDay.splice(rhs.payDay);
94 ServiceConf get(const ServiceConf& defaultValue) const noexcept
97 res.name = name.get(defaultValue.name);
98 res.comment = comment.get(defaultValue.comment);
99 res.cost = cost.get(defaultValue.cost);
100 res.payDay = payDay.get(defaultValue.payDay);
104 Optional<std::string> name;
105 Optional<std::string> comment;
106 Optional<double> cost;
107 Optional<uint8_t> payDay;