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