Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
JsonPatch.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 * JsonPatch.h
17 * Implementation of RFC 6902.
18 * Copyright (C) 2014 Simon Newton
19 */
20
29#ifndef INCLUDE_OLA_WEB_JSONPATCH_H_
30#define INCLUDE_OLA_WEB_JSONPATCH_H_
31
32#include <ola/base/Macro.h>
33#include <ola/web/Json.h>
34#include <ola/web/JsonPointer.h>
35#include <memory>
36#include <string>
37#include <vector>
38
39namespace ola {
40namespace web {
41
47class JsonPatchSet;
48
53 public:
54 virtual ~JsonPatchOp() {}
55
62 virtual bool Apply(JsonValue **value) const = 0;
63};
64
69 public:
75 JsonPatchAddOp(const JsonPointer &path, const JsonValue *value)
76 : m_pointer(path),
77 m_value(value) {
78 }
79
80 bool Apply(JsonValue **value) const;
81
82 private:
83 JsonPointer m_pointer;
84 std::auto_ptr<const JsonValue> m_value;
85
86 JsonPatchAddOp(const JsonPatchAddOp &) = delete;
87 const JsonPatchAddOp &operator=(const JsonPatchAddOp &) = delete;
88};
89
94 public:
99 explicit JsonPatchRemoveOp(const JsonPointer &path)
100 : m_pointer(path) {
101 }
102
103 bool Apply(JsonValue **value) const;
104
105 private:
106 const JsonPointer m_pointer;
107
108 JsonPatchRemoveOp(const JsonPatchRemoveOp &) = delete;
109 const JsonPatchRemoveOp &operator=(const JsonPatchRemoveOp &) = delete;
110};
111
116 public:
122 JsonPatchReplaceOp(const JsonPointer &path, const JsonValue *value)
123 : m_pointer(path),
124 m_value(value) {
125 }
126
127 bool Apply(JsonValue **value) const;
128
129 private:
130 const JsonPointer m_pointer;
131 std::auto_ptr<const JsonValue> m_value;
132
133 JsonPatchReplaceOp(const JsonPatchReplaceOp &) = delete;
134 const JsonPatchReplaceOp &operator=(const JsonPatchReplaceOp &) = delete;
135};
136
141 public:
148 : m_from(from),
149 m_to(to) {
150 }
151
152 bool Apply(JsonValue **value) const;
153
154 private:
155 JsonPointer m_from;
156 JsonPointer m_to;
157
158 JsonPatchMoveOp(const JsonPatchMoveOp &) = delete;
159 const JsonPatchMoveOp &operator=(const JsonPatchMoveOp &) = delete;
160};
161
166 public:
173 : m_from(from),
174 m_to(to) {
175 }
176
177 bool Apply(JsonValue **value) const;
178
179 private:
180 JsonPointer m_from;
181 JsonPointer m_to;
182
183 JsonPatchCopyOp(const JsonPatchCopyOp &) = delete;
184 const JsonPatchCopyOp &operator=(const JsonPatchCopyOp &) = delete;
185};
186
191 public:
192 JsonPatchTestOp(const JsonPointer &path, const JsonValue *value)
193 : m_pointer(path),
194 m_value(value) {
195 }
196
197 bool Apply(JsonValue **value) const;
198
199 private:
200 JsonPointer m_pointer;
201 std::auto_ptr<const JsonValue> m_value;
202
203 JsonPatchTestOp(const JsonPatchTestOp &) = delete;
204 const JsonPatchTestOp &operator=(const JsonPatchTestOp &) = delete;
205};
206
207
212 public:
213 JsonPatchSet() {}
215
220 void AddOp(JsonPatchOp *op);
221
227 bool Apply(JsonValue **value) const;
228
229 bool Empty() const { return m_patch_ops.empty(); }
230
231 private:
232 typedef std::vector<JsonPatchOp*> PatchOps;
233
234 PatchOps m_patch_ops;
235};
237} // namespace web
238} // namespace ola
239#endif // INCLUDE_OLA_WEB_JSONPATCH_H_
Basic data types used to represent elements in a JSON document.
An implementation of Json Pointers (RFC 6901).
Helper macros.
Add a JsonValue.
Definition JsonPatch.h:68
JsonPatchAddOp(const JsonPointer &path, const JsonValue *value)
Add the JsonValue to the specified path.
Definition JsonPatch.h:75
bool Apply(JsonValue **value) const
Apply the patch operation to the value.
Definition JsonPatch.cpp:189
Copy a value from one location to another.
Definition JsonPatch.h:165
bool Apply(JsonValue **value) const
Apply the patch operation to the value.
Definition JsonPatch.cpp:273
JsonPatchCopyOp(const JsonPointer &from, const JsonPointer &to)
Copy a value from one location to another.
Definition JsonPatch.h:172
Move a value from one location to another.
Definition JsonPatch.h:140
bool Apply(JsonValue **value) const
Apply the patch operation to the value.
Definition JsonPatch.cpp:232
JsonPatchMoveOp(const JsonPointer &from, const JsonPointer &to)
Move a value from one location to another.
Definition JsonPatch.h:147
A class to serialize a JSONValue to text.
Definition JsonPatch.h:52
virtual bool Apply(JsonValue **value) const =0
Apply the patch operation to the value.
Remove the value at the specified path.
Definition JsonPatch.h:93
bool Apply(JsonValue **value) const
Apply the patch operation to the value.
Definition JsonPatch.cpp:193
JsonPatchRemoveOp(const JsonPointer &path)
Add the JsonValue to the specified path.
Definition JsonPatch.h:99
Replace the value at the specified path.
Definition JsonPatch.h:115
JsonPatchReplaceOp(const JsonPointer &path, const JsonValue *value)
Replace the JsonValue at the specified path.
Definition JsonPatch.h:122
bool Apply(JsonValue **value) const
Apply the patch operation to the value.
Definition JsonPatch.cpp:212
An ordered collection of JsonPatchOps.
Definition JsonPatch.h:211
void AddOp(JsonPatchOp *op)
Add a patch operation to the set.
Definition JsonPatch.cpp:321
bool Apply(JsonValue **value) const
Apply this patch set to a value.
Definition JsonPatch.cpp:325
Test a path matches the specified value.
Definition JsonPatch.h:190
bool Apply(JsonValue **value) const
Apply the patch operation to the value.
Definition JsonPatch.cpp:301
A JSON pointer (RFC 6901) refers to a possible element in a JSON data structure.
Definition JsonPointer.h:66
The base class for JSON values.
Definition Json.h:119
The namespace containing all OLA symbols.
Definition Credentials.cpp:44