Adding JsonSchema parser implementation for simulator and Updating Raml Parser.
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / jsonSchemaParser / Properties.h
1 /******************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  ******************************************************************/\r
20 \r
21 #ifndef PROPERTIES_H_\r
22 #define PROPERTIES_H_\r
23 \r
24 #include <string>\r
25 #include <vector>\r
26 #include <map>\r
27 #include <boost/variant.hpp>\r
28 #include <boost/lexical_cast.hpp>\r
29 #include <limits>\r
30 #include "Items.h"\r
31 #include "AllowedValues.h"\r
32 #include "cJSON.h"\r
33 \r
34 namespace RAML\r
35 {\r
36     class Properties\r
37     {\r
38         public:\r
39             Properties(): m_min(INT_MAX), m_max(INT_MAX), m_multipleOf(INT_MAX) {}\r
40             Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX),\r
41                 m_multipleOf(INT_MAX) {}\r
42 \r
43             inline std::string getName(void) const\r
44             {\r
45                 return m_name;\r
46             }\r
47             inline void setName(const std::string &name)\r
48             {\r
49                 m_name = name;\r
50             }\r
51             template <typename T>\r
52             T getValue() const\r
53             {\r
54                 T val = T();\r
55                 return boost::get<T>(m_value);\r
56             }\r
57 \r
58             ValueVariant &getValue()\r
59             {\r
60                 return m_value;\r
61             }\r
62 \r
63             int getValueType() const\r
64             {\r
65                 return m_value.which();\r
66             }\r
67             int getValueInt()\r
68             {\r
69                 return boost::lexical_cast<int> (m_value);\r
70             }\r
71             std::string getValueString()\r
72             {\r
73                 return boost::lexical_cast<std::string> (m_value);\r
74             }\r
75 \r
76             template <typename T>\r
77             void setValue(const T &value)\r
78             {\r
79                 m_value = value;\r
80             }\r
81             inline void getRange(int &min, int &max, int &multipleOf) const\r
82             {\r
83                 min = m_min;\r
84                 max = m_max;\r
85                 multipleOf = m_multipleOf;\r
86             }\r
87             inline void setMin(const int &min)\r
88             {\r
89                 m_min = min;\r
90             }\r
91             inline void setMax(const int &max)\r
92             {\r
93                 m_max = max;\r
94             }\r
95             inline void setMultipleOf(const int &multipleOf)\r
96             {\r
97                 m_multipleOf = multipleOf;\r
98             }\r
99 \r
100             template <typename T>\r
101             bool setAllowedValues(const std::vector<T> &values)\r
102             {\r
103                 ValueVariant temp = values.at(0);\r
104                 if (temp.which() != m_value.which())\r
105                 {\r
106                     return false;\r
107                 }\r
108 \r
109                 m_allowedValues.addValues(values);\r
110                 return true;\r
111             }\r
112             inline int getAllowedValuesSize() const\r
113             {\r
114                 return m_allowedValues.size();\r
115             }\r
116             inline std::vector<ValueVariant> getAllowedValues()\r
117             {\r
118                 return m_allowedValues.getValues();\r
119             }\r
120             inline std::vector<int> getAllowedValuesInt()\r
121             {\r
122                 return m_allowedValues.getValuesInt();\r
123             }\r
124             inline std::vector<std::string> getAllowedValuesString()\r
125             {\r
126                 return m_allowedValues.getValuesString();\r
127             }\r
128             inline void setDescription(const std::string &description)\r
129             {\r
130                 m_description = description;\r
131             }\r
132             inline std::string getDescription()\r
133             {\r
134                 return m_description;\r
135             }\r
136             inline int getUpdateFrequencyTime()\r
137             {\r
138                 return m_updateInterval;\r
139             }\r
140             inline void setUpdateFrequencyTime(int interval)\r
141             {\r
142                 m_updateInterval = interval;\r
143             }\r
144             void setType(const std::string &type)\r
145             {\r
146                 m_type = type;\r
147             }\r
148             std::string getType()\r
149             {\r
150                 return m_type;\r
151             }\r
152             void setPattern(const std::string &pattern)\r
153             {\r
154                 m_pattern = pattern;\r
155             }\r
156             std::string getPattern()\r
157             {\r
158                 return m_pattern;\r
159             }\r
160             void setFormat(const std::string &format)\r
161             {\r
162                 m_format = format;\r
163             }\r
164             std::string getFormat()\r
165             {\r
166                 return m_format;\r
167             }\r
168             void setItem(Items *item)\r
169             {\r
170                 m_items.push_back(item);\r
171             }\r
172             std::vector<Items *> getItems()\r
173             {\r
174                 return m_items;\r
175             }\r
176             void setUnique( int value)\r
177             {\r
178                 if (value == cJSON_True) m_unique = true;\r
179                 else m_unique = false;\r
180             }\r
181 \r
182             bool getUnique()\r
183             {\r
184                 return m_unique;\r
185             }\r
186 \r
187             void setAdditionalItems(int value)\r
188             {\r
189                 if (value == cJSON_True) m_additionalItems = true;\r
190                 else m_additionalItems = false;\r
191             }\r
192 \r
193             bool getAdditionalItems()\r
194             {\r
195                 return m_additionalItems;\r
196             }\r
197         private:\r
198             std::string m_name;\r
199             ValueVariant m_value;\r
200             int m_max;\r
201             int m_min;\r
202             int m_multipleOf;\r
203             AllowedValues m_allowedValues;\r
204             int m_updateInterval;\r
205             std::string m_type;\r
206             std::string m_pattern;\r
207             std::string m_format;\r
208             std::string m_description;\r
209             bool m_unique;\r
210             bool m_additionalItems;\r
211             std::vector<Items *> m_items;\r
212     };\r
213     typedef std::shared_ptr<Properties> PropertiesPtr;\r
214 \r
215 }\r
216 #endif\r