#include "FloatValue.h" #include "FloatType.h" #include "Constants.h" #include "Range.h" #include "Limit.h" #include #include #include namespace Databoard { namespace Value { FloatValue::FloatValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) { } FloatValue::~FloatValue() { } void FloatValue::setValue(float value) { Databoard::Type::FloatType* floatType = dynamic_cast(dataBoard); if(floatType != NULL) { this->value = value; } } float FloatValue::getValue() { return value; } std::string FloatValue::writeOut(int /*indent*/) { std::string s; std::stringstream oss; oss << value; oss >> s; //if(unit.size() != 0) //{ // s += "(Unit=\"" + unit + "\")"; //} return s; } bool FloatValue::equals(const Value* other) { FloatValue* o = (FloatValue*)other; return (this->value < o->value); } std::string FloatValue::isValid() { if(dataBoard == NULL) { return "There is no datatype."; } Databoard::Type::FloatType* floatType = (Databoard::Type::FloatType*)dataBoard; if(floatType->getRange() == NULL) { return STR_EMPTY; } double minValue = floatType->minValue(); double maxValue = floatType->maxValue(); if(floatType->getRange()->getLower()->getInclusive() == true) { if(value < minValue) { return std::string("FloatValue: ") + STR_ERROR_VALUE_SMALL; } } else //if(integerType->getRange()->getLower()->getInclusive() == false) { if(value < minValue || (abs(value-minValue) < FLT_EPSILON)) { return std::string("FloatValue: ") + STR_ERROR_VALUE_SMALL; } } if(floatType->getRange()->getUpper()->getInclusive() == true) { if(value > maxValue) { return std::string("FloatValue: ") + STR_ERROR_VALUE_LARGE; } } else //if(integerType->getRange()->getUpper()->getInclusive() == false) { if(value > maxValue || (abs(value-minValue) > FLT_EPSILON)) { return std::string("FloatValue: ") + STR_ERROR_VALUE_LARGE; } } return STR_EMPTY; } } }