Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / jsonSchemaParser / Items.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   Items.h\r
23  *\r
24  * @brief   This file provides data Model for Json Schema Array Items.\r
25  */\r
26 \r
27 #ifndef ITEMS_H_\r
28 #define ITEMS_H_\r
29 \r
30 #include <string>\r
31 #include <vector>\r
32 #include <map>\r
33 #include "Properties.h"\r
34 #include "Helpers.h"\r
35 #include "AllowedValues.h"\r
36 #include <memory>\r
37 \r
38 namespace RAML\r
39 {\r
40     class Properties;\r
41     class AllowedValues;\r
42     /**\r
43      * @class   Items\r
44      * @brief   This class provides data Model for Json Schema Array Items.\r
45      */\r
46     class Items\r
47     {\r
48         public:\r
49             /**\r
50                   * Constructor of Items.\r
51                   */\r
52             Items() {}\r
53 \r
54             /**\r
55                  * This method is for setting Properties to Items\r
56                  *\r
57                  * @param propName - Properties name as string.\r
58                  * @param property - pointer to Properties.\r
59                  */\r
60             void addProperty(const std::string &propName, const std::shared_ptr<Properties> &property)\r
61             {\r
62                 if (m_properties.end() == m_properties.find(propName))\r
63                 {\r
64                     m_properties[propName] =  property;\r
65                 }\r
66             }\r
67 \r
68             /**\r
69                  * This method is for getting Properties from Items.\r
70                  *\r
71                  * @param propName - Properties name as string.\r
72                  *\r
73                  * @return  pointer to Properties to put the value got\r
74                  */\r
75             std::shared_ptr<Properties> getproperty(const std::string &propName)\r
76             {\r
77                 if (m_properties.end() != m_properties.find(propName))\r
78                 {\r
79                     return m_properties[propName];\r
80                 }\r
81                 return nullptr;\r
82             }\r
83 \r
84             /**\r
85                  * This method is for getting Properties from Items.\r
86                  *\r
87                  * @return map of Properties name as string and pointer to Properties\r
88                  */\r
89             std::map<std::string, std::shared_ptr<Properties> > const &getProperties()\r
90             {\r
91                 return m_properties;\r
92             }\r
93 \r
94             /**\r
95                  * This method is for setting Type to Items\r
96                  *\r
97                  * @param type - Type as string.\r
98                  */\r
99             void setType(const std::string &type)\r
100             {\r
101                 m_type = type;\r
102             }\r
103 \r
104             /**\r
105                  * This method is for getting Type from Items.\r
106                  *\r
107                  * @return Type as string\r
108                  */\r
109             std::string getType()\r
110             {\r
111                 return m_type;\r
112             }\r
113 \r
114             /**\r
115                  * This method is for setting RequiredValue to Items\r
116                  *\r
117                  * @param reqValue - RequiredValue as string.\r
118                  */\r
119             void setRequiredValue(const std::string &reqValue)\r
120             {\r
121                 auto it = m_required.begin();\r
122                 for (; it != m_required.end(); ++it)\r
123                 {\r
124                     if (*it == reqValue)\r
125                         break;\r
126                 }\r
127                 if (m_required.end() == it)\r
128                 {\r
129                     m_required.push_back(reqValue);\r
130                 }\r
131             }\r
132 \r
133             /**\r
134                  * This method is for getting RequiredValue from Items.\r
135                  *\r
136                  * @return list of RequiredValue as string\r
137                  */\r
138             std::vector<std::string> const &getRequiredValues()\r
139             {\r
140                 return m_required;\r
141             }\r
142 \r
143             /**\r
144                  * This method is for setting AllowedValues to Items\r
145                  *\r
146                  * @param values -list of AllowedValues.\r
147                  */\r
148             template <typename T>\r
149             bool setAllowedValues(const std::vector<T> &values)\r
150             {\r
151                 m_allowedValues.addValues(values);\r
152                 return true;\r
153             }\r
154 \r
155             /**\r
156                  * This method is for getting size of AllowedValues from Items.\r
157                  *\r
158                  * @return size of AllowedValues\r
159                  */\r
160             inline int getAllowedValuesSize() const\r
161             {\r
162                 return m_allowedValues.size();\r
163             }\r
164 \r
165             /**\r
166                  * This method is for getting AllowedValues from Items.\r
167                  *\r
168                  * @return list of AllowedValues\r
169                  */\r
170             inline std::vector<ValueVariant> getAllowedValues()\r
171             {\r
172                 return m_allowedValues.getValues();\r
173             }\r
174 \r
175             /**\r
176                  * This method is for getting AllowedValues as Integer from Items.\r
177                  *\r
178                  * @return list of AllowedValues as Integer\r
179                  */\r
180             inline std::vector<int> getAllowedValuesInt()\r
181             {\r
182                 return m_allowedValues.getValuesInt();\r
183             }\r
184 \r
185             /**\r
186                  * This method is for getting AllowedValues as String from Items.\r
187                  *\r
188                  * @return list of AllowedValues as String\r
189                  */\r
190             inline std::vector<std::string> getAllowedValuesString()\r
191             {\r
192                 return m_allowedValues.getValuesString();\r
193             }\r
194         private:\r
195             std::map<std::string, std::shared_ptr<Properties> > m_properties;\r
196             std::string m_type;\r
197             std::vector<std::string>  m_required;\r
198             AllowedValues m_allowedValues;\r
199     };\r
200 \r
201     /** ItemsPtr - shared Ptr to Items.*/\r
202     typedef std::shared_ptr<Items> ItemsPtr;\r
203 }\r
204 #endif\r
205 \r