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