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