]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/OptionalValue.cpp
Added org.simantics.fileimport{,ui} to bundles POM.
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / OptionalValue.cpp
1 #include "OptionalValue.h"\r
2 \r
3 #include "Constants.h"\r
4 \r
5 namespace Databoard {\r
6         namespace Value {\r
7                 OptionalValue::OptionalValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)\r
8                 {\r
9                         this->value = NULL;\r
10                 }\r
11 \r
12                 OptionalValue::~OptionalValue()\r
13                 {\r
14                         if(value != NULL)\r
15                         {\r
16                                 delete value;\r
17                                 \r
18                                 value = NULL;\r
19                         }\r
20                 }\r
21 \r
22                 void OptionalValue::setValue(Value* value)\r
23                 {\r
24                         if(this->value != NULL)\r
25                         {\r
26                                 delete this->value;\r
27                                 \r
28                                 this->value = NULL;\r
29                         }\r
30 \r
31                         this->value = value;\r
32                 }\r
33 \r
34                 void OptionalValue::setNoValue()\r
35                 {\r
36                         if(value != NULL)\r
37                         {\r
38                                 delete value;\r
39                                 \r
40                                 value = NULL;\r
41                         }\r
42                 }\r
43 \r
44                 Value* OptionalValue::getValue()\r
45                 {\r
46                         return value;\r
47                 }\r
48 \r
49                 bool OptionalValue::hasValue()\r
50                 {\r
51                         return (value != NULL);\r
52                 }\r
53 \r
54                 std::string OptionalValue::writeOut(int /*indent*/)\r
55                 {\r
56                         std::string s;\r
57 \r
58                         if(value != NULL)\r
59                         {\r
60                                 s += value->writeOut();\r
61                         }\r
62 \r
63                         return s;\r
64                 }\r
65 \r
66                 bool OptionalValue::equals(const Value* other)\r
67                 {\r
68                         OptionalValue* o = (OptionalValue*)other;\r
69 \r
70                         if(hasValue() != o->hasValue())\r
71                         {\r
72                                 return hasValue();\r
73                         }\r
74 \r
75                         return value->equals(o->value);\r
76                 }\r
77 \r
78                 std::string OptionalValue::isValid()\r
79                 {\r
80                         if(hasValue() == true)\r
81                         {\r
82                                 return value->isValid();\r
83                         }\r
84 \r
85                         return STR_EMPTY;\r
86                 }\r
87         }\r
88 }\r