1 /******************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 ******************************************************************/
\r
22 * @file Properties.h
\r
24 * @brief This file provides data Model for Json Schema Properties.
\r
27 #ifndef PROPERTIES_H_
\r
28 #define PROPERTIES_H_
\r
33 #include <boost/variant.hpp>
\r
34 #include <boost/lexical_cast.hpp>
\r
37 #include "AllowedValues.h"
\r
45 * @brief This class provides data Model for Json Schema Properties.
\r
51 * Constructor of Properties.
\r
53 Properties(): m_min(INT_MAX), m_max(INT_MAX),
\r
54 m_multipleOf(INT_MAX), m_unique(false), m_additionalItems(false) {}
\r
57 * Constructor of Properties.
\r
59 * @param name - Properties name as string.
\r
61 Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX),
\r
62 m_multipleOf(INT_MAX),
\r
63 m_unique(false), m_additionalItems(false) {}
\r
66 * This method is for getting Name from Properties.
\r
68 * @return Properties name as string
\r
70 inline std::string getName(void) const
\r
76 * This method is for setting name to Properties
\r
78 * @param name - Properties name as string.
\r
80 inline void setName(const std::string &name)
\r
86 * This method is for getting Value from Properties.
\r
88 * @return Properties Value
\r
90 template <typename T>
\r
93 return boost::get<T>(m_value);
\r
97 * This method is for getting Value from Properties.
\r
99 * @return Properties Value
\r
101 ValueVariant &getValue()
\r
107 * This method is for getting ValueVariant type from Properties.
\r
109 * @return Properties Value type as Int
\r
111 int getValueType() const
\r
113 return m_value.which();
\r
117 * This method is for getting ValueVariant type from Properties.
\r
119 * @return Properties VariantType type
\r
121 VariantType getVariantType() const
\r
123 if (m_value.which() == 3)
\r
124 return VariantType::STRING;
\r
125 else if (m_value.which() == 2)
\r
126 return VariantType::BOOL;
\r
127 else if (m_value.which() == 1)
\r
128 return VariantType::DOUBLE;
\r
130 return VariantType::INT;
\r
134 * This method is for getting Value type as Integer from Properties.
\r
136 * @return Properties Value type as Integer
\r
140 return boost::lexical_cast<int> (m_value);
\r
144 * This method is for getting Value type as String from Properties.
\r
146 * @return Properties Value type as String
\r
148 std::string getValueString()
\r
150 return boost::lexical_cast<std::string> (m_value);
\r
154 * This method is for getting Value type as double from Properties.
\r
156 * @return Properties Value type as double
\r
158 double getValueDouble()
\r
160 return boost::lexical_cast<double> (m_value);
\r
164 * This method is for getting Value type as bool from Properties.
\r
166 * @return Properties Value type as bool
\r
168 bool getValueBool()
\r
170 return boost::lexical_cast<bool> (m_value);
\r
174 * This method is for setting Value to Properties
\r
176 * @param value - Properties Value.
\r
178 template <typename T>
\r
179 void setValue(const T &value)
\r
185 * This method is for getting Range from Properties.
\r
187 * @param min - reference to hold Minimum value of Properties.
\r
188 * @param max - reference to hold Maximum value of Properties.
\r
189 * @param multipleOf - reference to hold multipleOf value of Properties.
\r
191 inline void getRange(double &min, double &max, int &multipleOf) const
\r
195 multipleOf = m_multipleOf;
\r
199 * This method is for setting Minimum to Properties.
\r
201 * @param min - Minimum value of Properties.
\r
203 inline void setMin(double min)
\r
209 * This method is for setting Maximum to Properties
\r
211 * @param max - Maximum value of Properties.
\r
213 inline void setMax(double max)
\r
218 * This method is for setting multipleOf to Properties
\r
220 * @param multipleOf - multipleOf value of Properties.
\r
222 inline void setMultipleOf(const int &multipleOf)
\r
224 m_multipleOf = multipleOf;
\r
228 * This method is for setting AllowedValues to Properties
\r
230 * @param values - list of AllowedValues of Properties.
\r
232 template <typename T>
\r
233 bool setAllowedValues(const std::vector<T> &values)
\r
235 ValueVariant temp = values.at(0);
\r
236 if (temp.which() != m_value.which())
\r
241 m_allowedValues.addValues(values);
\r
246 * This method is for getting size of AllowedValues from Properties.
\r
248 * @return size of AllowedValues
\r
250 inline int getAllowedValuesSize() const
\r
252 return m_allowedValues.size();
\r
256 * This method is for getting AllowedValues from Properties.
\r
258 * @return list of AllowedValues of Properties.
\r
260 inline std::vector<ValueVariant> getAllowedValues()
\r
262 return m_allowedValues.getValues();
\r
266 * This method is for getting AllowedValues as integer from Properties.
\r
268 * @return list of AllowedValues as integer
\r
270 inline std::vector<int> getAllowedValuesInt()
\r
272 return m_allowedValues.getValuesInt();
\r
276 * This method is for getting AllowedValues as String from Properties.
\r
278 * @return list of AllowedValues as String
\r
280 inline std::vector<std::string> getAllowedValuesString()
\r
282 return m_allowedValues.getValuesString();
\r
286 * This method is for getting AllowedValues as Double from Properties.
\r
288 * @return list of AllowedValues as Double
\r
290 inline std::vector<double> getAllowedValuesDouble()
\r
292 return m_allowedValues.getValuesDouble();
\r
296 * This method is for getting AllowedValues as Bool from Properties.
\r
298 * @return list of AllowedValues as Bool
\r
300 inline std::vector<bool> getAllowedValuesBool()
\r
302 return m_allowedValues.getValuesBool();
\r
306 * This method is for setting Description to Properties
\r
308 * @param description - Description as string.
\r
310 inline void setDescription(const std::string &description)
\r
312 m_description = description;
\r
316 * This method is for getting Description from Properties.
\r
318 * @return Description as string
\r
320 inline std::string getDescription()
\r
322 return m_description;
\r
326 * This method is for setting Type to Properties
\r
328 * @param type - Type as string.
\r
330 void setType(const std::string &type)
\r
336 * This method is for getting Type from Properties.
\r
338 * @return Type as string
\r
340 std::string getType()
\r
346 * This method is for setting Pattern to Properties
\r
348 * @param pattern - Pattern as string.
\r
350 void setPattern(const std::string &pattern)
\r
352 m_pattern = pattern;
\r
357 * This method is for getting Pattern from Properties.
\r
359 * @return Pattern as string
\r
361 std::string getPattern()
\r
367 * This method is for setting Format to Properties
\r
369 * @param format - Format as string.
\r
371 void setFormat(const std::string &format)
\r
377 * This method is for getting Format from Properties.
\r
379 * @return Format as string
\r
381 std::string getFormat()
\r
387 * This method is for setting Items to Properties
\r
389 * @param item - pointer to Items
\r
391 void setItem(const ItemsPtr &item)
\r
393 m_items.push_back(item);
\r
397 * This method is for getting Items from Properties.
\r
399 * @return list of pointer to Items
\r
401 std::vector<ItemsPtr> const &getItems() const
\r
407 * This method is for setting Unique to Properties
\r
409 * @param value - Unique as bool
\r
411 void setUnique( int value)
\r
413 if (value == cJSON_True) m_unique = true;
\r
414 else m_unique = false;
\r
418 * This method is for getting isUnique from Properties.
\r
420 * @return isUnique as bool
\r
428 * This method is for setting AdditionalItems to Properties
\r
430 * @param value - AdditionalItems as bool
\r
432 void setAdditionalItems(int value)
\r
434 if (value == cJSON_True) m_additionalItems = true;
\r
435 else m_additionalItems = false;
\r
439 * This method is for getting AdditionalItems from Properties.
\r
441 * @return AdditionalItems as bool
\r
443 bool getAdditionalItems()
\r
445 return m_additionalItems;
\r
448 std::string m_name;
\r
449 ValueVariant m_value;
\r
453 AllowedValues m_allowedValues;
\r
454 std::string m_type;
\r
455 std::string m_pattern;
\r
456 std::string m_format;
\r
457 std::string m_description;
\r
459 bool m_additionalItems;
\r
460 std::vector<ItemsPtr > m_items;
\r
463 /** PropertiesPtr - shared Ptr to Properties.*/
\r
464 typedef std::shared_ptr<Properties> PropertiesPtr;
\r