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
43 /** ValueVariant - Boost Variant to hold type of property*/
\r
44 typedef boost::variant <
\r
50 std::vector<Properties>
\r
54 /** VariantType - enumeration for variant types*/
\r
55 enum class VariantType
\r
68 * @class ValueProperty
\r
69 * @brief This class provides data Model for Json Schema Value Property.
\r
74 /** Type - enumeration for ValueProperty types*/
\r
86 * Constructor of ValueProperty.
\r
90 ValueProperty(const ValueProperty &) = default;
\r
92 ValueProperty &operator=(const ValueProperty &) = default;
\r
94 ValueProperty(ValueProperty &&) = default;
\r
96 ValueProperty &operator=(ValueProperty &&) = default;
\r
99 * explicit Constructor of ValueProperty for Type RANGE.
\r
101 * @param min - minimum value of property.
\r
102 * @param max- maximum value of property.
\r
103 * @param multipleOf- multipleOf value of property.
\r
105 explicit ValueProperty(double min, double max, int multipleOf);
\r
108 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
110 * @param valueSet - allowed values in the Properties.
\r
112 explicit ValueProperty(const std::vector<int> &valueSet);
\r
115 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
117 * @param valueSet - allowed values in the Properties.
\r
119 explicit ValueProperty(const std::vector<double> &valueSet);
\r
122 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
124 * @param valueSet - allowed values in the Properties.
\r
126 explicit ValueProperty(const std::vector<bool> &valueSet);
\r
129 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
131 * @param valueSet - allowed values in the Properties.
\r
133 explicit ValueProperty(const std::vector<std::string> &valueSet);
\r
136 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
138 * @param valueSet - allowed values in the Properties.
\r
140 explicit ValueProperty(const std::vector<ValueVariant> &valueSet);
\r
143 * explicit Constructor of ValueProperty for Type PATTERN or FORMAT.
\r
145 * @param type - ValueProperty Type.
\r
146 * @param value - value for the pattern or format.
\r
148 explicit ValueProperty(Type type, std::string value);
\r
151 * explicit Constructor of ValueProperty for Type ARRAY.
\r
153 * @param type - ValueProperty Type.
\r
154 * @param minItems - minimum elements in the Array property.
\r
155 * @param maxItems - maximum elements in the Array property.
\r
156 * @param unique - unique elements in the Array property.
\r
157 * @param additionalItems - additional elements in the Array property.
\r
159 explicit ValueProperty(Type type, int minItems, int maxItems, bool unique, bool additionalItems);
\r
162 * This method is for getting type of ValueProperty.
\r
164 * @return Type of ValueProperty
\r
169 * This method is for getting minimum value of ValueProperty.
\r
171 * @return min value of ValueProperty
\r
173 double min() const;
\r
176 * This method is for getting maximum value of ValueProperty.
\r
178 * @return max value of ValueProperty
\r
180 double max() const;
\r
183 * This method is for getting multipleOf value of ValueProperty.
\r
185 * @return multipleOf value of ValueProperty
\r
187 int multipleOf() const;
\r
190 * This method is for getting pattern value of ValueProperty.
\r
192 * @return pattern value of ValueProperty
\r
194 std::string pattern() const;
\r
197 * This method is for getting format value of ValueProperty.
\r
199 * @return format value of ValueProperty
\r
201 std::string format() const;
\r
204 * This method is for getting valueSet of ValueProperty.
\r
206 * @return valueSet of ValueProperty
\r
208 int valueSetSize() const;
\r
211 * This method is for getting valueSet of ValueProperty.
\r
213 * @return valueSet of ValueProperty
\r
215 std::vector<ValueVariant> valueSet() const;
\r
218 * This method is for getting valueArray of ValueProperty.
\r
220 * @param minItems - reference to get minimum elements in the Array property.
\r
221 * @param maxItems - reference to get maximum elements in the Array property.
\r
222 * @param unique - reference to get unique elements in the Array property.
\r
223 * @param additionalItems - reference to get additional elements in the Array property.
\r
225 void valueArray(int &minItems, int &maxItems, bool &unique, bool &additionalItems) const;
\r
232 std::vector<ValueVariant> m_valueSet;
\r
233 std::string m_pattern;
\r
234 std::string m_format;
\r
238 bool m_additionalItems;
\r
242 * @class Properties
\r
243 * @brief This class provides data Model for Json Schema Properties.
\r
250 * @brief This class provides type information of Json Properties.
\r
256 * Constructor of TypeInfo.
\r
258 * @param VariantType - type of property.
\r
259 * @param VariantType - type of parent property.
\r
260 * @param int - depth of property.
\r
262 TypeInfo(VariantType type = VariantType::UNKNOWN,
\r
263 VariantType baseType = VariantType::UNKNOWN,
\r
266 TypeInfo(const TypeInfo &) = default;
\r
268 TypeInfo &operator=(const TypeInfo &) = default;
\r
270 TypeInfo(TypeInfo &&) = default;
\r
272 TypeInfo &operator=(TypeInfo &&) = default;
\r
275 * This method is for getting type of properties.
\r
277 * @return VariantType of Property
\r
279 VariantType type() const;
\r
282 * This method is for getting base or parent type of properties.
\r
284 * @return VariantType of parent Property
\r
286 VariantType baseType() const;
\r
289 * This method is for getting depth of properties.
\r
291 * @return depth as int
\r
296 * operator for TypeInfo to check equality.
\r
300 bool operator ==(const TypeInfo &) const;
\r
303 * operator for TypeInfo to check inequality.
\r
307 bool operator !=(const TypeInfo &) const;
\r
310 VariantType m_type;
\r
311 VariantType m_baseType;
\r
316 * Constructor of Properties.
\r
318 * @param name - Properties name as string.
\r
320 Properties(const std::string &name) : m_name(name) {}
\r
322 Properties() = default;
\r
324 Properties(const Properties &) = default;
\r
326 Properties &operator=(const Properties &) = default;
\r
328 Properties(Properties &&) = default;
\r
330 Properties &operator=(Properties &&) = default;
\r
333 * This method is for getting TypeInfo of Properties.
\r
335 * @return Properties TypeInfo
\r
337 TypeInfo getType() const;
\r
340 * This method is for setting type of Properties.
\r
342 * @param type -Propertie's Type
\r
344 void setTypeString(const std::string &type);
\r
347 * This method is for getting Name from Properties.
\r
349 * @return Properties name as string
\r
351 std::string getName() const;
\r
354 * This method is for setting name to Properties
\r
356 * @param name - Properties name as string.
\r
358 void setName(const std::string &name);
\r
361 * This method is for getting Description from Properties.
\r
363 * @return Description as string
\r
365 std::string getDescription() const;
\r
368 * This method is for setting Description to Properties
\r
370 * @param description - Description as string.
\r
372 void setDescription(const std::string &description);
\r
375 * This method is for setting Value to Properties.
\r
377 * @param value - Value of Properties
\r
379 template <typename T>
\r
380 void setValue(const T &value)
\r
382 m_value = std::make_shared<ValueVariant>(value);
\r
386 * This method is for getting Value from Properties.
\r
388 * @return Properties Value
\r
390 ValueVariant getValue() const;
\r
393 * This method is for getting Value from Properties.
\r
395 * @return Properties Value
\r
397 template <typename T>
\r
400 return boost::get<T>(*(m_value.get()));
\r
404 * This method is for checking if default Value exists in the Properties.
\r
406 * @return true if present and false if not present
\r
408 bool isDefaultValue() const { return ((m_value != nullptr) ? true : false); }
\r
411 * This method is for getting ValueProperty from Properties.
\r
413 * @return vector of pointer to ValueProperty
\r
415 std::vector<std::shared_ptr<ValueProperty> > const &getValueProperties() const;
\r
418 * This method is for setting ValueProperty to Properties
\r
420 * @param value - pointer to ValueProperty
\r
422 void setValueProperty(const std::shared_ptr<ValueProperty> &value);
\r
426 * This method is for getting RequiredValue from Properties.
\r
428 * @return list of RequiredValue as string
\r
430 std::vector<std::string> const &getRequiredValues() const;
\r
433 * This method is for setting RequiredValue to Properties
\r
435 * @param reqValue - RequiredValue as string.
\r
437 void setRequiredValue(const std::string &reqValue);
\r
441 std::string m_typeString;
\r
442 std::string m_name;
\r
443 std::string m_description;
\r
444 std::shared_ptr<ValueVariant> m_value;
\r
445 std::vector<std::shared_ptr<ValueProperty> > m_valueProperty;
\r
446 std::vector<std::string> m_required;
\r
449 /** PropertiesPtr - shared Ptr to Properties.*/
\r
450 typedef std::shared_ptr<Properties> PropertiesPtr;
\r
452 /** ValuePropertyPtr - shared Ptr to ValueProperty.*/
\r
453 typedef std::shared_ptr<ValueProperty> ValuePropertyPtr;
\r