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
67 * @class ValueProperty
\r
68 * @brief This class provides data Model for Json Schema Value Property.
\r
73 /** Type - enumeration for ValueProperty types*/
\r
85 * Constructor of ValueProperty.
\r
89 * Copy Constructor of ValueProperty.
\r
91 * @param ValueProperty.
\r
93 ValueProperty(const ValueProperty &) = default;
\r
95 * Assignment operator for ValueProperty.
\r
97 * @param ValueProperty.
\r
99 ValueProperty &operator=(const ValueProperty &) = default;
\r
101 * Copy Constructor of ValueProperty.
\r
103 * @param ValueProperty.
\r
105 ValueProperty(ValueProperty &&) = default;
\r
107 * Assignment operator for ValueProperty.
\r
109 * @param ValueProperty.
\r
111 ValueProperty &operator=(ValueProperty &&) = default;
\r
114 * explicit Constructor of ValueProperty for Type RANGE.
\r
116 * @param min - minimum value of property.
\r
117 * @param max- maximum value of property.
\r
118 * @param multipleOf- multipleOf value of property.
\r
120 explicit ValueProperty(double min, double max, int multipleOf);
\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<int> &valueSet);
\r
128 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
130 * @param valueSet - allowed values in the Properties.
\r
132 explicit ValueProperty(const std::vector<double> &valueSet);
\r
134 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
136 * @param valueSet - allowed values in the Properties.
\r
138 explicit ValueProperty(const std::vector<bool> &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<std::string> &valueSet);
\r
146 * explicit Constructor of ValueProperty for Type VALUE_SET.
\r
148 * @param valueSet - allowed values in the Properties.
\r
150 explicit ValueProperty(const std::vector<ValueVariant> &valueSet);
\r
152 * explicit Constructor of ValueProperty for Type PATTERN or FORMAT.
\r
154 * @param type - ValueProperty Type.
\r
155 * @param value - value for the pattern or format.
\r
157 explicit ValueProperty(Type type, std::string value);
\r
159 * explicit Constructor of ValueProperty for Type ARRAY.
\r
161 * @param type - ValueProperty Type.
\r
162 * @param minItems - minimum elements in the Array property.
\r
163 * @param maxItems - maximum elements in the Array property.
\r
164 * @param unique - unique elements in the Array property.
\r
165 * @param additionalItems - additional elements in the Array property.
\r
167 explicit ValueProperty(Type type, int minItems, int maxItems, bool unique, bool additionalItems);
\r
170 * This method is for getting type of ValueProperty.
\r
172 * @return Type of ValueProperty
\r
176 * This method is for getting minimum value of ValueProperty.
\r
178 * @return min value of ValueProperty
\r
180 double min() const;
\r
182 * This method is for getting maximum value of ValueProperty.
\r
184 * @return max value of ValueProperty
\r
186 double max() const;
\r
188 * This method is for getting multipleOf value of ValueProperty.
\r
190 * @return multipleOf value of ValueProperty
\r
192 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
200 * This method is for getting format value of ValueProperty.
\r
202 * @return format value of ValueProperty
\r
204 std::string format() const;
\r
206 * This method is for getting valueSet of ValueProperty.
\r
208 * @return valueSet of ValueProperty
\r
210 int valueSetSize() const;
\r
212 * This method is for getting valueSet of ValueProperty.
\r
214 * @return valueSet of ValueProperty
\r
216 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, VariantType, int);
\r
264 * Copy Constructor of TypeInfo.
\r
268 TypeInfo(const TypeInfo &) = default;
\r
270 * Assignment operator for TypeInfo.
\r
274 TypeInfo &operator=(const TypeInfo &) = default;
\r
276 * Copy Constructor of TypeInfo.
\r
280 TypeInfo(TypeInfo &&) = default;
\r
282 * Assignment operator for TypeInfo.
\r
286 TypeInfo &operator=(TypeInfo &&) = default;
\r
288 * Constructor of TypeInfo.
\r
290 TypeInfo() = default;
\r
293 * This method is for getting type of properties.
\r
295 * @return VariantType of Property
\r
297 VariantType type() const;
\r
299 * This method is for getting base or parent type of properties.
\r
301 * @return VariantType of parent Property
\r
303 VariantType baseType() const;
\r
305 * This method is for getting depth of properties.
\r
307 * @return depth as int
\r
311 * operator for TypeInfo to check equality.
\r
315 bool operator ==(const TypeInfo &) const;
\r
317 * operator for TypeInfo to check inequality.
\r
321 bool operator !=(const TypeInfo &) const;
\r
324 VariantType m_type;
\r
325 VariantType m_baseType;
\r
330 * Constructor of Properties.
\r
332 * @param name - Properties name as string.
\r
334 Properties(const std::string &name) : m_name(name) {}
\r
336 * Constructor of Properties.
\r
338 Properties() = default;
\r
340 * Copy Constructor of Properties.
\r
342 * @param Properties.
\r
344 Properties(const Properties &) = default;
\r
346 * Assignment operator for Properties.
\r
348 * @param Properties.
\r
350 Properties &operator=(const Properties &) = default;
\r
352 * Copy Constructor of Properties.
\r
354 * @param Properties.
\r
356 Properties(Properties &&) = default;
\r
358 * Assignment operator for Properties.
\r
360 * @param Properties.
\r
362 Properties &operator=(Properties &&) = default;
\r
365 * This method is for getting TypeInfo of Properties.
\r
367 * @return Properties TypeInfo
\r
369 TypeInfo getType() const;
\r
372 * This method is for setting type of Properties.
\r
374 * @param type -Propertie's Type
\r
376 void setTypeString(const std::string &type);
\r
379 * This method is for getting Name from Properties.
\r
381 * @return Properties name as string
\r
383 std::string getName() const;
\r
385 * This method is for setting name to Properties
\r
387 * @param name - Properties name as string.
\r
389 void setName(const std::string &name);
\r
391 * This method is for getting Description from Properties.
\r
393 * @return Description as string
\r
395 std::string getDescription() const;
\r
398 * This method is for setting Description to Properties
\r
400 * @param description - Description as string.
\r
402 void setDescription(const std::string &description);
\r
405 * This method is for setting Value to Properties.
\r
407 * @param value - Value of Properties
\r
409 template <typename T>
\r
410 void setValue(const T &value)
\r
412 m_value = std::make_shared<ValueVariant>(value);
\r
416 * This method is for getting Value from Properties.
\r
418 * @return Properties Value
\r
420 ValueVariant getValue() const;
\r
423 * This method is for getting Value from Properties.
\r
425 * @return Properties Value
\r
427 template <typename T>
\r
430 return boost::get<T>(*(m_value.get()));
\r
434 * This method is for checking if default Value exists in the Properties.
\r
436 * @return true if present and false if not present
\r
438 bool isDefaultValue() const { return ((m_value != nullptr) ? true : false); }
\r
440 * This method is for getting ValueProperty from Properties.
\r
442 * @return vector of pointer to ValueProperty
\r
444 std::vector<std::shared_ptr<ValueProperty> > const &getValueProperties() const;
\r
447 * This method is for setting ValueProperty to Properties
\r
449 * @param value - pointer to ValueProperty
\r
451 void setValueProperty(const std::shared_ptr<ValueProperty> &value);
\r
455 * This method is for getting RequiredValue from Properties.
\r
457 * @return list of RequiredValue as string
\r
459 std::vector<std::string> const &getRequiredValues() const;
\r
462 * This method is for setting RequiredValue to Properties
\r
464 * @param reqValue - RequiredValue as string.
\r
466 void setRequiredValue(const std::string &reqValue);
\r
470 std::string m_typeString;
\r
471 std::string m_name;
\r
472 std::string m_description;
\r
473 std::shared_ptr<ValueVariant> m_value;
\r
474 std::vector<std::shared_ptr<ValueProperty> > m_valueProperty;
\r
475 std::vector<std::string> m_required;
\r
478 /** PropertiesPtr - shared Ptr to Properties.*/
\r
479 typedef std::shared_ptr<Properties> PropertiesPtr;
\r
481 /** ValuePropertyPtr - shared Ptr to ValueProperty.*/
\r
482 typedef std::shared_ptr<ValueProperty> ValuePropertyPtr;
\r