#include <boost/variant.hpp>\r
#include <boost/lexical_cast.hpp>\r
#include <limits>\r
-#include "Items.h"\r
-#include "AllowedValues.h"\r
+#if defined (__TIZENRT__)\r
+#include <apps/netutils/cJSON.h>\r
+#else\r
#include "cJSON.h"\r
+#endif\r
#include <memory>\r
\r
namespace RAML\r
{\r
+ class Properties;\r
+\r
+ /** ValueVariant - Boost Variant to hold type of property*/\r
+ typedef boost::variant <\r
+ int,\r
+ double,\r
+ bool,\r
+ std::string,\r
+ Properties,\r
+ std::vector<Properties>\r
+\r
+ > ValueVariant;\r
+\r
+ /** VariantType - enumeration for variant types*/\r
+ enum class VariantType\r
+ {\r
+ UNKNOWN,\r
+ INTEGER,\r
+ DOUBLE,\r
+ BOOLEAN,\r
+ STRING,\r
+ PROPERTY,\r
+ ARRAY,\r
+ OBJECT\r
+ };\r
+\r
/**\r
- * @class Properties\r
- * @brief This class provides data Model for Json Schema Properties.\r
+ * @class ValueProperty\r
+ * @brief This class provides data Model for Json Schema Value Property.\r
*/\r
- class Properties\r
+ class ValueProperty\r
{\r
public:\r
- /**\r
- * Constructor of Properties.\r
- */\r
- Properties(): m_min(INT_MAX), m_max(INT_MAX), m_doubleMin(INT_MAX), m_doubleMax(INT_MAX),\r
- m_multipleOf(INT_MAX), m_unique(false), m_additionalItems(false) {}\r
+ /** Type - enumeration for ValueProperty types*/\r
+ enum class Type\r
+ {\r
+ UNKNOWN,\r
+ RANGE,\r
+ VALUE_SET,\r
+ PATTERN,\r
+ FORMAT,\r
+ ARRAY\r
+ };\r
\r
/**\r
- * Constructor of Properties.\r
- *\r
- * @param name - Properties name as string.\r
- */\r
- Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX),\r
- m_doubleMin(INT_MAX), m_doubleMax(INT_MAX), m_multipleOf(INT_MAX),\r
- m_unique(false), m_additionalItems(false) {}\r
+ * Constructor of ValueProperty.\r
+ */\r
+ ValueProperty();\r
\r
- /**\r
- * This method is for getting Name from Properties.\r
- *\r
- * @return Properties name as string\r
- */\r
- inline std::string getName(void) const\r
- {\r
- return m_name;\r
- }\r
+ ValueProperty(const ValueProperty &) = default;\r
\r
- /**\r
- * This method is for setting name to Properties\r
- *\r
- * @param name - Properties name as string.\r
- */\r
- inline void setName(const std::string &name)\r
- {\r
- m_name = name;\r
- }\r
+ ValueProperty &operator=(const ValueProperty &) = default;\r
\r
- /**\r
- * This method is for getting Value from Properties.\r
- *\r
- * @return Properties Value\r
- */\r
- template <typename T>\r
- T getValue() const\r
- {\r
- return boost::get<T>(m_value);\r
- }\r
+ ValueProperty(ValueProperty &&) = default;\r
\r
- /**\r
- * This method is for getting Value from Properties.\r
- *\r
- * @return Properties Value\r
- */\r
- ValueVariant &getValue()\r
- {\r
- return m_value;\r
- }\r
+ ValueProperty &operator=(ValueProperty &&) = default;\r
\r
/**\r
- * This method is for getting ValueVariant type from Properties.\r
- *\r
- * @return Properties Value type as Int\r
- */\r
- int getValueType() const\r
- {\r
- return m_value.which();\r
- }\r
+ * explicit Constructor of ValueProperty for Type RANGE.\r
+ *\r
+ * @param min - minimum value of property.\r
+ * @param max- maximum value of property.\r
+ * @param multipleOf- multipleOf value of property.\r
+ */\r
+ explicit ValueProperty(double min, double max, int multipleOf);\r
\r
/**\r
- * This method is for getting ValueVariant type from Properties.\r
- *\r
- * @return Properties VariantType type\r
- */\r
- VariantType getVariantType() const\r
- {\r
- if (m_value.which() == 3)\r
- return VariantType::STRING;\r
- else if (m_value.which() == 2)\r
- return VariantType::BOOL;\r
- else if (m_value.which() == 1)\r
- return VariantType::DOUBLE;\r
- else\r
- return VariantType::INT;\r
- }\r
+ * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+ *\r
+ * @param valueSet - allowed values in the Properties.\r
+ */\r
+ explicit ValueProperty(const std::vector<int> &valueSet);\r
\r
/**\r
- * This method is for getting Value type as Integer from Properties.\r
- *\r
- * @return Properties Value type as Integer\r
- */\r
- int getValueInt()\r
- {\r
- return boost::lexical_cast<int> (m_value);\r
- }\r
+ * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+ *\r
+ * @param valueSet - allowed values in the Properties.\r
+ */\r
+ explicit ValueProperty(const std::vector<double> &valueSet);\r
\r
/**\r
- * This method is for getting Value type as String from Properties.\r
- *\r
- * @return Properties Value type as String\r
- */\r
- std::string getValueString()\r
- {\r
- return boost::lexical_cast<std::string> (m_value);\r
- }\r
+ * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+ *\r
+ * @param valueSet - allowed values in the Properties.\r
+ */\r
+ explicit ValueProperty(const std::vector<bool> &valueSet);\r
\r
/**\r
- * This method is for getting Value type as double from Properties.\r
- *\r
- * @return Properties Value type as double\r
- */\r
- double getValueDouble()\r
- {\r
- return boost::lexical_cast<double> (m_value);\r
- }\r
+ * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+ *\r
+ * @param valueSet - allowed values in the Properties.\r
+ */\r
+ explicit ValueProperty(const std::vector<std::string> &valueSet);\r
\r
/**\r
- * This method is for getting Value type as bool from Properties.\r
- *\r
- * @return Properties Value type as bool\r
- */\r
- bool getValueBool()\r
- {\r
- return boost::lexical_cast<bool> (m_value);\r
- }\r
+ * explicit Constructor of ValueProperty for Type VALUE_SET.\r
+ *\r
+ * @param valueSet - allowed values in the Properties.\r
+ */\r
+ explicit ValueProperty(const std::vector<ValueVariant> &valueSet);\r
\r
/**\r
- * This method is for setting Value to Properties\r
- *\r
- * @param value - Properties Value.\r
- */\r
- template <typename T>\r
- void setValue(const T &value)\r
- {\r
- m_value = value;\r
- }\r
+ * explicit Constructor of ValueProperty for Type PATTERN or FORMAT.\r
+ *\r
+ * @param type - ValueProperty Type.\r
+ * @param value - value for the pattern or format.\r
+ */\r
+ explicit ValueProperty(Type type, std::string value);\r
\r
/**\r
- * This method is for getting Range from Properties.\r
- *\r
- * @param min - reference to hold Minimum value of Properties.\r
- * @param max - reference to hold Maximum value of Properties.\r
- * @param multipleOf - reference to hold multipleOf value of Properties.\r
- */\r
- inline void getRange(int &min, int &max, int &multipleOf) const\r
- {\r
- min = m_min;\r
- max = m_max;\r
- multipleOf = m_multipleOf;\r
- }\r
+ * explicit Constructor of ValueProperty for Type ARRAY.\r
+ *\r
+ * @param type - ValueProperty Type.\r
+ * @param minItems - minimum elements in the Array property.\r
+ * @param maxItems - maximum elements in the Array property.\r
+ * @param unique - unique elements in the Array property.\r
+ * @param additionalItems - additional elements in the Array property.\r
+ */\r
+ explicit ValueProperty(Type type, int minItems, int maxItems, bool unique, bool additionalItems);\r
\r
/**\r
- * This method is for getting Range from Properties.\r
- *\r
- * @param min - reference to hold Minimum value of Properties.\r
- * @param max - reference to hold Maximum value of Properties.\r
- * @param multipleOf - reference to hold multipleOf value of Properties.\r
- */\r
- inline void getRangeDouble(double &min, double &max, int &multipleOf) const\r
- {\r
- min = m_doubleMin;\r
- max = m_doubleMax;\r
- multipleOf = m_multipleOf;\r
- }\r
- /**\r
- * This method is for setting Minimum to Properties\r
- *\r
- * @param min - Minimum value of Properties.\r
- */\r
- inline void setMin(const int &min)\r
- {\r
- m_min = min;\r
- }\r
+ * This method is for getting type of ValueProperty.\r
+ *\r
+ * @return Type of ValueProperty\r
+ */\r
+ Type type() const;\r
\r
/**\r
- * This method is for setting Maximum to Properties\r
- *\r
- * @param max - Maximum value of Properties.\r
- */\r
- inline void setMax(const int &max)\r
- {\r
- m_max = max;\r
- }\r
+ * This method is for getting minimum value of ValueProperty.\r
+ *\r
+ * @return min value of ValueProperty\r
+ */\r
+ double min() const;\r
\r
/**\r
- * This method is for setting Minimum to Properties\r
- *\r
- * @param min - Minimum value of Properties.\r
- */\r
- inline void setMinDouble(const double &min)\r
- {\r
- m_doubleMin = min;\r
- }\r
+ * This method is for getting maximum value of ValueProperty.\r
+ *\r
+ * @return max value of ValueProperty\r
+ */\r
+ double max() const;\r
\r
/**\r
- * This method is for setting Maximum to Properties\r
- *\r
- * @param max - Maximum value of Properties.\r
- */\r
- inline void setMaxDouble(const double &max)\r
- {\r
- m_doubleMax = max;\r
- }\r
- /**\r
- * This method is for setting multipleOf to Properties\r
- *\r
- * @param multipleOf - multipleOf value of Properties.\r
- */\r
- inline void setMultipleOf(const int &multipleOf)\r
- {\r
- m_multipleOf = multipleOf;\r
- }\r
+ * This method is for getting multipleOf value of ValueProperty.\r
+ *\r
+ * @return multipleOf value of ValueProperty\r
+ */\r
+ int multipleOf() const;\r
\r
/**\r
- * This method is for setting AllowedValues to Properties\r
- *\r
- * @param values - list of AllowedValues of Properties.\r
- */\r
- template <typename T>\r
- bool setAllowedValues(const std::vector<T> &values)\r
- {\r
- ValueVariant temp = values.at(0);\r
- if (temp.which() != m_value.which())\r
- {\r
- return false;\r
- }\r
-\r
- m_allowedValues.addValues(values);\r
- return true;\r
- }\r
+ * This method is for getting pattern value of ValueProperty.\r
+ *\r
+ * @return pattern value of ValueProperty\r
+ */\r
+ std::string pattern() const;\r
\r
/**\r
- * This method is for getting size of AllowedValues from Properties.\r
- *\r
- * @return size of AllowedValues\r
- */\r
- inline int getAllowedValuesSize() const\r
- {\r
- return m_allowedValues.size();\r
- }\r
+ * This method is for getting format value of ValueProperty.\r
+ *\r
+ * @return format value of ValueProperty\r
+ */\r
+ std::string format() const;\r
\r
/**\r
- * This method is for getting AllowedValues from Properties.\r
- *\r
- * @return list of AllowedValues of Properties.\r
- */\r
- inline std::vector<ValueVariant> getAllowedValues()\r
- {\r
- return m_allowedValues.getValues();\r
- }\r
+ * This method is for getting valueSet of ValueProperty.\r
+ *\r
+ * @return valueSet of ValueProperty\r
+ */\r
+ int valueSetSize() const;\r
\r
/**\r
- * This method is for getting AllowedValues as integer from Properties.\r
- *\r
- * @return list of AllowedValues as integer\r
- */\r
- inline std::vector<int> getAllowedValuesInt()\r
- {\r
- return m_allowedValues.getValuesInt();\r
- }\r
+ * This method is for getting valueSet of ValueProperty.\r
+ *\r
+ * @return valueSet of ValueProperty\r
+ */\r
+ std::vector<ValueVariant> valueSet() const;\r
\r
/**\r
- * This method is for getting AllowedValues as String from Properties.\r
- *\r
- * @return list of AllowedValues as String\r
- */\r
- inline std::vector<std::string> getAllowedValuesString()\r
- {\r
- return m_allowedValues.getValuesString();\r
- }\r
+ * This method is for getting valueArray of ValueProperty.\r
+ *\r
+ * @param minItems - reference to get minimum elements in the Array property.\r
+ * @param maxItems - reference to get maximum elements in the Array property.\r
+ * @param unique - reference to get unique elements in the Array property.\r
+ * @param additionalItems - reference to get additional elements in the Array property.\r
+ */\r
+ void valueArray(int &minItems, int &maxItems, bool &unique, bool &additionalItems) const;\r
\r
- /**\r
- * This method is for getting AllowedValues as Double from Properties.\r
- *\r
- * @return list of AllowedValues as Double\r
- */\r
- inline std::vector<double> getAllowedValuesDouble()\r
- {\r
- return m_allowedValues.getValuesDouble();\r
- }\r
+ private:\r
+ Type m_type;\r
+ double m_min;\r
+ double m_max;\r
+ int m_multipleOf;\r
+ std::vector<ValueVariant> m_valueSet;\r
+ std::string m_pattern;\r
+ std::string m_format;\r
+ int m_minItems;\r
+ int m_maxItems;\r
+ bool m_unique;\r
+ bool m_additionalItems;\r
+ };\r
\r
+ /**\r
+ * @class Properties\r
+ * @brief This class provides data Model for Json Schema Properties.\r
+ */\r
+ class Properties\r
+ {\r
+ public:\r
/**\r
- * This method is for getting AllowedValues as Bool from Properties.\r
- *\r
- * @return list of AllowedValues as Bool\r
- */\r
- inline std::vector<bool> getAllowedValuesBool()\r
+ * @class TypeInfo\r
+ * @brief This class provides type information of Json Properties.\r
+ */\r
+ class TypeInfo\r
{\r
- return m_allowedValues.getValuesBool();\r
- }\r
+ public:\r
+ /**\r
+ * Constructor of TypeInfo.\r
+ *\r
+ * @param VariantType - type of property.\r
+ * @param VariantType - type of parent property.\r
+ * @param int - depth of property.\r
+ */\r
+ TypeInfo(VariantType type = VariantType::UNKNOWN,\r
+ VariantType baseType = VariantType::UNKNOWN,\r
+ int depth = 0);\r
+\r
+ TypeInfo(const TypeInfo &) = default;\r
+\r
+ TypeInfo &operator=(const TypeInfo &) = default;\r
+\r
+ TypeInfo(TypeInfo &&) = default;\r
+\r
+ TypeInfo &operator=(TypeInfo &&) = default;\r
+\r
+ /**\r
+ * This method is for getting type of properties.\r
+ *\r
+ * @return VariantType of Property\r
+ */\r
+ VariantType type() const;\r
+\r
+ /**\r
+ * This method is for getting base or parent type of properties.\r
+ *\r
+ * @return VariantType of parent Property\r
+ */\r
+ VariantType baseType() const;\r
+\r
+ /**\r
+ * This method is for getting depth of properties.\r
+ *\r
+ * @return depth as int\r
+ */\r
+ int depth() const;\r
+\r
+ /**\r
+ * operator for TypeInfo to check equality.\r
+ *\r
+ * @param TypeInfo.\r
+ */\r
+ bool operator ==(const TypeInfo &) const;\r
+\r
+ /**\r
+ * operator for TypeInfo to check inequality.\r
+ *\r
+ * @param TypeInfo.\r
+ */\r
+ bool operator !=(const TypeInfo &) const;\r
+\r
+ private:\r
+ VariantType m_type;\r
+ VariantType m_baseType;\r
+ int m_depth;\r
+ };\r
\r
/**\r
- * This method is for setting Description to Properties\r
- *\r
- * @param description - Description as string.\r
- */\r
- inline void setDescription(const std::string &description)\r
- {\r
- m_description = description;\r
- }\r
+ * Constructor of Properties.\r
+ *\r
+ * @param name - Properties name as string.\r
+ */\r
+ Properties(const std::string &name) : m_name(name) {}\r
+\r
+ Properties() = default;\r
+\r
+ Properties(const Properties &) = default;\r
+\r
+ Properties &operator=(const Properties &) = default;\r
+\r
+ Properties(Properties &&) = default;\r
+\r
+ Properties &operator=(Properties &&) = default;\r
\r
/**\r
- * This method is for getting Description from Properties.\r
- *\r
- * @return Description as string\r
- */\r
- inline std::string getDescription()\r
- {\r
- return m_description;\r
- }\r
+ * This method is for getting TypeInfo of Properties.\r
+ *\r
+ * @return Properties TypeInfo\r
+ */\r
+ TypeInfo getType() const;\r
\r
/**\r
- * This method is for setting Type to Properties\r
- *\r
- * @param type - Type as string.\r
- */\r
- void setType(const std::string &type)\r
- {\r
- m_type = type;\r
- }\r
+ * This method is for setting type of Properties.\r
+ *\r
+ * @param type -Propertie's Type\r
+ */\r
+ void setTypeString(const std::string &type);\r
\r
/**\r
- * This method is for getting Type from Properties.\r
- *\r
- * @return Type as string\r
- */\r
- std::string getType()\r
- {\r
- return m_type;\r
- }\r
+ * This method is for getting Name from Properties.\r
+ *\r
+ * @return Properties name as string\r
+ */\r
+ std::string getName() const;\r
\r
/**\r
- * This method is for setting Pattern to Properties\r
- *\r
- * @param pattern - Pattern as string.\r
- */\r
- void setPattern(const std::string &pattern)\r
- {\r
- m_pattern = pattern;\r
- }\r
+ * This method is for setting name to Properties\r
+ *\r
+ * @param name - Properties name as string.\r
+ */\r
+ void setName(const std::string &name);\r
\r
+ /**\r
+ * This method is for getting Description from Properties.\r
+ *\r
+ * @return Description as string\r
+ */\r
+ std::string getDescription() const;\r
\r
/**\r
- * This method is for getting Pattern from Properties.\r
- *\r
- * @return Pattern as string\r
- */\r
- std::string getPattern()\r
- {\r
- return m_pattern;\r
- }\r
+ * This method is for setting Description to Properties\r
+ *\r
+ * @param description - Description as string.\r
+ */\r
+ void setDescription(const std::string &description);\r
\r
/**\r
- * This method is for setting Format to Properties\r
- *\r
- * @param format - Format as string.\r
- */\r
- void setFormat(const std::string &format)\r
+ * This method is for setting Value to Properties.\r
+ *\r
+ * @param value - Value of Properties\r
+ */\r
+ template <typename T>\r
+ void setValue(const T &value)\r
{\r
- m_format = format;\r
+ m_value = std::make_shared<ValueVariant>(value);\r
}\r
\r
/**\r
- * This method is for getting Format from Properties.\r
- *\r
- * @return Format as string\r
- */\r
- std::string getFormat()\r
- {\r
- return m_format;\r
- }\r
+ * This method is for getting Value from Properties.\r
+ *\r
+ * @return Properties Value\r
+ */\r
+ ValueVariant getValue() const;\r
\r
/**\r
- * This method is for setting Items to Properties\r
- *\r
- * @param item - pointer to Items\r
- */\r
- void setItem(const ItemsPtr &item)\r
+ * This method is for getting Value from Properties.\r
+ *\r
+ * @return Properties Value\r
+ */\r
+ template <typename T>\r
+ T getValue() const\r
{\r
- m_items.push_back(item);\r
+ return boost::get<T>(*(m_value.get()));\r
}\r
\r
/**\r
- * This method is for getting Items from Properties.\r
- *\r
- * @return list of pointer to Items\r
- */\r
- std::vector<ItemsPtr> const &getItems() const\r
- {\r
- return m_items;\r
- }\r
+ * This method is for checking if default Value exists in the Properties.\r
+ *\r
+ * @return true if present and false if not present\r
+ */\r
+ bool isDefaultValue() const { return ((m_value != nullptr) ? true : false); }\r
\r
/**\r
- * This method is for setting Unique to Properties\r
- *\r
- * @param value - Unique as bool\r
- */\r
- void setUnique( int value)\r
- {\r
- if (value == cJSON_True) m_unique = true;\r
- else m_unique = false;\r
- }\r
+ * This method is for getting ValueProperty from Properties.\r
+ *\r
+ * @return vector of pointer to ValueProperty\r
+ */\r
+ std::vector<std::shared_ptr<ValueProperty> > const &getValueProperties() const;\r
\r
/**\r
- * This method is for getting isUnique from Properties.\r
- *\r
- * @return isUnique as bool\r
- */\r
- bool getUnique()\r
- {\r
- return m_unique;\r
- }\r
+ * This method is for setting ValueProperty to Properties\r
+ *\r
+ * @param value - pointer to ValueProperty\r
+ */\r
+ void setValueProperty(const std::shared_ptr<ValueProperty> &value);\r
+\r
\r
/**\r
- * This method is for setting AdditionalItems to Properties\r
- *\r
- * @param value - AdditionalItems as bool\r
- */\r
- void setAdditionalItems(int value)\r
- {\r
- if (value == cJSON_True) m_additionalItems = true;\r
- else m_additionalItems = false;\r
- }\r
+ * This method is for getting RequiredValue from Properties.\r
+ *\r
+ * @return list of RequiredValue as string\r
+ */\r
+ std::vector<std::string> const &getRequiredValues() const;\r
\r
/**\r
- * This method is for getting AdditionalItems from Properties.\r
- *\r
- * @return AdditionalItems as bool\r
- */\r
- bool getAdditionalItems()\r
- {\r
- return m_additionalItems;\r
- }\r
+ * This method is for setting RequiredValue to Properties\r
+ *\r
+ * @param reqValue - RequiredValue as string.\r
+ */\r
+ void setRequiredValue(const std::string &reqValue);\r
+\r
private:\r
+ TypeInfo m_type;\r
+ std::string m_typeString;\r
std::string m_name;\r
- ValueVariant m_value;\r
- int m_min;\r
- int m_max;\r
- double m_doubleMin;\r
- double m_doubleMax;\r
- int m_multipleOf;\r
- AllowedValues m_allowedValues;\r
- std::string m_type;\r
- std::string m_pattern;\r
- std::string m_format;\r
std::string m_description;\r
- bool m_unique;\r
- bool m_additionalItems;\r
- std::vector<ItemsPtr > m_items;\r
+ std::shared_ptr<ValueVariant> m_value;\r
+ std::vector<std::shared_ptr<ValueProperty> > m_valueProperty;\r
+ std::vector<std::string> m_required;\r
};\r
\r
/** PropertiesPtr - shared Ptr to Properties.*/\r
typedef std::shared_ptr<Properties> PropertiesPtr;\r
\r
+ /** ValuePropertyPtr - shared Ptr to ValueProperty.*/\r
+ typedef std::shared_ptr<ValueProperty> ValuePropertyPtr;\r
+\r
}\r
#endif\r