varconf 1.0.3
Configuration library for the Worldforge system.
dyncmp.cpp
1/*
2 * variable.cpp - implementation of the dynamically derived value container compare.
3 * Copyright (C) 2001, Ron Steinke
4 * (C) 2003-2006 Alistair Riddoch
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Contact: Joseph Zupko
21 * jaz147@psu.edu
22 *
23 * 189 Reese St.
24 * Old Forge, PA 18518
25 */
26
27#include "dyncmp.h"
28
29#include <string>
30
31namespace varconf {
32namespace dynvar {
33
34Compare::~Compare() = default;
35
36Compare& Compare::operator=(const Compare& c)
37{
38 VarBase::operator=(c);
39 m_v1 = c.m_v1;
40 m_v2 = c.m_v2;
41 return *this;
42}
43
44void Compare::set_val()
45{
46 if(m_v1.is_bool() && m_v2.is_bool())
47 VarBase::operator=(bool_cmp(bool(m_v1), bool(m_v2)));
48 else if(m_v1.is_int() && m_v2.is_int())
49 VarBase::operator=(int_cmp(int(m_v1), int(m_v2)));
50 else if(m_v1.is_double() && m_v2.is_double())
51 VarBase::operator=(double_cmp(double(m_v1), double(m_v2)));
52 else if(m_v1.is_string() && m_v2.is_string()) {
53 std::string s1 = std::string(m_v1), s2 = std::string(m_v2);
54 VarBase::operator=(string_cmp(s1, s2));
55 }
56 else
57 VarBase::operator=(VarBase()); // Set it invalid
58}
59
60Equal::~Equal() = default;
61
62bool Equal::bool_cmp(bool b1, bool b2)
63{
64 return b1 == b2;
65}
66
67bool Equal::int_cmp(int i1, int i2)
68{
69 return i1 == i2;
70}
71
72bool Equal::double_cmp(double d1, double d2)
73{
74 return d1 == d2;
75}
76
77bool Equal::string_cmp(const std::string& s1, const std::string& s2)
78{
79 return s1 == s2;
80}
81
82NotEq::~NotEq() = default;
83
84bool NotEq::bool_cmp(bool b1, bool b2)
85{
86 return b1 != b2;
87}
88
89bool NotEq::int_cmp(int i1, int i2)
90{
91 return i1 != i2;
92}
93
94bool NotEq::double_cmp(double d1, double d2)
95{
96 return d1 != d2;
97}
98
99bool NotEq::string_cmp(const std::string& s1, const std::string& s2)
100{
101 return s1 != s2;
102}
103
104Greater::~Greater() = default;
105
106bool Greater::bool_cmp(bool b1, bool b2)
107{
108 return b1 > b2;
109}
110
111bool Greater::int_cmp(int i1, int i2)
112{
113 return i1 > i2;
114}
115
116bool Greater::double_cmp(double d1, double d2)
117{
118 return d1 > d2;
119}
120
121bool Greater::string_cmp(const std::string& s1, const std::string& s2)
122{
123 return s1 > s2;
124}
125
126GreaterEq::~GreaterEq() = default;
127
128bool GreaterEq::bool_cmp(bool b1, bool b2)
129{
130 return b1 >= b2;
131}
132
133bool GreaterEq::int_cmp(int i1, int i2)
134{
135 return i1 >= i2;
136}
137
138bool GreaterEq::double_cmp(double d1, double d2)
139{
140 return d1 >= d2;
141}
142
143bool GreaterEq::string_cmp(const std::string& s1, const std::string& s2)
144{
145 return s1 >= s2;
146}
147
148Less::~Less() = default;
149
150bool Less::bool_cmp(bool b1, bool b2)
151{
152 return b1 < b2;
153}
154
155bool Less::int_cmp(int i1, int i2)
156{
157 return i1 < i2;
158}
159
160bool Less::double_cmp(double d1, double d2)
161{
162 return d1 < d2;
163}
164
165bool Less::string_cmp(const std::string& s1, const std::string& s2)
166{
167 return s1 < s2;
168}
169
170LessEq::~LessEq() = default;
171
172bool LessEq::bool_cmp(bool b1, bool b2)
173{
174 return b1 <= b2;
175}
176
177bool LessEq::int_cmp(int i1, int i2)
178{
179 return i1 <= i2;
180}
181
182bool LessEq::double_cmp(double d1, double d2)
183{
184 return d1 <= d2;
185}
186
187bool LessEq::string_cmp(const std::string& s1, const std::string& s2)
188{
189 return s1 <= s2;
190}
191
192}} // namespace varconf::dynvar