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
36 #if defined (__TIZENRT__)
\r
37 #include <apps/netutils/cJSON.h>
\r
47 /** ValueVariant - Boost Variant to hold type of property*/
\r
48 typedef boost::variant <
\r
54 std::vector<Properties>
\r
58 /** VariantType - enumeration for variant types*/
\r
59 enum class VariantType
\r
72 * @class ValueProperty
\r
73 * @brief This class provides data Model for Json Schema Value Property.
\r
78 /** Type - enumeration for ValueProperty types*/
\r
90 * Constructor of ValueProperty.
\r
94 ValueProperty(const ValueProperty &) = default;
\r
96 ValueProperty &operator=(const ValueProperty &) = default;
\r
98 ValueProperty(ValueProperty &&) = default;
\r
100 ValueProperty &operator=(ValueProperty &&) = default;
\r
103 * explicit Constructor of ValueProperty for Type RANGE.
\r
105 * @param min - minimum value of property.
\r
106 * @param max- maximum value of property.
\r
107 * @param multipleOf- multipleOf value of property.
\r
109 explicit ValueProperty(double min, double max, int multipleOf);
\r
112 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
114 * @param valueSet - allowed values in the Properties.
\r
116 explicit ValueProperty(const std::vector<int> &valueSet);
\r
119 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
121 * @param valueSet - allowed values in the Properties.
\r
123 explicit ValueProperty(const std::vector<double> &valueSet);
\r
126 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
128 * @param valueSet - allowed values in the Properties.
\r
130 explicit ValueProperty(const std::vector<bool> &valueSet);
\r
133 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
135 * @param valueSet - allowed values in the Properties.
\r
137 explicit ValueProperty(const std::vector<std::string> &valueSet);
\r
140 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
142 * @param valueSet - allowed values in the Properties.
\r
144 explicit ValueProperty(const std::vector<ValueVariant> &valueSet);
\r
147 * explicit Constructor of ValueProperty for Type PATTERN or FORMAT.
\r
149 * @param type - ValueProperty Type.
\r
150 * @param value - value for the pattern or format.
\r
152 explicit ValueProperty(Type type, std::string value);
\r
155 * explicit Constructor of ValueProperty for Type ARRAY.
\r
157 * @param type - ValueProperty Type.
\r
158 * @param minItems - minimum elements in the Array property.
\r
159 * @param maxItems - maximum elements in the Array property.
\r
160 * @param unique - unique elements in the Array property.
\r
161 * @param additionalItems - additional elements in the Array property.
\r
163 explicit ValueProperty(Type type, int minItems, int maxItems, bool unique, bool additionalItems);
\r
166 * This method is for getting type of ValueProperty.
\r
168 * @return Type of ValueProperty
\r
173 * This method is for getting minimum value of ValueProperty.
\r
175 * @return min value of ValueProperty
\r
177 double min() const;
\r
180 * This method is for getting maximum value of ValueProperty.
\r
182 * @return max value of ValueProperty
\r
184 double max() const;
\r
187 * This method is for getting multipleOf value of ValueProperty.
\r
189 * @return multipleOf value of ValueProperty
\r
191 int multipleOf() const;
\r
194 * This method is for getting pattern value of ValueProperty.
\r
196 * @return pattern value of ValueProperty
\r
198 std::string pattern() const;
\r
201 * This method is for getting format value of ValueProperty.
\r
203 * @return format value of ValueProperty
\r
205 std::string format() const;
\r
208 * This method is for getting valueSet of ValueProperty.
\r
210 * @return valueSet of ValueProperty
\r
212 int valueSetSize() const;
\r
215 * This method is for getting valueSet of ValueProperty.
\r
217 * @return valueSet of ValueProperty
\r
219 std::vector<ValueVariant> valueSet() const;
\r
222 * This method is for getting valueArray of ValueProperty.
\r
224 * @param minItems - reference to get minimum elements in the Array property.
\r
225 * @param maxItems - reference to get maximum elements in the Array property.
\r
226 * @param unique - reference to get unique elements in the Array property.
\r
227 * @param additionalItems - reference to get additional elements in the Array property.
\r
229 void valueArray(int &minItems, int &maxItems, bool &unique, bool &additionalItems) const;
\r
236 std::vector<ValueVariant> m_valueSet;
\r
237 std::string m_pattern;
\r
238 std::string m_format;
\r
242 bool m_additionalItems;
\r
246 * @class Properties
\r
247 * @brief This class provides data Model for Json Schema Properties.
\r
254 * @brief This class provides type information of Json Properties.
\r
260 * Constructor of TypeInfo.
\r
262 * @param VariantType - type of property.
\r
263 * @param VariantType - type of parent property.
\r
264 * @param int - depth of property.
\r
266 TypeInfo(VariantType type = VariantType::UNKNOWN,
\r
267 VariantType baseType = VariantType::UNKNOWN,
\r
270 TypeInfo(const TypeInfo &) = default;
\r
272 TypeInfo &operator=(const TypeInfo &) = default;
\r
274 TypeInfo(TypeInfo &&) = default;
\r
276 TypeInfo &operator=(TypeInfo &&) = default;
\r
279 * This method is for getting type of properties.
\r
281 * @return VariantType of Property
\r
283 VariantType type() const;
\r
286 * This method is for getting base or parent type of properties.
\r
288 * @return VariantType of parent Property
\r
290 VariantType baseType() const;
\r
293 * This method is for getting depth of properties.
\r
295 * @return depth as int
\r
300 * operator for TypeInfo to check equality.
\r
304 bool operator ==(const TypeInfo &) const;
\r
307 * operator for TypeInfo to check inequality.
\r
311 bool operator !=(const TypeInfo &) const;
\r
314 VariantType m_type;
\r
315 VariantType m_baseType;
\r
320 * Constructor of Properties.
\r
322 * @param name - Properties name as string.
\r
324 Properties(const std::string &name) : m_name(name) {}
\r
326 Properties() = default;
\r
328 Properties(const Properties &) = default;
\r
330 Properties &operator=(const Properties &) = default;
\r
332 Properties(Properties &&) = default;
\r
334 Properties &operator=(Properties &&) = default;
\r
337 * This method is for getting TypeInfo of Properties.
\r
339 * @return Properties TypeInfo
\r
341 TypeInfo getType() const;
\r
344 * This method is for setting type of Properties.
\r
346 * @param type -Propertie's Type
\r
348 void setTypeString(const std::string &type);
\r
351 * This method is for getting Name from Properties.
\r
353 * @return Properties name as string
\r
355 std::string getName() const;
\r
358 * This method is for setting name to Properties
\r
360 * @param name - Properties name as string.
\r
362 void setName(const std::string &name);
\r
365 * This method is for getting Description from Properties.
\r
367 * @return Description as string
\r
369 std::string getDescription() const;
\r
372 * This method is for setting Description to Properties
\r
374 * @param description - Description as string.
\r
376 void setDescription(const std::string &description);
\r
379 * This method is for setting Value to Properties.
\r
381 * @param value - Value of Properties
\r
383 template <typename T>
\r
384 void setValue(const T &value)
\r
386 m_value = std::make_shared<ValueVariant>(value);
\r
390 * This method is for getting Value from Properties.
\r
392 * @return Properties Value
\r
394 ValueVariant getValue() const;
\r
397 * This method is for getting Value from Properties.
\r
399 * @return Properties Value
\r
401 template <typename T>
\r
404 return boost::get<T>(*(m_value.get()));
\r
408 * This method is for checking if default Value exists in the Properties.
\r
410 * @return true if present and false if not present
\r
412 bool isDefaultValue() const { return ((m_value != nullptr) ? true : false); }
\r
415 * This method is for getting ValueProperty from Properties.
\r
417 * @return vector of pointer to ValueProperty
\r
419 std::vector<std::shared_ptr<ValueProperty> > const &getValueProperties() const;
\r
422 * This method is for setting ValueProperty to Properties
\r
424 * @param value - pointer to ValueProperty
\r
426 void setValueProperty(const std::shared_ptr<ValueProperty> &value);
\r
430 * This method is for getting RequiredValue from Properties.
\r
432 * @return list of RequiredValue as string
\r
434 std::vector<std::string> const &getRequiredValues() const;
\r
437 * This method is for setting RequiredValue to Properties
\r
439 * @param reqValue - RequiredValue as string.
\r
441 void setRequiredValue(const std::string &reqValue);
\r
445 std::string m_typeString;
\r
446 std::string m_name;
\r
447 std::string m_description;
\r
448 std::shared_ptr<ValueVariant> m_value;
\r
449 std::vector<std::shared_ptr<ValueProperty> > m_valueProperty;
\r
450 std::vector<std::string> m_required;
\r
453 /** PropertiesPtr - shared Ptr to Properties.*/
\r
454 typedef std::shared_ptr<Properties> PropertiesPtr;
\r
456 /** ValuePropertyPtr - shared Ptr to ValueProperty.*/
\r
457 typedef std::shared_ptr<ValueProperty> ValuePropertyPtr;
\r