Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsonData.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * JsonData.h
17  * The top level container for JSON data.
18  * Copyright (C) 2014 Simon Newton
19  */
20 
29 #ifndef INCLUDE_OLA_WEB_JSONDATA_H_
30 #define INCLUDE_OLA_WEB_JSONDATA_H_
31 
32 #include <ola/base/Macro.h>
33 #include <ola/web/Json.h>
34 #include <ola/web/JsonPatch.h>
35 #include <ola/web/JsonSchema.h>
36 #include <memory>
37 #include <string>
38 
39 namespace ola {
40 namespace web {
41 
57 class JsonData {
58  public:
65  JsonData(const JsonValue *value,
66  ValidatorInterface *schema = NULL)
67  : m_value(value),
68  m_schema(schema) {
69  }
70 
76  const JsonValue* Value() const { return m_value.get(); }
77 
82  bool SetValue(JsonValue *value);
83 
89  bool Apply(const JsonPatchSet &patch);
90 
94  const ValidatorInterface* GetSchema() const { return m_schema; }
95 
96  private:
97  std::auto_ptr<const JsonValue> m_value;
98  ValidatorInterface *m_schema;
99 
100  bool IsValid(const JsonValue *value);
101 };
102 
104 } // namespace web
105 } // namespace ola
106 #endif // INCLUDE_OLA_WEB_JSONDATA_H_