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), m_doubleMin(INT_MAX), m_doubleMax(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_doubleMin(INT_MAX), m_doubleMax(INT_MAX), 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(int &min, int &max, int &multipleOf) const
\r
195 multipleOf = m_multipleOf;
\r
199 * This method is for getting Range from Properties.
\r
201 * @param min - reference to hold Minimum value of Properties.
\r
202 * @param max - reference to hold Maximum value of Properties.
\r
203 * @param multipleOf - reference to hold multipleOf value of Properties.
\r
205 inline void getRangeDouble(double &min, double &max, int &multipleOf) const
\r
209 multipleOf = m_multipleOf;
\r
212 * This method is for setting Minimum to Properties
\r
214 * @param min - Minimum value of Properties.
\r
216 inline void setMin(const int &min)
\r
222 * This method is for setting Maximum to Properties
\r
224 * @param max - Maximum value of Properties.
\r
226 inline void setMax(const int &max)
\r
232 * This method is for setting Minimum to Properties
\r
234 * @param min - Minimum value of Properties.
\r
236 inline void setMinDouble(const double &min)
\r
242 * This method is for setting Maximum to Properties
\r
244 * @param max - Maximum value of Properties.
\r
246 inline void setMaxDouble(const double &max)
\r
251 * This method is for setting multipleOf to Properties
\r
253 * @param multipleOf - multipleOf value of Properties.
\r
255 inline void setMultipleOf(const int &multipleOf)
\r
257 m_multipleOf = multipleOf;
\r
261 * This method is for setting AllowedValues to Properties
\r
263 * @param values - list of AllowedValues of Properties.
\r
265 template <typename T>
\r
266 bool setAllowedValues(const std::vector<T> &values)
\r
268 ValueVariant temp = values.at(0);
\r
269 if (temp.which() != m_value.which())
\r
274 m_allowedValues.addValues(values);
\r
279 * This method is for getting size of AllowedValues from Properties.
\r
281 * @return size of AllowedValues
\r
283 inline int getAllowedValuesSize() const
\r
285 return m_allowedValues.size();
\r
289 * This method is for getting AllowedValues from Properties.
\r
291 * @return list of AllowedValues of Properties.
\r
293 inline std::vector<ValueVariant> getAllowedValues()
\r
295 return m_allowedValues.getValues();
\r
299 * This method is for getting AllowedValues as integer from Properties.
\r
301 * @return list of AllowedValues as integer
\r
303 inline std::vector<int> getAllowedValuesInt()
\r
305 return m_allowedValues.getValuesInt();
\r
309 * This method is for getting AllowedValues as String from Properties.
\r
311 * @return list of AllowedValues as String
\r
313 inline std::vector<std::string> getAllowedValuesString()
\r
315 return m_allowedValues.getValuesString();
\r
319 * This method is for getting AllowedValues as Double from Properties.
\r
321 * @return list of AllowedValues as Double
\r
323 inline std::vector<double> getAllowedValuesDouble()
\r
325 return m_allowedValues.getValuesDouble();
\r
329 * This method is for getting AllowedValues as Bool from Properties.
\r
331 * @return list of AllowedValues as Bool
\r
333 inline std::vector<bool> getAllowedValuesBool()
\r
335 return m_allowedValues.getValuesBool();
\r
339 * This method is for setting Description to Properties
\r
341 * @param description - Description as string.
\r
343 inline void setDescription(const std::string &description)
\r
345 m_description = description;
\r
349 * This method is for getting Description from Properties.
\r
351 * @return Description as string
\r
353 inline std::string getDescription()
\r
355 return m_description;
\r
359 * This method is for setting Type to Properties
\r
361 * @param type - Type as string.
\r
363 void setType(const std::string &type)
\r
369 * This method is for getting Type from Properties.
\r
371 * @return Type as string
\r
373 std::string getType()
\r
379 * This method is for setting Pattern to Properties
\r
381 * @param pattern - Pattern as string.
\r
383 void setPattern(const std::string &pattern)
\r
385 m_pattern = pattern;
\r
390 * This method is for getting Pattern from Properties.
\r
392 * @return Pattern as string
\r
394 std::string getPattern()
\r
400 * This method is for setting Format to Properties
\r
402 * @param format - Format as string.
\r
404 void setFormat(const std::string &format)
\r
410 * This method is for getting Format from Properties.
\r
412 * @return Format as string
\r
414 std::string getFormat()
\r
420 * This method is for setting Items to Properties
\r
422 * @param item - pointer to Items
\r
424 void setItem(const ItemsPtr &item)
\r
426 m_items.push_back(item);
\r
430 * This method is for getting Items from Properties.
\r
432 * @return list of pointer to Items
\r
434 std::vector<ItemsPtr> const &getItems() const
\r
440 * This method is for setting Unique to Properties
\r
442 * @param value - Unique as bool
\r
444 void setUnique( int value)
\r
446 if (value == cJSON_True) m_unique = true;
\r
447 else m_unique = false;
\r
451 * This method is for getting isUnique from Properties.
\r
453 * @return isUnique as bool
\r
461 * This method is for setting AdditionalItems to Properties
\r
463 * @param value - AdditionalItems as bool
\r
465 void setAdditionalItems(int value)
\r
467 if (value == cJSON_True) m_additionalItems = true;
\r
468 else m_additionalItems = false;
\r
472 * This method is for getting AdditionalItems from Properties.
\r
474 * @return AdditionalItems as bool
\r
476 bool getAdditionalItems()
\r
478 return m_additionalItems;
\r
481 std::string m_name;
\r
482 ValueVariant m_value;
\r
485 double m_doubleMin;
\r
486 double m_doubleMax;
\r
488 AllowedValues m_allowedValues;
\r
489 std::string m_type;
\r
490 std::string m_pattern;
\r
491 std::string m_format;
\r
492 std::string m_description;
\r
494 bool m_additionalItems;
\r
495 std::vector<ItemsPtr > m_items;
\r
498 /** PropertiesPtr - shared Ptr to Properties.*/
\r
499 typedef std::shared_ptr<Properties> PropertiesPtr;
\r