Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / Utils.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   Utils.h\r
23  *\r
24  * @brief   This file provides utilities for RamlParser.\r
25  */\r
26 \r
27 #ifndef UTILS_H\r
28 #define UTILS_H\r
29 \r
30 #include "yaml-cpp/yaml.h"\r
31 #include "ActionType.h"\r
32 \r
33 namespace RAML\r
34 {\r
35     namespace Keys\r
36     {\r
37         /** Title - Raml title key.*/\r
38         const std::string Title = "title";\r
39         /** Version - Raml Version key.*/\r
40         const std::string Version = "version";\r
41         /** BaseUri - Raml BaseUri key.*/\r
42         const std::string BaseUri = "baseUri";\r
43         /** Protocols - Raml Protocols key.*/\r
44         const std::string Protocols = "protocols";\r
45         /** MediaType - Raml MediaType key.*/\r
46         const std::string MediaType = "mediaType";\r
47         /** Schemas - Raml Schemas key.*/\r
48         const std::string Schemas = "schemas";\r
49         /** ResourceTypes - Raml ResourceTypes key.*/\r
50         const std::string ResourceTypes = "resourceTypes";\r
51         /** Traits - Raml Traits key.*/\r
52         const std::string Traits = "traits";\r
53         /** IsTrait - Raml is key.*/\r
54         const std::string IsTrait = "is";\r
55 \r
56         /** Resource - Raml Resource key.*/\r
57         const std::string Resource = "/";\r
58         /** ActionType - Raml allowed ActionType key.*/\r
59         const std::vector<std::string> ActionType = {"get", "post", "put", "delete",\r
60                                                      "head", "patch", "options", "trace"\r
61                                                     };\r
62 \r
63         /** Responses - Raml Responses key.*/\r
64         const std::string Responses = "responses";\r
65         /** Body - Raml Body key.*/\r
66         const std::string Body = "body";\r
67         /** Schema - Raml Schema key.*/\r
68         const std::string Schema = "schema";\r
69         /** Example - Raml Example key.*/\r
70         const std::string Example = "example";\r
71 \r
72         /** BaseUriParameters - Raml BaseUriParameters key.*/\r
73         const std::string BaseUriParameters = "baseUriParameters";\r
74         /** UriParameters - Raml UriParameters key.*/\r
75         const std::string UriParameters = "uriParameters";\r
76         /** Headers - Raml title Headers.*/\r
77         const std::string Headers = "headers";\r
78         /** QueryParameters - Raml QueryParameters key.*/\r
79         const std::string QueryParameters = "queryParameters";\r
80         /** FormParameters - Raml FormParameters key.*/\r
81         const std::string FormParameters = "formParameters";\r
82         /** DisplayName - Raml DisplayName key.*/\r
83         const std::string DisplayName = "displayName";\r
84         /** Description - Raml Description key.*/\r
85         const std::string Description = "description";\r
86         /** Type - Raml Type key.*/\r
87         const std::string Type = "type";\r
88         /** Enum - Raml Enum key.*/\r
89         const std::string Enum = "enum";\r
90         /** Pattern - Raml Pattern key.*/\r
91         const std::string Pattern = "pattern";\r
92         /** MinLength - Raml MinLength key.*/\r
93         const std::string MinLength = "minLength";\r
94         /** MaxLength - Raml MaxLength key.*/\r
95         const std::string MaxLength = "maxLength";\r
96         /** Minimum - Raml Minimum key.*/\r
97         const std::string Minimum = "minimum";\r
98         /** Maximum - Raml Maximum key.*/\r
99         const std::string Maximum = "maximum";\r
100         /** Repeat - Raml Repeat key.*/\r
101         const std::string Repeat = "repeat";\r
102         /** Required - Raml Required key.*/\r
103         const std::string Required = "required";\r
104         /** Default - Raml Default key.*/\r
105         const std::string Default = "default";\r
106         /** Title - Raml title key.*/\r
107 \r
108         /** Documentation - Raml Documentation key.*/\r
109         const std::string Documentation = "documentation";\r
110         /** Content - Raml Content key.*/\r
111         const std::string Content = "content";\r
112 \r
113         /** Json - Raml Json key.*/\r
114         const std::string Json = "json";\r
115         /** AllowedRamlYamlTypes - Raml AllowedRamlYamlTypes key.*/\r
116         const std::vector<std::string> AllowedRamlYamlTypes = {"raml", "yaml", "yml"};\r
117 \r
118     }\r
119 \r
120     /**\r
121     * This macro is reading yamlNode as String.\r
122     *\r
123     * @param yamlNode - reference to yamlNode\r
124     *\r
125     * @return value as string\r
126     */\r
127 \r
128 #define READ_NODE_AS_STRING(yamlNode)                   \\r
129 ({                                                      \\r
130 (yamlNode).as<std::string>();                           \\r
131 })\r
132 \r
133     /**\r
134     * This macro is reading yamlNode as int.\r
135     *\r
136     * @param yamlNode - reference to yamlNode\r
137     *\r
138     * @return value as int\r
139     */\r
140 #define READ_NODE_AS_INT(yamlNode)                      \\r
141 ({                                                      \\r
142     (yamlNode).as<int>();                               \\r
143 })\r
144 \r
145     /**\r
146     * This macro is reading yamlNode as long.\r
147     *\r
148     * @param yamlNode - reference to yamlNode\r
149     *\r
150     * @return value as long\r
151     */\r
152 #define READ_NODE_AS_LONG(yamlNode)                     \\r
153 ({                                                      \\r
154     (yamlNode).as<long>();                              \\r
155 })\r
156     /**\r
157      * This macro is reading yamlNode as bool.\r
158      *\r
159      * @param yamlNode - reference to yamlNode\r
160      *\r
161      * @return value as bool\r
162       */\r
163 #define READ_NODE_AS_BOOL(yamlNode)                     \\r
164 ({                                                      \\r
165         (yamlNode).as<bool>();                          \\r
166 })\r
167     /**\r
168     * This macro is getting ActionType\r
169     *\r
170     * @param key - string\r
171     *\r
172     * @return ActionType\r
173     */\r
174 \r
175 #define GET_ACTION_TYPE(key)                            \\r
176 ({                                                      \\r
177     ActionType actionType = ActionType::GET;            \\r
178     if (key == "get" )                                  \\r
179         actionType = ActionType::GET;                   \\r
180     else if (key == "post" )                            \\r
181         actionType = ActionType::POST;                  \\r
182     else if (key == "put" )                             \\r
183         actionType = ActionType::PUT;                   \\r
184     else if (key == "delete" )                          \\r
185         actionType = ActionType::DELETE;                \\r
186     else if (key == "head" )                            \\r
187         actionType = ActionType::HEAD;                  \\r
188     else if (key == "patch" )                           \\r
189         actionType = ActionType::PATCH;                 \\r
190     else if (key == "options" )                         \\r
191         actionType = ActionType::OPTIONS;               \\r
192     else if (key == "trace" )                           \\r
193         actionType = ActionType::TRACE;                 \\r
194     actionType;                                         \\r
195 })\r
196 \r
197 }\r
198 #endif\r