Merge branch 'master' into easysetup
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / IncludeResolver.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   IncludeResolver.h\r
23  *\r
24  * @brief   This file provides APIs for resolving included files.\r
25  */\r
26 \r
27 #ifndef INCLUDE_RESOLVER_H\r
28 #define INCLUDE_RESOLVER_H\r
29 \r
30 #include "yaml-cpp/yaml.h"\r
31 #include "cJSON.h"\r
32 #include "RamlUtils.h"\r
33 #include <fstream>\r
34 #include "yaml-cpp/exceptions.h"\r
35 #include "RamlExceptions.h"\r
36 \r
37 namespace RAML\r
38 {\r
39     /**\r
40      * @class   IncludeResolver\r
41      * @brief   This class provides a set of APIs for resolving included files.\r
42      */\r
43     class IncludeResolver\r
44     {\r
45         public:\r
46             /** FileType - enumeration for Included File types*/\r
47             enum class FileType\r
48             {\r
49                 NODE, JSON, FILE, NOTAG , ERROR\r
50             };\r
51 \r
52         public:\r
53             /**\r
54                  * This method is for reading a file specified in YamlNode and parse it to\r
55                  * getting the created RootNode from RAML file.\r
56                  *\r
57                  * @param yamlFile - Reference to YamlNode specifying the FileName.\r
58                  *\r
59                  * @return pointer to root node from the Parsed file.\r
60                  */\r
61             YAML::Node readToYamlNode(const YAML::Node &yamlFile );\r
62 \r
63             /**\r
64                  * This method is for reading a file specified in YamlNode and parse the specified Json file.\r
65                  *\r
66                  * @param jsonFile - Reference to YamlNode specifying the FileName.\r
67                  *\r
68                  * @return cJSON pointer to CJson object.\r
69                  */\r
70             cJSON *readToJson(const YAML::Node &jsonFile );\r
71 \r
72             /**\r
73                  * This method is for reading a file specified in YamlNode and parse the content of file.\r
74                  *\r
75                  * @param file - Reference to YamlNode specifying the FileName.\r
76                  *\r
77                  * @return contents of the file.\r
78                  */\r
79             std::string readFromFile(const YAML::Node &file );\r
80 \r
81             /**\r
82                  * This method is checking the file type specified in YamlNode.\r
83                  *\r
84                  * @param yamlNode - Reference to YamlNode specifying the FileName.\r
85                  *\r
86                  * @return FileType type of file.\r
87                  */\r
88             FileType getFileType(const YAML::Node &yamlNode );\r
89 \r
90             /**\r
91                  * This method is for reading a file specified and parse the content of file.\r
92                  *\r
93                  * @param jsonFileName - FileName of Json file to be read.\r
94                  *\r
95                  * @return pointer to CJson object.\r
96                  */\r
97             cJSON *readToJson(const std::string &jsonFileName);\r
98 \r
99             /**\r
100                   * Constructor of IncludeResolver.\r
101                   */\r
102             IncludeResolver() {}\r
103 \r
104             /**\r
105                   * Constructor of IncludeResolver.\r
106                   *\r
107                   * @param path -  configuration file path.\r
108                   *\r
109                   */\r
110             IncludeResolver(const std::string &path) : m_path(path) {}\r
111 \r
112         private:\r
113             std::string m_path;\r
114     };\r
115 \r
116     /** IncludeResolverPtr - shared Ptr to IncludeResolver.*/\r
117     typedef std::shared_ptr<IncludeResolver> IncludeResolverPtr;\r
118 \r
119 }\r
120 #endif\r