1 #include "FloatValue.h"
\r
3 #include "FloatType.h"
\r
4 #include "Constants.h"
\r
12 namespace Databoard {
\r
14 FloatValue::FloatValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)
\r
18 FloatValue::~FloatValue()
\r
22 void FloatValue::setValue(float value)
\r
24 Databoard::Type::FloatType* floatType = dynamic_cast<Databoard::Type::FloatType*>(dataBoard);
\r
26 if(floatType != NULL)
\r
28 this->value = value;
\r
32 float FloatValue::getValue()
\r
37 std::string FloatValue::writeOut(int /*indent*/)
\r
41 std::stringstream oss;
\r
47 //if(unit.size() != 0)
\r
49 // s += "(Unit=\"" + unit + "\")";
\r
55 bool FloatValue::equals(const Value* other)
\r
57 FloatValue* o = (FloatValue*)other;
\r
59 return (this->value < o->value);
\r
63 std::string FloatValue::isValid()
\r
65 if(dataBoard == NULL)
\r
67 return "There is no datatype.";
\r
70 Databoard::Type::FloatType* floatType = (Databoard::Type::FloatType*)dataBoard;
\r
72 if(floatType->getRange() == NULL)
\r
77 double minValue = floatType->minValue();
\r
78 double maxValue = floatType->maxValue();
\r
80 if(floatType->getRange()->getLower()->getInclusive() == true)
\r
82 if(value < minValue)
\r
84 return std::string("FloatValue: ") + STR_ERROR_VALUE_SMALL;
\r
87 else //if(integerType->getRange()->getLower()->getInclusive() == false)
\r
89 if(value < minValue || (abs(value-minValue) < FLT_EPSILON))
\r
91 return std::string("FloatValue: ") + STR_ERROR_VALUE_SMALL;
\r
95 if(floatType->getRange()->getUpper()->getInclusive() == true)
\r
97 if(value > maxValue)
\r
99 return std::string("FloatValue: ") + STR_ERROR_VALUE_LARGE;
\r
102 else //if(integerType->getRange()->getUpper()->getInclusive() == false)
\r
104 if(value > maxValue || (abs(value-minValue) > FLT_EPSILON))
\r
106 return std::string("FloatValue: ") + STR_ERROR_VALUE_LARGE;
\r