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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  Contact:  Joseph Zupko
21  *            jaz147@psu.edu
22  *
23  *            189 Reese St.
24  *            Old Forge, PA 18518
25  */
26 
27 #include <varconf/dyncmp.h>
28 
29 #include <string>
30 
31 namespace varconf {
32 namespace dynvar {
33 
~Compare()34 Compare::~Compare()
35 {
36 }
37 
operator =(const Compare & c)38 Compare& Compare::operator=(const Compare& c)
39 {
40   VarBase::operator=(c);
41   m_v1 = c.m_v1;
42   m_v2 = c.m_v2;
43   return *this;
44 }
45 
set_val()46 void Compare::set_val()
47 {
48   if(m_v1.is_bool() && m_v2.is_bool())
49     VarBase::operator=(bool_cmp(bool(m_v1), bool(m_v2)));
50   else if(m_v1.is_int() && m_v2.is_int())
51     VarBase::operator=(int_cmp(int(m_v1), int(m_v2)));
52   else if(m_v1.is_double() && m_v2.is_double())
53     VarBase::operator=(double_cmp(double(m_v1), double(m_v2)));
54   else if(m_v1.is_string() && m_v2.is_string()) {
55     std::string s1 = std::string(m_v1), s2 = std::string(m_v2);
56     VarBase::operator=(string_cmp(s1, s2));
57   }
58   else
59     VarBase::operator=(VarBase()); // Set it invalid
60 }
61 
~Equal()62 Equal::~Equal()
63 {
64 }
65 
bool_cmp(const bool b1,const bool b2)66 bool Equal::bool_cmp(const bool b1, const bool b2)
67 {
68   return b1 == b2;
69 }
70 
int_cmp(const int i1,const int i2)71 bool Equal::int_cmp(const int i1, const int i2)
72 {
73   return i1 == i2;
74 }
75 
double_cmp(const double d1,const double d2)76 bool Equal::double_cmp(const double d1, const double d2)
77 {
78   return d1 == d2;
79 }
80 
string_cmp(const std::string & s1,const std::string & s2)81 bool Equal::string_cmp(const std::string& s1, const std::string& s2)
82 {
83   return s1 == s2;
84 }
85 
~NotEq()86 NotEq::~NotEq()
87 {
88 }
89 
bool_cmp(const bool b1,const bool b2)90 bool NotEq::bool_cmp(const bool b1, const bool b2)
91 {
92   return b1 != b2;
93 }
94 
int_cmp(const int i1,const int i2)95 bool NotEq::int_cmp(const int i1, const int i2)
96 {
97   return i1 != i2;
98 }
99 
double_cmp(const double d1,const double d2)100 bool NotEq::double_cmp(const double d1, const double d2)
101 {
102   return d1 != d2;
103 }
104 
string_cmp(const std::string & s1,const std::string & s2)105 bool NotEq::string_cmp(const std::string& s1, const std::string& s2)
106 {
107   return s1 != s2;
108 }
109 
~Greater()110 Greater::~Greater()
111 {
112 }
113 
bool_cmp(const bool b1,const bool b2)114 bool Greater::bool_cmp(const bool b1, const bool b2)
115 {
116   return b1 > b2;
117 }
118 
int_cmp(const int i1,const int i2)119 bool Greater::int_cmp(const int i1, const int i2)
120 {
121   return i1 > i2;
122 }
123 
double_cmp(const double d1,const double d2)124 bool Greater::double_cmp(const double d1, const double d2)
125 {
126   return d1 > d2;
127 }
128 
string_cmp(const std::string & s1,const std::string & s2)129 bool Greater::string_cmp(const std::string& s1, const std::string& s2)
130 {
131   return s1 > s2;
132 }
133 
~GreaterEq()134 GreaterEq::~GreaterEq()
135 {
136 }
137 
bool_cmp(const bool b1,const bool b2)138 bool GreaterEq::bool_cmp(const bool b1, const bool b2)
139 {
140   return b1 >= b2;
141 }
142 
int_cmp(const int i1,const int i2)143 bool GreaterEq::int_cmp(const int i1, const int i2)
144 {
145   return i1 >= i2;
146 }
147 
double_cmp(const double d1,const double d2)148 bool GreaterEq::double_cmp(const double d1, const double d2)
149 {
150   return d1 >= d2;
151 }
152 
string_cmp(const std::string & s1,const std::string & s2)153 bool GreaterEq::string_cmp(const std::string& s1, const std::string& s2)
154 {
155   return s1 >= s2;
156 }
157 
~Less()158 Less::~Less()
159 {
160 }
161 
bool_cmp(const bool b1,const bool b2)162 bool Less::bool_cmp(const bool b1, const bool b2)
163 {
164   return b1 < b2;
165 }
166 
int_cmp(const int i1,const int i2)167 bool Less::int_cmp(const int i1, const int i2)
168 {
169   return i1 < i2;
170 }
171 
double_cmp(const double d1,const double d2)172 bool Less::double_cmp(const double d1, const double d2)
173 {
174   return d1 < d2;
175 }
176 
string_cmp(const std::string & s1,const std::string & s2)177 bool Less::string_cmp(const std::string& s1, const std::string& s2)
178 {
179   return s1 < s2;
180 }
181 
~LessEq()182 LessEq::~LessEq()
183 {
184 }
185 
bool_cmp(const bool b1,const bool b2)186 bool LessEq::bool_cmp(const bool b1, const bool b2)
187 {
188   return b1 <= b2;
189 }
190 
int_cmp(const int i1,const int i2)191 bool LessEq::int_cmp(const int i1, const int i2)
192 {
193   return i1 <= i2;
194 }
195 
double_cmp(const double d1,const double d2)196 bool LessEq::double_cmp(const double d1, const double d2)
197 {
198   return d1 <= d2;
199 }
200 
string_cmp(const std::string & s1,const std::string & s2)201 bool LessEq::string_cmp(const std::string& s1, const std::string& s2)
202 {
203   return s1 <= s2;
204 }
205 
206 }} // namespace varconf::dynvar
207