Open Lighting Architecture  Latest Git
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_
bool SetValue(JsonValue *value)
Set the value for this JsonData.
Definition: JsonData.cpp:31
The base class for JSON values.
Definition: Json.h:119
Represents a JSON text as defined in section 2 of RFC7158.
Definition: JsonData.h:57
bool Apply(const JsonPatchSet &patch)
Apply a set of JSON patches to the value.
Definition: JsonData.cpp:41
Implementation of JSON Patch (RFC 6902).
const JsonValue * Value() const
Return the JsonValue for this text.
Definition: JsonData.h:76
const ValidatorInterface * GetSchema() const
Return the schema for this JSON data.
Definition: JsonData.h:94
An ordered collection of JsonPatchOps.
Definition: JsonPatch.h:205
JsonData(const JsonValue *value, ValidatorInterface *schema=NULL)
Construct a new JsonData.
Definition: JsonData.h:65
Helper macros.
The interface Json Schema Validators.
Definition: JsonSchema.h:56
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
A Json Schema, see www.json-schema.org.
Basic data types used to represent elements in a JSON document.