Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / jsonSchemaParser / AllowedValues.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   AllowedValues.h\r
23  *\r
24  * @brief   This file provides data Model for Json Schema AllowedValues.\r
25  */\r
26 \r
27 #ifndef ALLOWED_VALUES_H_\r
28 #define ALLOWED_VALUES_H_\r
29 \r
30 #include <string>\r
31 #include <vector>\r
32 #include <map>\r
33 #include <boost/variant.hpp>\r
34 #include <boost/lexical_cast.hpp>\r
35 #include "Helpers.h"\r
36 \r
37 namespace RAML\r
38 {\r
39     /**\r
40      * @class   AllowedValues\r
41      * @brief   This class provides data Model for Json Schema AllowedValues.\r
42      */\r
43     class AllowedValues\r
44     {\r
45         public:\r
46             /**\r
47                  * This method is for setting AllowedValues\r
48                  *\r
49                  * @param value - Allowed Value to set.\r
50                  */\r
51             template <typename T>\r
52             void addValue(const T &value)\r
53             {\r
54                 ValueVariant temp = value;\r
55                 m_values.push_back(temp);\r
56             }\r
57 \r
58             /**\r
59                  * This method is for setting AllowedValues\r
60                  *\r
61                  * @param values - list of Allowed Values to set.\r
62                  */\r
63             template <typename T>\r
64             void addValues(const std::vector<T> &values)\r
65             {\r
66                 for (auto value : values)\r
67                 {\r
68                     ValueVariant vValue = value;\r
69                     m_values.push_back(vValue);\r
70                 }\r
71             }\r
72 \r
73             /**\r
74                  * This method is for getting AllowedValues\r
75                  *\r
76                  * @param index - Allowed Values at index to be fetched\r
77                  */\r
78             inline ValueVariant &at(int index)\r
79             {\r
80                 return m_values.at(index);\r
81             }\r
82 \r
83             /**\r
84                  * This method is for getting size of AllowedValues\r
85                  *\r
86                  * @return size of Allowed Values list\r
87                  */\r
88             inline int size() const\r
89             {\r
90                 return m_values.size();\r
91             }\r
92 \r
93             /**\r
94                  * This method is for getting AllowedValues.\r
95                  *\r
96                  * @return list of AllowedValues\r
97                  */\r
98             inline std::vector<ValueVariant> getValues()\r
99             {\r
100                 return m_values;\r
101             }\r
102 \r
103             /**\r
104                  * This method is for getting AllowedValues as integer.\r
105                  *\r
106                  * @return list of AllowedValues as integer.\r
107                  */\r
108             inline std::vector<int> getValuesInt()\r
109             {\r
110                 std::vector<int> values;\r
111                 for (auto value : m_values)\r
112                 {\r
113                     values.push_back(boost::lexical_cast<int> (value));\r
114                 }\r
115                 return values;\r
116             }\r
117 \r
118             /**\r
119                  * This method is for getting AllowedValues as string.\r
120                  *\r
121                  * @return list of AllowedValues as string.\r
122                  */\r
123             inline std::vector<std::string> getValuesString()\r
124             {\r
125                 std::vector<std::string> values;\r
126                 for (auto value : m_values)\r
127                 {\r
128                     values.push_back(boost::lexical_cast<std::string> (value));\r
129                 }\r
130                 return values;\r
131             }\r
132 \r
133             /**\r
134                  * This method is for getting AllowedValues as Double.\r
135                  *\r
136                  * @return list of AllowedValues as Double.\r
137                  */\r
138             inline std::vector<double> getValuesDouble()\r
139             {\r
140                 std::vector<double> values;\r
141                 for (auto value : m_values)\r
142                 {\r
143                     values.push_back(boost::lexical_cast<double> (value));\r
144                 }\r
145                 return values;\r
146             }\r
147 \r
148             /**\r
149                  * This method is for getting AllowedValues as Bool.\r
150                  *\r
151                  * @return list of AllowedValues as Bool.\r
152                  */\r
153             inline std::vector<bool> getValuesBool()\r
154             {\r
155                 std::vector<bool> values;\r
156                 for (auto value : m_values)\r
157                 {\r
158                     values.push_back(boost::lexical_cast<bool> (value));\r
159                 }\r
160                 return values;\r
161             }\r
162 \r
163         private:\r
164             std::vector<ValueVariant> m_values;\r
165     };\r
166 \r
167 }\r
168 #endif\r