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