X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FUnionValue.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FUnionValue.cpp;h=67568e79fe017735ff1ffdcc32513534dca49938;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/UnionValue.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/UnionValue.cpp new file mode 100644 index 000000000..67568e79f --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/UnionValue.cpp @@ -0,0 +1,96 @@ +#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(); + } + } +}