X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FDoubleValue.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FDoubleValue.cpp;h=258cc4b7a2fc52a91816ee1c0e25e40c4aed7fbf;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/DoubleValue.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/DoubleValue.cpp new file mode 100644 index 000000000..258cc4b7a --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/DoubleValue.cpp @@ -0,0 +1,115 @@ +#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; + } + } +}