]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/UnionValue.cpp
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / UnionValue.cpp
1 #include "UnionValue.h"
2
3 #include "UnionType.h"
4 #include "Component.h"
5 #include "Constants.h"
6
7 namespace Databoard {
8         namespace Value {
9                 UnionValue::UnionValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)
10                 {
11                         tag = -1;
12                         value = NULL;
13                 }
14
15                 UnionValue::~UnionValue()
16                 {
17                         if(value != NULL)
18                         {
19                                 delete value;
20                                 value = NULL;
21                         }
22                 }
23
24                 int UnionValue::getTag()
25                 {
26                         return tag;
27                 }
28
29                 Value* UnionValue::getValue()
30                 {
31                         return value;
32                 }
33
34                 void UnionValue::setValue(int tag, Value* value)
35                 {
36                         this->tag = tag;
37                         this->value = value;
38                 }
39
40                 std::string UnionValue::writeOut(int /*indent*/)
41                 {
42                         std::string s;
43
44                         Databoard::Type::UnionType* unionType = (Databoard::Type::UnionType*)dataBoard;
45
46                         Databoard::Type::Component* component = unionType->getComponent(tag);
47
48                         if(component != NULL)
49                         {
50                                 s += component->getName();
51                                 s += " ";
52                         }
53
54                         if(value != NULL)
55                         {
56                                 s += value->writeOut();
57                         }
58
59                         //s += value;
60
61                         //if(unit.size() != 0)
62                         //{
63                         //      s += "(Unit=\"" + unit + "\")";
64                         //}
65
66                         return s;
67                 }
68
69                 bool UnionValue::equals(const Value* other)
70                 {
71                         UnionValue* o = (UnionValue*)other;
72
73                         if(tag != o->tag)
74                         {
75                                 return (tag < o->tag);
76                         }
77
78                         return (value->equals(o->value));
79                 }
80
81                 std::string UnionValue::isValid()
82                 {
83                         if(dataBoard == NULL)
84                         {
85                                 return "LongValue: There is no datatype.";
86                         }
87
88                         if(value == NULL)
89                         {
90                                 return STR_ERROR;
91                         }
92
93                         return value->isValid();
94                 }
95         }
96 }