]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringType.cpp
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / StringType.cpp
1 #include "StringType.h"
2
3 #include "Range.h"
4 #include "Limit.h"
5
6 #include <limits>
7
8 namespace Databoard {
9         namespace Type {
10
11                 StringType::StringType()
12                 {
13                         this->length = NULL;
14                 }
15
16                 StringType::StringType(std::string pattern)
17                 {
18                         this->pattern = pattern;
19                         this->length = NULL;
20                 }
21
22                 StringType::StringType(std::string pattern, std::string mimeType, Range* length)
23                 {
24                         this->pattern = pattern;
25                         this->mimeType = mimeType;
26                         this->length = length;
27                 }
28
29                 StringType::~StringType()
30                 {
31                         if(length != NULL)
32                         {
33                                 delete length;
34                         }
35                 }
36
37                 std::string StringType::getPattern()
38                 {
39                         return pattern;
40                 }
41
42                 void StringType::setPattern(std::string pattern)
43                 {
44                         this->pattern = pattern;
45                 }
46
47                 std::string StringType::getMimeType()
48                 {
49                         return mimeType;
50                 }
51
52                 void StringType::setMimeType(std::string mimeType)
53                 {
54                         this->mimeType = mimeType;
55                 }
56
57                 Range* StringType::getLength()
58                 {
59                         return length;
60                 }
61
62                 void StringType::setLength(Range* length)
63                 {
64                         this->length = length;
65                 }
66
67                 int StringType::minLength()
68                 {
69                         if(length == NULL) return 0;
70
71                         return length->getLower()->getInteger(INT_MAX);
72                 }
73
74                 int StringType::maxLength()
75                 {
76                         if(length == NULL) return INT_MAX;
77                         
78                         return length->getUpper()->getInteger(INT_MIN);
79                 }
80
81                 std::string StringType::writeOut(int /*indent*/)
82                 {
83                         std::string s;
84
85                         s.append("String");
86
87                         bool parenthesis = false;
88
89                         if(mimeType.size() > 0)
90                         {
91                                 s += "(mimeType=\"" + mimeType + "\"";
92
93                                 parenthesis = true;
94                         }
95
96                         if(pattern.size() > 0)
97                         {
98                                 if(parenthesis == false)
99                                 {
100                                         s += "(";
101                                 }
102                                 else
103                                 {
104                                         s += ", ";
105                                 }
106
107                                 s += "pattern=\"" + pattern + "\"";
108
109                                 parenthesis = true;
110                         }
111
112                         if(parenthesis == true)
113                         {
114                                 s += ")";
115                         }
116
117                         return s;
118                 }
119         }
120 }