1 #ifndef __DIADES__ALTARICA__VALUE__HH 2 #define __DIADES__ALTARICA__VALUE__HH 8 #include<unordered_map> 31 class AltaricaModelData;
45 typedef enum{OrOp=0,AndOp=1,ImplyOp=2,EqOp=3,NeqOp=4,GtOp=5,GeqOp=6,LtOp=7,LeqOp=8,AddOp=9,SubOp=10,MulOp=11,DivOp=12,ModOp=13}
BinaryOperator;
57 typedef vector<int>::size_type
Code;
76 static string typeName() {
return "Altarica::Value"; }
95 bool isEqualStructure(
const Value & value)
const;
96 bool isLessStructure(
const Value & value)
const;
97 bool isEqualArray(
const Value & value)
const;
98 bool isLessArray(
const Value & value)
const;
114 always_require(Exception, type().isInteger(),
"integer(): this value is not an integer");
124 always_require(Exception, type().isBoolean(),
"boolean(): this value is not a boolean");
134 always_require(Exception, !isNull(),
"identifier(): invalid value");
135 always_require(Exception, type().isIdentifier(),
"identifier(): this value is not an indentifier");
143 unsigned size()
const;
150 const Value & getField(
unsigned index)
const;
181 string textify()
const;
193 bool operator==(
const Value & value)
const;
202 bool operator<(
const Value & value)
const;
210 bool operator<=(
const Value & value)
const {
return (*
this < value) || (*
this == value); }
214 bool operator>=(
const Value & value)
const {
return (*
this > value) || (*
this == value); }
234 const Value & apply(UnaryOperator op)
const;
250 bool operator()(
const reference_wrapper<T> & ref1,
const reference_wrapper<T> & ref2)
252 return ref1.get() == ref2.get();
260 bool isEqual(
const vector< reference_wrapper<T> > & vect1,
const vector< reference_wrapper<T> > & vect2)
262 bool result = vect1.size() == vect2.size();
264 while(result && (index < vect1.size()))
272 template<
typename T1,
typename T2>
273 bool isEqual(
const map< T1, reference_wrapper<T2> > & map1,
const map< T1, reference_wrapper<T2> > & map2)
275 bool result = map1.size() == map2.size();
276 typename map< T1, reference_wrapper<T2> >::const_iterator it1 = map1.begin();
277 typename map< T1, reference_wrapper<T2> >::const_iterator it2 = map2.begin();
278 while(result && (it1 != map1.end()))
280 result = (it1->first == it2->first) &&
EqualRef<T2>()(it1->second,it2->second);
298 static string typeName() {
return "Diades::Altarica::ValueFactory"; }
314 const Value & getValue(
bool value);
319 const Value & getValue(
int value);
342 return *_basicValues[0];
414 template <Value::BinaryOperator OP>
418 static string typeName() {
return "Diades::Altarica::BinaryOperator"; }
423 return value1.
apply(OP,value2);
427 throw(Exception(
Msg(
"Failure to apply a binary operator between '%1%' and '%2%'.")
428 % value1 % value2,e));
434 template <Value::UnaryOperator OP>
438 static string typeName() {
return "Diades::Altarica::UnaryOperator"; }
443 return value.
apply(OP);
447 throw(Exception(
Msg(
"Failure to apply a unary operator on value '%1%'.")
vector< Value::Pointer > _identifierValues
const Identifier & identifier() const
bool operator()(const reference_wrapper< T > &ref1, const reference_wrapper< T > &ref2)
Utils::Exception< UnaryOperator< OP > > Exception
An Identifier is a reference to a string (IdentifierData) that only contains alpha-numeric characters...
#define always_require(Exception, expr, message)
unordered_map< string, unsigned > _structureMapping
bool operator>=(const Value &value) const
Type::ConstReference _type
vector< int >::size_type Code
const Value & nullValue() const
Utils::Exception< ValueFactory > Exception
vector< ConstReference > ArrayFields
map< Identifier, ConstReference > StructureFields
Utils::Exception< Value > Exception
reference_wrapper< Type const > ConstReference
reference_wrapper< Value const > ConstReference
const Value & apply(BinaryOperator op, const Value &value) const
Utils::Exception< BinaryOperator< OP > > Exception
Namespace of the Diades project.
StructureFields _structure
int operator()(const Value &value)
unordered_map< Identifier, unsigned > _identifierMapping
reference_wrapper< Value > Reference
unordered_map< int, Value::Pointer > _integerMapping
vector< Value::Pointer > _arrayedValues
ostream & operator<<(ostream &os, const CarriedValue &value)
bool isEqual(const map< T1, reference_wrapper< T2 > > &map1, const map< T1, reference_wrapper< T2 > > &map2)
vector< Value::ConstReference > ValueEnumeration
enumeration of Value elements (unicity and sorting is in charge of the user)
vector< Value::Pointer > _structuredValues
unordered_map< string, unsigned > _arrayMapping
bool operator()(const Value &value)
bool operator>(const Value &value) const
vector< Value::Pointer > _basicValues
bool operator!=(const Value &value) const
Identifier operator()(const Value &value)
const Type & type() const
bool operator<=(const Value &value) const