00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_VALUE_HPP
00017 #define TORC_GENERIC_OM_VALUE_HPP
00018
00019 #include "torc/generic/om/DumpRestoreConfig.hpp"
00020
00021
00022 #include <boost/variant.hpp>
00023
00024 #ifdef GENOM_SERIALIZATION
00025 #include <boost/serialization/access.hpp>
00026 #endif //GENOM_SERIALIZATION
00027
00028 #include "torc/generic/util/Error.hpp"
00029
00030 namespace torc {
00031
00032 namespace generic {
00033
00034
00035
00036
00037 class Value
00038 {
00039 #ifdef GENOM_SERIALIZATION
00040 friend class boost::serialization::access;
00041 #endif
00042 public:
00043
00044
00045
00046
00047
00048 enum Type
00049 {
00050 eValueTypeUndefined,
00051 eValueTypeBoolean,
00052 eValueTypeInteger,
00053 eValueTypeMiNoMax,
00054 eValueTypeNumber,
00055 eValueTypePoint,
00056 eValueTypeString
00057
00058 };
00059
00060
00061
00062 typedef bool Boolean;
00063
00064
00065
00066
00067 typedef int32_t Integer;
00068
00069
00070
00071
00072 typedef std::string String;
00073
00074
00075
00076
00077 class Number
00078 {
00079 #ifdef GENOM_SERIALIZATION
00080 friend class boost::serialization::access;
00081 #endif
00082
00083 private:
00084 int32_t mMantissa;
00085 int32_t mExponent;
00086
00087 public:
00088 Number();
00089
00090 Number(int32_t inMantissa, int32_t inExponent);
00091
00092 ~Number() throw();
00093
00094 Number(const Number & inSource) throw();
00095
00096 Number &
00097 operator=(const Number & inSource) throw();
00098
00099 bool
00100 operator <(const Number & inRhs) const throw();
00101
00102 bool
00103 operator ==(const Number & inRhs) const throw();
00104
00105 bool
00106 operator >(const Number & inRhs) const throw();
00107
00108 bool
00109 operator >=(const Number & inRhs) const throw();
00110
00111 bool
00112 operator <=(const Number & inRhs) const throw();
00113
00114 bool
00115 operator !=(const Number & inRhs) const throw();
00116
00117 inline const int32_t
00118 getMantissa() const throw();
00119
00120 void
00121 setMantissa(const int32_t & inSource) throw();
00122
00123 inline const int32_t
00124 getExponent() const throw();
00125
00126 void
00127 setExponent(const int32_t & inSource) throw();
00128
00129 double
00130 eval() const throw();
00131
00132 private:
00133 #ifdef GENOM_SERIALIZATION
00134 template<class Archive> void
00135 serialize( Archive &ar, unsigned int ) {
00136 ar & mExponent;
00137 ar & mMantissa;
00138 }
00139 #endif //GENOM_SERIALIZATION
00140 };
00141
00142
00143
00144
00145
00146 class MiNoMax
00147 {
00148 #ifdef GENOM_SERIALIZATION
00149 friend class boost::serialization::access;
00150 #endif
00151 private:
00152 Value::Number mMin;
00153 bool mMinUndefined;
00154 Value::Number mNominal;
00155 Value::Number mMax;
00156 bool mMaxUndefined;
00157
00158 public:
00159 MiNoMax();
00160
00161 MiNoMax(Value::Number inMin,
00162 Value::Number inNominal, Value::Number inMax );
00163
00164 ~MiNoMax() throw();
00165
00166 MiNoMax(const MiNoMax & inSource) throw();
00167
00168 MiNoMax &
00169 operator=(const MiNoMax & inSource) throw();
00170
00171 bool
00172 operator <(const MiNoMax & inRhs) const throw();
00173
00174 bool
00175 operator ==(const MiNoMax & inRhs) const throw();
00176
00177 bool
00178 operator !=(const MiNoMax & inRhs) const throw();
00179
00180 bool
00181 operator >(const MiNoMax & inRhs) const throw();
00182
00183 bool
00184 operator >=(const MiNoMax & inRhs) const throw();
00185
00186 bool
00187 operator <=(const MiNoMax & inRhs) const throw();
00188
00189 void
00190 setMax(const Value::Number & inSource) throw();
00191
00192 inline const Value::Number
00193 getMax() const throw();
00194
00195 inline const bool
00196 getMinUndefined() const throw();
00197
00198 inline const bool
00199 getMaxUndefined() const throw();
00200
00201 inline const Value::Number
00202 getMin() const throw();
00203
00204 void
00205 setMin(const Value::Number & inSource) throw();
00206
00207 inline const Value::Number
00208 getNominal() const throw();
00209
00210 void
00211 setNominal(const Value::Number & inSource) throw();
00212
00213 #ifdef GENOM_SERIALIZATION
00214 template<class Archive> void
00215 serialize( Archive &ar, unsigned int ) {
00216 ar & mMin;
00217 ar & mMinUndefined;
00218 ar & mNominal;
00219 ar & mMax;
00220 ar & mMaxUndefined;
00221 }
00222 #endif //GENOM_SERIALIZATION
00223
00224 };
00225
00226
00227
00228
00229
00230 class Point
00231 {
00232 #ifdef GENOM_SERIALIZATION
00233 friend class boost::serialization::access;
00234 #endif
00235
00236 private:
00237 int32_t mX;
00238 int32_t mY;
00239
00240 public:
00241 Point();
00242
00243 Point(int32_t inX, int32_t inY);
00244
00245 ~Point() throw();
00246
00247 Point(const Point & inSource);
00248
00249 Point &
00250 operator=(const Point & inSource) throw();
00251
00252 bool
00253 operator <(const Point & inRhs) const throw();
00254
00255 bool
00256 operator ==(const Point & inRhs) const throw();
00257
00258 bool
00259 operator !=(const Point & inRhs) const throw();
00260
00261 bool
00262 operator >(const Point & inRhs) const throw();
00263
00264 bool
00265 operator >=(const Point & inRhs) const throw();
00266
00267 bool
00268 operator <=(const Point & inRhs) const throw();
00269
00270 inline const int32_t
00271 getX() const throw();
00272
00273 void
00274 setX(const int32_t & inSource) throw();
00275
00276 inline const int32_t
00277 getY() const throw();
00278
00279 void
00280 setY(const int32_t & inSource) throw();
00281
00282 private:
00283 #ifdef GENOM_SERIALIZATION
00284 template<class Archive> void
00285 serialize( Archive &ar, unsigned int ) {
00286 ar & mX;
00287 ar & mY;
00288 }
00289 #endif //GENOM_SERIALIZATION
00290 };
00291
00292 Value();
00293
00294 Value(Type type);
00295
00296 template<typename _ValueType>
00297 Value(Type type, const _ValueType & inSource);
00298
00299 ~Value() throw();
00300
00301 Value(const Value & inSource);
00302
00303 Value &
00304 operator=(const Value & inSource) throw();
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 template<typename _ValueType>
00316 _ValueType
00317 get() const throw(Error);
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 template<typename _ValueType>
00329 void
00330 set(const _ValueType & inSource) throw(Error);
00331
00332
00333
00334
00335
00336
00337 inline const Type
00338 getType() const throw();
00339
00340
00341
00342
00343
00344
00345 void
00346 setType(const Type & inSource) throw();
00347
00348
00349
00350
00351
00352
00353 inline const bool
00354 getIsSet() const throw();
00355
00356
00357
00358
00359
00360
00361 void
00362 setIsSet(const bool & inSource) throw();
00363
00364
00365 private:
00366 #ifdef GENOM_SERIALIZATION
00367 template<class Archive> void
00368 serialize( Archive &ar, unsigned int );
00369 #endif //GENOM_SERIALIZATION
00370
00371 Type mType;
00372 boost::variant<
00373 Value::Boolean,
00374 Value::Integer,
00375 Value::Number,
00376 Value::MiNoMax,
00377 Value::Point,
00378 Value::String> mValue;
00379 bool mIsSet;
00380 };
00381
00382 inline const Value::Number
00383 Value::MiNoMax::getMax() const throw() {
00384 return mMax;
00385 }
00386
00387 inline const bool
00388 Value::MiNoMax::getMinUndefined() const throw() {
00389 return mMinUndefined;
00390 }
00391
00392 inline const bool
00393 Value::MiNoMax::getMaxUndefined() const throw() {
00394 return mMaxUndefined;
00395 }
00396
00397 inline const Value::Number
00398 Value::MiNoMax::getMin() const throw() {
00399 return mMin;
00400 }
00401
00402 inline const Value::Number
00403 Value::MiNoMax::getNominal() const throw() {
00404 return mNominal;
00405 }
00406
00407 inline const int32_t
00408 Value::Number::getMantissa() const throw() {
00409 return mMantissa;
00410 }
00411
00412 inline const int32_t
00413 Value::Number::getExponent() const throw() {
00414 return mExponent;
00415 }
00416
00417 inline const int32_t
00418 Value::Point::getX() const throw() {
00419 return mX;
00420 }
00421
00422 inline const int32_t
00423 Value::Point::getY() const throw() {
00424 return mY;
00425 }
00426
00427
00428
00429
00430
00431
00432 inline const Value::Type
00433 Value::getType() const throw() {
00434 return mType;
00435 }
00436
00437
00438
00439
00440
00441
00442 inline const bool
00443 Value::getIsSet() const throw() {
00444 return mIsSet;
00445 }
00446
00447 template<typename _ValueType>
00448 Value::Value(Value::Type type, const _ValueType & inSource)
00449 :mType( type ),
00450 mValue( inSource ),
00451 mIsSet( true ) {
00452 }
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463 template<typename _ValueType>
00464 void
00465 Value::set(const _ValueType & inSource) throw(Error) {
00466 mValue = inSource;
00467 }
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 template<typename _ValueType>
00479 _ValueType
00480 Value::get() const throw(Error) {
00481 if( !mIsSet )
00482 {
00483 Error e( eMessageIdErrorValueNotSet,
00484 __FUNCTION__, __FILE__, __LINE__ );
00485 e.saveContextData("Value set", mIsSet );
00486 throw e;
00487 }
00488 _ValueType v;
00489 try
00490 {
00491 v = boost::get<_ValueType>(mValue);
00492 }
00493 catch( const boost::bad_get &e )
00494 {
00495 Error e( eMessageIdErrorTypeCast,
00496 __FUNCTION__, __FILE__, __LINE__ );
00497 e.saveContextData("Value", mValue );
00498 e.saveContextData("Casted Type",
00499 std::string("_ValueType") );
00500 throw e;
00501 }
00502 return v;
00503 }
00504
00505
00506 }
00507
00508 }
00509 #endif // TORC_GENERIC_OM_VALUE_HPP