#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; } } }