torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Value.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef HAVE_CONFIG_H
17 #include "torc/generic/config.h"
18 #endif
19 
20 #ifdef GENOM_SERIALIZATION
21 #include <boost/archive/binary_iarchive.hpp>
22 #include <boost/archive/binary_oarchive.hpp>
23 #include <boost/serialization/variant.hpp>
24 #endif //GENOM_SERIALIZATION
25 #include <cmath>
26 
27 #include "torc/generic/Value.hpp"
28 
29 namespace torc {
30 namespace generic {
31 
32 Value::MiNoMax::MiNoMax() : mMin(), mMinUndefined(true), mNominal(), mMax(), mMaxUndefined(true) {}
33 
35  mMin(inMin), mMinUndefined(false), mNominal(inNominal), mMax(inMax), mMaxUndefined(false) {}
36 
38 
39 Value::MiNoMax::MiNoMax(const Value::MiNoMax& inSource) : mMin(inSource.mMin),
40  mMinUndefined(inSource.mMinUndefined), mNominal(inSource.mNominal), mMax(inSource.mMax),
41  mMaxUndefined(inSource.mMaxUndefined) {}
42 
44  if(this != &inSource) {
45  mMin = inSource.mMin;
46  mMinUndefined = inSource.mMinUndefined;
47  mNominal = inSource.mNominal;
48  mMax = inSource.mMax;
49  mMaxUndefined = inSource.mMaxUndefined;
50  }
51  return *this;
52 }
53 
54 bool Value::MiNoMax::operator <(const Value::MiNoMax& inRhs) const {
55  return mNominal.eval() < inRhs.mNominal.eval();
56 }
57 
58 bool Value::MiNoMax::operator ==(const Value::MiNoMax& inRhs) const {
59  return mNominal.eval() == inRhs.mNominal.eval();
60 }
61 
62 bool Value::MiNoMax::operator >(const Value::MiNoMax& inRhs) const {
63  return mNominal.eval() > inRhs.mNominal.eval();
64 }
65 
66 bool Value::MiNoMax::operator >=(const Value::MiNoMax& inRhs) const {
67  return mNominal.eval() >= inRhs.mNominal.eval();
68 }
69 
70 bool Value::MiNoMax::operator <=(const Value::MiNoMax& inRhs) const {
71  return mNominal.eval() <= inRhs.mNominal.eval();
72 }
73 
74 bool Value::MiNoMax::operator !=(const Value::MiNoMax& inRhs) const {
75  return !operator ==(inRhs);
76 }
77 
78 void Value::MiNoMax::setMax(const Value::Number& inSource) {
79  mMax = inSource;
80  mMaxUndefined = false;
81 }
82 
83 void Value::MiNoMax::setMin(const Value::Number& inSource) {
84  mMin = inSource;
85  mMinUndefined = false;
86 }
87 
89  mNominal = inSource;
90 }
91 
92 Value::Number::Number() : mMantissa(0), mExponent(0) {}
93 
94 Value::Number::Number(int32_t inMantissa, int32_t inExponent) : mMantissa(inMantissa),
95  mExponent(inExponent) {}
96 
98 
99 Value::Number::Number(const Value::Number& inSource) : mMantissa(inSource.mMantissa),
100  mExponent(inSource.mExponent) {}
101 
103  if(this != &inSource) {
104  mMantissa = inSource.mMantissa;
105  mExponent = inSource.mExponent;
106  }
107  return *this;
108 }
109 
110 bool Value::Number::operator <(const Value::Number& inRhs) const {
111  return eval() < inRhs.eval();
112 }
113 
114 bool Value::Number::operator ==(const Value::Number& inRhs) const {
115  return eval() == inRhs.eval();
116 }
117 
118 bool Value::Number::operator >(const Value::Number& inRhs) const {
119  return eval() > inRhs.eval();
120 }
121 
122 bool Value::Number::operator >=(const Value::Number& inRhs) const {
123  return eval() >= inRhs.eval();
124 }
125 
126 bool Value::Number::operator <=(const Value::Number& inRhs) const {
127  return eval() <= inRhs.eval();
128 }
129 
130 bool Value::Number::operator !=(const Value::Number& inRhs) const {
131  return !operator ==(inRhs);
132 }
133 
134 void Value::Number::setMantissa(const int32_t& inSource) {
135  mMantissa = inSource;
136 }
137 
138 void Value::Number::setExponent(const int32_t& inSource) {
139  mExponent = inSource;
140 }
141 
142 double Value::Number::eval() const {
143  return static_cast<double>(mMantissa) * pow(10, static_cast<double>(mExponent));
144 }
145 
146 Value::Point::Point() : mX(0), mY(0) {}
147 
148 Value::Point::Point(int32_t inX, int32_t inY) : mX(inX), mY(inY) {}
149 
150 Value::Point::~Point() throw () {}
151 
152 Value::Point::Point(const Value::Point& inSource) : mX(inSource.mX), mY(inSource.mY) {}
153 
155  if(this != &inSource) {
156  mX = inSource.mX;
157  mY = inSource.mY;
158  }
159  return *this;
160 }
161 
162 bool Value::Point::operator <(const Value::Point& inRhs) const {
163  return mX < inRhs.mY || (mX == inRhs.mX && mY < inRhs.mY);
164 }
165 
166 bool Value::Point::operator ==(const Value::Point& inRhs) const {
167  return mX == inRhs.mY && mY == inRhs.mY;
168 }
169 
170 bool Value::Point::operator >(const Value::Point& inRhs) const {
171  return mX > inRhs.mY || (mX == inRhs.mX && mY > inRhs.mY);
172 }
173 
174 bool Value::Point::operator >=(const Value::Point& inRhs) const {
175  return mX >= inRhs.mY && mY >= inRhs.mY;
176 }
177 
178 bool Value::Point::operator <=(const Value::Point& inRhs) const {
179  return mX <= inRhs.mY && mY <= inRhs.mY;
180 }
181 
182 bool Value::Point::operator !=(const Value::Point& inRhs) const {
183  return !operator ==(inRhs);
184 }
185 
186 void Value::Point::setX(const int32_t& inSource) {
187  mX = inSource;
188 }
189 
190 void Value::Point::setY(const int32_t& inSource) {
191  mX = inSource;
192 }
193 
195 
196 Value::Value(Value::Type type) : mType(type), mValue(), mIsSet(false) {}
197 
198 Value::~Value() throw () {}
199 
200 Value::Value(const Value& inSource) : mType(inSource.mType), mValue(inSource.mValue),
201  mIsSet(inSource.mIsSet) {}
202 
203 Value& Value::operator=(const Value& inSource) {
204  if(this != &inSource) {
205  mType = inSource.mType;
206  mValue = inSource.mValue;
207  mIsSet = inSource.mIsSet;
208  }
209  return *this;
210 }
211 
212 /**
213  * Get the type of inSource stored in this object.
214  *
215  * @return The type of object
216  */
217 void Value::setType(const Value::Type& inSource) {
218  mType = inSource;
219 }
220 
221 /**
222  false* Set whether this object is defined with a inSource, or is undefined.
223  *
224  * @param[in] inSource True if initialized.
225  */
226 void Value::setIsSet(const bool& inSource) {
227  mIsSet = inSource;
228 }
229 
230 #ifdef GENOM_SERIALIZATION
231 template <class Archive> void Value::serialize(Archive& ar, unsigned int) {
232  ar & mType;
233  ar & mValue;
234  ar & mIsSet;
235 }
236 
237 //TO SATISFY THE LINKER
238 template void Value::serialize<boost::archive::binary_iarchive>(
239  boost::archive::binary_iarchive& ar, const unsigned int);
240 
241 template void Value::serialize<boost::archive::binary_oarchive>(
242  boost::archive::binary_oarchive& ar, const unsigned int);
243 
244 #endif //GENOM_SERIALIZATION
245 
246 } // namespace generic
247 } // namespace torc
bool operator==(const Point &inRhs) const
Definition: Value.cpp:166
bool operator>(const MiNoMax &inRhs) const
Definition: Value.cpp:62
void setMantissa(const int32_t &inSource)
Definition: Value.cpp:134
bool operator!=(const Point &inRhs) const
Definition: Value.cpp:182
double eval() const
Definition: Value.cpp:142
bool operator>=(const MiNoMax &inRhs) const
Definition: Value.cpp:66
void setX(const int32_t &inSource)
Definition: Value.cpp:186
void setNominal(const Value::Number &inSource)
Definition: Value.cpp:88
bool operator!=(const MiNoMax &inRhs) const
Definition: Value.cpp:74
void setMax(const Value::Number &inSource)
Definition: Value.cpp:78
bool operator>(const Point &inRhs) const
Definition: Value.cpp:170
void setMin(const Value::Number &inSource)
Definition: Value.cpp:83
bool operator<=(const Number &inRhs) const
Definition: Value.cpp:126
Number & operator=(const Number &inSource)
Definition: Value.cpp:102
bool operator<(const Point &inRhs) const
Definition: Value.cpp:162
boost::variant< Value::Boolean, Value::Integer, Value::Number, Value::MiNoMax, Value::Point, Value::String > mValue
Definition: Value.hpp:303
bool operator==(const location &loc1, const location &loc2)
Compare two location objects.
bool operator!=(const Number &inRhs) const
Definition: Value.cpp:130
bool operator==(const Number &inRhs) const
Definition: Value.cpp:114
bool operator==(const MiNoMax &inRhs) const
Definition: Value.cpp:58
Point & operator=(const Point &inSource)
Definition: Value.cpp:154
bool operator>=(const Number &inRhs) const
Definition: Value.cpp:122
MiNoMax & operator=(const MiNoMax &inSource)
Definition: Value.cpp:43
void setType(const Type &inSource)
Definition: Value.cpp:217
bool operator>=(const Point &inRhs) const
Definition: Value.cpp:174
bool operator<=(const Point &inRhs) const
Definition: Value.cpp:178
bool operator<=(const MiNoMax &inRhs) const
Definition: Value.cpp:70
bool operator<(const Number &inRhs) const
Definition: Value.cpp:110
void setExponent(const int32_t &inSource)
Definition: Value.cpp:138
bool operator>(const Number &inRhs) const
Definition: Value.cpp:118
void setY(const int32_t &inSource)
Definition: Value.cpp:190
bool operator<(const MiNoMax &inRhs) const
Definition: Value.cpp:54
Value & operator=(const Value &inSource)
Definition: Value.cpp:203
void setIsSet(const bool &inSource)
Definition: Value.cpp:226