]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/NumberType.cpp
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / NumberType.cpp
1 #include "NumberType.h"
2
3 #include "Range.h"
4
5 #include "Constants.h"
6
7 namespace Databoard {
8         namespace Type {
9
10                 NumberType::NumberType()
11                 {
12                         range = NULL;
13                 }
14
15                 NumberType::NumberType(std::string unit)
16                 {
17                         this->unit = unit;
18                         range = new Range();
19                 }
20
21                 NumberType::NumberType(std::string unit, Range* range)
22                 {
23                         this->unit = unit;
24                         this->range = range;
25                 }
26
27                 NumberType::~NumberType()
28                 {
29                         if(range != NULL)
30                         {
31                                 delete range;
32                         }
33                 }
34
35                 std::string NumberType::getUnit()
36                 {
37                         return unit;
38                 }
39
40                 void NumberType::setUnit(std::string unit)
41                 {
42                         this->unit = unit;
43                 }
44
45                 Range* NumberType::getRange()
46                 {
47                         return range;
48                 }
49
50                 void NumberType::setRange(Range* value)
51                 {
52                         this->range = value;
53                 }
54
55                 std::string NumberType::writeOut(int /*indent*/)
56                 {
57                         std::string s;
58
59                         bool parenthesis = false;
60
61                         if(unit.size() != 0)
62                         {
63                                 s += "(";
64                                 s.append(STR_UNIT);
65                                 s += "=\"" + unit + "\"";
66
67
68                                 parenthesis = true;
69                         }
70
71                         if(range != NULL)
72                         {
73                                 if(parenthesis == false)
74                                 {
75                                         s += "(";
76                                 }
77                                 else
78                                 {
79                                         s += ", ";
80                                 }
81
82                                 s.append(STR_RANGE);
83                                 s += "=" + range->writeOut();
84
85                                 parenthesis = true;
86                         }
87
88                         if(parenthesis == true)
89                         {
90                                 s += ")";
91                         }
92
93
94
95                         return s;
96                 }
97         }
98 }