#include "DoubleValue.h" #include "DoubleType.h" #include "Constants.h" #include "Range.h" #include "Limit.h" #include #include #include #include #include namespace Databoard { namespace Value { DoubleValue::DoubleValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) { } DoubleValue::~DoubleValue() { } void DoubleValue::setValue(double value) { Databoard::Type::DoubleType* doubleType = dynamic_cast(dataBoard); if(doubleType != NULL) { this->value = value; } } double DoubleValue::getValue() { return value; } std::string DoubleValue::writeOut(int /*indent*/) { std::string s; std::stringstream oss; //oss.setf(std::ios::fixed); oss << value; oss >> s; return s; } bool DoubleValue::equals(const Value* other) { DoubleValue* o = (DoubleValue*)other; return (this->value < o->value); } std::string DoubleValue::isValid() { if(dataBoard == NULL) { return "There is no datatype."; } Databoard::Type::DoubleType* doubleType = (Databoard::Type::DoubleType*)dataBoard; if(doubleType->getRange() == NULL) { return STR_EMPTY; } double minValue = doubleType->minValue(); double maxValue = doubleType->maxValue(); if(doubleType->getRange()->getLower()->getInclusive() == true) { if(value < minValue) { return std::string("DoubleValue: ") + STR_ERROR_VALUE_SMALL; } } else //if(integerType->getRange()->getLower()->getInclusive() == false) { if(value < minValue || (abs(value-minValue) < DBL_EPSILON)) { return std::string("DoubleValue: ") + STR_ERROR_VALUE_SMALL; } } if(doubleType->getRange()->getUpper()->getInclusive() == true) { if(value > maxValue) { return std::string("DoubleValue: ") + STR_ERROR_VALUE_LARGE; } } else //if(integerType->getRange()->getUpper()->getInclusive() == false) { double d1 = abs(value-maxValue); double d2 = DBL_EPSILON; if(value > maxValue || (abs(value-maxValue) < DBL_EPSILON)) { return std::string("DoubleValue: ") + STR_ERROR_VALUE_LARGE; } } return STR_EMPTY; } } }