X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FLongValue.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FLongValue.cpp;h=47632d567dec8c7ec86080846593c742a1a3caec;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LongValue.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LongValue.cpp new file mode 100644 index 000000000..47632d567 --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LongValue.cpp @@ -0,0 +1,111 @@ +#include "LongValue.h" + +#include "LongType.h" +#include "Constants.h" +#include "Range.h" +#include "Limit.h" + +#include + +namespace Databoard { + namespace Value { + LongValue::LongValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) + { + } + + LongValue::~LongValue() + { + } + + void LongValue::setValue(long value) + { + Databoard::Type::LongType* longType = dynamic_cast(dataBoard); + + if(longType != NULL) + { + this->value = value; + } + } + + long LongValue::getValue() + { + return value; + } + + std::string LongValue::writeOut(int /*indent*/) + { + std::string s; + + std::stringstream oss; + + oss << value; + + oss >> s; + + //if(unit.size() != 0) + //{ + // s += "(Unit=\"" + unit + "\")"; + //} + + return s; + } + + bool LongValue::equals(const Value* other) + { + LongValue* o = (LongValue*)other; + + return (this->value < o->value); + + } + + std::string LongValue::isValid() + { + if(dataBoard == NULL) + { + return "LongValue: There is no datatype."; + } + + Databoard::Type::LongType* longType = (Databoard::Type::LongType*)dataBoard; + + if(longType->getRange() == NULL) + { + return STR_EMPTY; + } + + int minValue = longType->minValue(); + int maxValue = longType->maxValue(); + + if(longType->getRange()->getLower()->getInclusive() == true) + { + if(value < minValue) + { + return std::string("LongValue: ") + STR_ERROR_VALUE_SMALL; + } + } + else //if(longType->getRange()->getLower()->getInclusive() == false) + { + if(value <= minValue) + { + return std::string("LongValue: ") + STR_ERROR_VALUE_SMALL; + } + } + + if(longType->getRange()->getUpper()->getInclusive() == true) + { + if(value > maxValue) + { + return std::string("LongValue: ") + STR_ERROR_VALUE_LARGE; + } + } + else //if(longType->getRange()->getUpper()->getInclusive() == false) + { + if(value >= maxValue) + { + return std::string("LongValue: ") + STR_ERROR_VALUE_LARGE; + } + } + + return STR_EMPTY; + } + } +}