nlib
JsonPatch.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONPATCH_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_JSONPATCH_H_
18 
19 #include <utility>
21 
22 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
23 #undef NLIB_VIS_PUBLIC
24 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
25 #endif
26 
27 NLIB_NAMESPACE_BEGIN
28 namespace msgpack {
29 
31  public:
34 #ifdef __cpp_rvalue_references
35 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
36  JsonPatchBuilder(JsonPatchBuilder&& rhs) = default;
37  JsonPatchBuilder& operator=(JsonPatchBuilder&& rhs) = default;
38 #else
39  JsonPatchBuilder(JsonPatchBuilder&& rhs) NLIB_NOEXCEPT : oplist_(std::move(rhs.oplist_)) {}
41  oplist_ = std::move(rhs.oplist_);
42  return *this;
43  }
44 #endif
45 #endif
47  : oplist_(rhs.oplist_, move_tag()) {}
49  oplist_.assign(rhs.oplist_, move_tag());
50  return *this;
51  }
53  return PathValueOp("add", path, value);
54  }
55 #ifdef __cpp_rvalue_references
57  return PathValueOp("add", path, &value);
58  }
59 #endif
60  errno_t Remove(const nlib_utf8_t* path) NLIB_NOEXCEPT;
62  return PathValueOp("replace", path, value);
63  }
64 #ifdef __cpp_rvalue_references
66  return PathValueOp("replace", path, &value);
67  }
68 #endif
70  const nlib_utf8_t* from) NLIB_NOEXCEPT {
71  return PathFromOp("move", path, from);
72  }
74  const nlib_utf8_t* from) NLIB_NOEXCEPT {
75  return PathFromOp("copy", path, from);
76  }
78  return PathValueOp("test", path, value);
79  }
80 #ifdef __cpp_rvalue_references
82  return PathValueOp("test", path, &value);
83  }
84 #endif
85  errno_t Export(MpObject* patch) NLIB_NOEXCEPT;
86 #ifdef __cpp_rvalue_references
87  std::pair<errno_t, std::unique_ptr<MpObject> > Export() NLIB_NOEXCEPT;
88 #endif
89 
90  private:
91  errno_t ResolvePath(const nlib_utf8_t* path, MpObject* path_obj) NLIB_NOEXCEPT;
92  errno_t PathValueOp(const nlib_utf8_t* opstr, const nlib_utf8_t* path,
93  MpObject* path_obj) NLIB_NOEXCEPT;
94  errno_t PathFromOp(const nlib_utf8_t* opstr, const nlib_utf8_t* path,
95  const nlib_utf8_t* from) NLIB_NOEXCEPT;
96 
97  private:
98  MpObject oplist_;
100 };
101 
103  public:
104  static errno_t Apply(MpObject* obj, MpObject* patch, size_t* index) NLIB_NOEXCEPT;
105 
106  private:
108 };
109 
110 } // namespace msgpack
111 NLIB_NAMESPACE_END
112 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonPatchBuilder)
113 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
114 #undef NLIB_VIS_PUBLIC
115 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
116 #endif
117 
118 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONPATCH_H_
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:95
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:183
errno_t Add(const nlib_utf8_t *path, MpObject &&value) noexcept
Adds an "add" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:56
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
Class to apply JSON Patch (RFC-6902).
Definition: JsonPatch.h:102
Object created when MessagePack or JSON is read.
Definition: MpObject.h:96
errno_t Copy(const nlib_utf8_t *path, const nlib_utf8_t *from) noexcept
Adds a "copy" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:73
errno_t Test(const nlib_utf8_t *path, MpObject *value) noexcept
Adds a "test" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:77
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:270
Object created when MessagePack, JSON, or CSV is read.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:109
errno_t Add(const nlib_utf8_t *path, MpObject *value) noexcept
Adds an "add" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:52
errno_t Test(const nlib_utf8_t *path, MpObject &&value) noexcept
Adds a "test" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:81
errno_t Replace(const nlib_utf8_t *path, MpObject &&value) noexcept
Adds an "replace" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:65
errno_t Replace(const nlib_utf8_t *path, MpObject *value) noexcept
Adds an "replace" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:61
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:250
errno_t Move(const nlib_utf8_t *path, const nlib_utf8_t *from) noexcept
Adds a "move" operation to the array that serves as the JSON Patch document.
Definition: JsonPatch.h:69
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:303
Class to create JSON Patch (RFC-6902).
Definition: JsonPatch.h:30
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37