Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / jsonSchemaParser / Definitions.h
1 /******************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\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
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
18  *\r
19  ******************************************************************/\r
20 \r
21 /**\r
22  * @file   Definitions.h\r
23  *\r
24  * @brief   This file provides data Model for Json Schema Definitions.\r
25  */\r
26 \r
27 #ifndef DEFINITIONS_H_\r
28 #define DEFINITIONS_H_\r
29 \r
30 #include <string>\r
31 #include <vector>\r
32 #include <map>\r
33 #include "Properties.h"\r
34 #include <memory>\r
35 \r
36 namespace RAML\r
37 {\r
38     /**\r
39      * @class   Definitions\r
40      * @brief   This class provides data Model for Json Schema Definitions.\r
41      */\r
42     class Definitions\r
43     {\r
44         public:\r
45 \r
46             /**\r
47                   * Constructor of Definitions.\r
48                   */\r
49             Definitions() = default;\r
50 \r
51             /**\r
52                   * Constructor of Definitions.\r
53                   *\r
54                   * @param name - Definitions name as string.\r
55                   */\r
56             Definitions(const std::string &name) : m_defName(name) {}\r
57 \r
58             /**\r
59                  * This method is for getting Name from Definitions.\r
60                  *\r
61                  * @return Definitions name as string\r
62                  */\r
63             inline std::string getName(void) const\r
64             {\r
65                 return m_defName;\r
66             }\r
67 \r
68             /**\r
69                  * This method is for setting name to Definitions\r
70                  *\r
71                  * @param name - Definitions name as string.\r
72                  */\r
73             inline void setName(const std::string &name)\r
74             {\r
75                 m_defName = name;\r
76             }\r
77 \r
78             /**\r
79                  * This method is for getting Type from Definitions.\r
80                  *\r
81                  * @return Definitions Type as string\r
82                  */\r
83             inline std::string getType(void) const\r
84             {\r
85                 return m_type;\r
86             }\r
87 \r
88             /**\r
89                  * This method is for setting Type to Definitions\r
90                  *\r
91                  * @param type - Definitions Type as string.\r
92                  */\r
93             inline void setType(const std::string &type)\r
94             {\r
95                 m_type = type;\r
96             }\r
97 \r
98             /**\r
99                  * This method is for getting RequiredValue from Definitions.\r
100                  *\r
101                  * @return list of RequiredValue as string\r
102                  */\r
103             std::vector<std::string> const &getRequiredValues() const\r
104             {\r
105                 return m_required;\r
106             }\r
107 \r
108             /**\r
109                  * This method is for setting RequiredValue to Definitions\r
110                  *\r
111                  * @param reqValue - RequiredValue as string.\r
112                  */\r
113             void setRequiredValue(const std::string &reqValue)\r
114             {\r
115                 auto it = m_required.begin();\r
116                 for (; it != m_required.end(); ++it)\r
117                 {\r
118                     if (*it == reqValue)\r
119                         break;\r
120                 }\r
121                 if (m_required.end() == it)\r
122                 {\r
123                     m_required.push_back(reqValue);\r
124                 }\r
125             }\r
126 \r
127             /**\r
128                  * This method is for getting size of Properties from Definitions.\r
129                  *\r
130                  * @return size of Properties map\r
131                  */\r
132             int propertiesSize() const { return m_properties.size(); }\r
133 \r
134             /**\r
135                  * This method is for getting Properties from Definitions.\r
136                  *\r
137                  * @param propName - name of property as string.\r
138                  *\r
139                  * @return pointer to Properties.\r
140                  */\r
141             inline PropertiesPtr getproperty(const std::string &propName )\r
142             {\r
143                 if (m_properties.end() != m_properties.find(propName))\r
144                 {\r
145                     return m_properties[propName];\r
146                 }\r
147                 return nullptr;\r
148             }\r
149 \r
150             /**\r
151                  * This method is for getting Properties from Definitions.\r
152                  *\r
153                  * @return map of Property name and pointer to Properties\r
154                  */\r
155             inline std::map<std::string, PropertiesPtr> const  &getProperties()\r
156             {\r
157                 return m_properties;\r
158             }\r
159 \r
160             /**\r
161                  * This method is for setting Properties to Definitions\r
162                  *\r
163                  * @param propName - Definitions Type as string.\r
164                  * @param property - pointer to Properties.\r
165                  */\r
166             void addProperty(const std::string &propName, const PropertiesPtr &property)\r
167             {\r
168                 if (m_properties.end() == m_properties.find(propName))\r
169                 {\r
170                     m_properties[propName] =  property;\r
171                 }\r
172             }\r
173         private:\r
174             std::map<std::string, PropertiesPtr > m_properties;\r
175             std::string m_defName;\r
176             std::string m_type;\r
177             std::vector<std::string> m_required;\r
178 \r
179     };\r
180 \r
181     /** DefinitionsPtr - shared Ptr to Definitions.*/\r
182     typedef std::shared_ptr<Definitions> DefinitionsPtr;\r
183 \r
184 }\r
185 #endif\r