replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / model / Schema.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   Schema.h\r
23  *\r
24  * @brief   This file provides data Model for RAML Schema.\r
25  */\r
26 \r
27 #ifndef SCHEMAS_H\r
28 #define SCHEMAS_H\r
29 \r
30 #include <string>\r
31 #if defined (__TIZENRT__)\r
32 #include <apps/netutils/cJSON.h>\r
33 #else\r
34 #include "cJSON.h"\r
35 #endif\r
36 #include "IncludeResolver.h"\r
37 \r
38 #include "JsonSchema.h"\r
39 \r
40 namespace RAML\r
41 {\r
42     /**\r
43      * @class   Schema\r
44      * @brief   This class provides data Model for RAML Schema.\r
45      */\r
46     class Schema\r
47     {\r
48         public:\r
49             /**\r
50              * This method is for getting CJson object of schema.\r
51              *\r
52              * @return pointer to cJSON.\r
53              */\r
54             virtual cJSON *getJson() const;\r
55 \r
56             /**\r
57              * This method is for setting schema as CJson object.\r
58              *\r
59              * @param cjson - Cjson pointer.\r
60              */\r
61             virtual void setJson(cJSON *cjson);\r
62 \r
63             /**\r
64              * This method is for getting schema as string.\r
65              *\r
66              * @return string.\r
67              */\r
68             virtual std::string getSchema() const;\r
69 \r
70             /**\r
71              * This method is for setting schema as string.\r
72              *\r
73              * @param schema - schema string.\r
74              */\r
75             virtual void setSchema(const std::string &schema);\r
76 \r
77             /**\r
78              * This method is for getting Properties from JsonSchema.\r
79              *\r
80              * @return pointer to JsonSchema.\r
81              */\r
82             virtual JsonSchemaPtr const &getProperties() const;\r
83 \r
84             /**\r
85              * Constructor of Schema.\r
86              *\r
87              * @param schema - contents of schema to be parsed\r
88              * @param includeResolver - Reference to IncludeResolver for reading external files\r
89              *\r
90              */\r
91             Schema(const std::string &schema, const IncludeResolverPtr &includeResolver):\r
92                 m_schema(schema) , m_cjson(cJSON_Parse(schema.c_str())),\r
93                 m_resProperties(std::make_shared<JsonSchema>(m_cjson, includeResolver) ) ,\r
94                 m_includeResolver(includeResolver) {}\r
95 \r
96             /**\r
97              * Constructor of Schema.\r
98              */\r
99             Schema(): m_cjson(NULL), m_resProperties(std::make_shared<JsonSchema>()),\r
100                 m_includeResolver(NULL) {}\r
101 \r
102             Schema(const Schema&) = delete;\r
103             Schema& operator=(const Schema&) = delete;\r
104             Schema(Schema&&) = delete;\r
105             Schema& operator=(Schema&&) = delete;\r
106 \r
107             /**\r
108              * Destructor of Schema.\r
109              */\r
110             ~Schema() { cJSON_Delete(m_cjson); }\r
111 \r
112         private:\r
113             std::string m_schema;\r
114             cJSON *m_cjson;\r
115             JsonSchemaPtr m_resProperties;\r
116             IncludeResolverPtr m_includeResolver;\r
117     };\r
118 \r
119     /** SchemaPtr - shared Ptr to Schema.*/\r
120     typedef std::shared_ptr<Schema> SchemaPtr;\r
121 \r
122 }\r
123 #endif\r