#include "UnionValue.h" #include "UnionType.h" #include "Component.h" #include "Constants.h" namespace Databoard { namespace Value { UnionValue::UnionValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) { tag = -1; value = NULL; } UnionValue::~UnionValue() { if(value != NULL) { delete value; value = NULL; } } int UnionValue::getTag() { return tag; } Value* UnionValue::getValue() { return value; } void UnionValue::setValue(int tag, Value* value) { this->tag = tag; this->value = value; } std::string UnionValue::writeOut(int /*indent*/) { std::string s; Databoard::Type::UnionType* unionType = (Databoard::Type::UnionType*)dataBoard; Databoard::Type::Component* component = unionType->getComponent(tag); if(component != NULL) { s += component->getName(); s += " "; } if(value != NULL) { s += value->writeOut(); } //s += value; //if(unit.size() != 0) //{ // s += "(Unit=\"" + unit + "\")"; //} return s; } bool UnionValue::equals(const Value* other) { UnionValue* o = (UnionValue*)other; if(tag != o->tag) { return (tag < o->tag); } return (value->equals(o->value)); } std::string UnionValue::isValid() { if(dataBoard == NULL) { return "LongValue: There is no datatype."; } if(value == NULL) { return STR_ERROR; } return value->isValid(); } } }