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()) {}
48  JsonPatchBuilder& assign(JsonPatchBuilder& rhs, move_tag) NLIB_NOEXCEPT { // NOLINT
49  oplist_.assign(rhs.oplist_, move_tag());
50  return *this;
51  }
53  return PathValueOp("add", path, value);
54  }
55  errno_t Remove(const nlib_utf8_t* path) NLIB_NOEXCEPT;
56  NLIB_ALWAYS_INLINE errno_t Replace(const nlib_utf8_t* path, MpObject* value) NLIB_NOEXCEPT {
57  return PathValueOp("replace", path, value);
58  }
60  const nlib_utf8_t* from) NLIB_NOEXCEPT {
61  return PathFromOp("move", path, from);
62  }
64  const nlib_utf8_t* from) NLIB_NOEXCEPT {
65  return PathFromOp("copy", path, from);
66  }
67  NLIB_ALWAYS_INLINE errno_t Test(const nlib_utf8_t* path, MpObject* value) NLIB_NOEXCEPT {
68  return PathValueOp("test", path, value);
69  }
70  errno_t Export(MpObject* patch) NLIB_NOEXCEPT;
71 #ifdef __cpp_rvalue_references
72  std::pair<errno_t, MpObject> Export() NLIB_NOEXCEPT {
73  std::pair<errno_t, MpObject> rval;
74  rval.first = Export(&rval.second);
75  return rval;
76  }
77 #endif
78  NLIB_DEPRECATED void swap(JsonPatchBuilder& rhs) NLIB_NOEXCEPT {
79  using std::swap;
80  swap(oplist_, rhs.oplist_);
81  }
82 
83  private:
84  errno_t ResolvePath(const nlib_utf8_t* path, MpObject* path_obj) NLIB_NOEXCEPT;
85  errno_t PathValueOp(const nlib_utf8_t* opstr,
86  const nlib_utf8_t* path, MpObject* path_obj) NLIB_NOEXCEPT;
87  errno_t PathFromOp(const nlib_utf8_t* opstr,
88  const nlib_utf8_t* path, const nlib_utf8_t* from) NLIB_NOEXCEPT;
89 
90  private:
91  MpObject oplist_;
93 };
94 
96  public:
97  static errno_t Apply(MpObject* obj, MpObject* patch, size_t* index) NLIB_NOEXCEPT;
98 
99  private:
101 };
102 
103 } // namespace msgpack
104 NLIB_NAMESPACE_END
105 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonPatchBuilder)
106 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
107 #undef NLIB_VIS_PUBLIC
108 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
109 #endif
110 
111 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONPATCH_H_
112 
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:97
#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:179
#define NLIB_DEPRECATED
Indicates that a function or something has been deprecated.
Definition: Config.h:109
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
Class to apply JSON Patch (RFC-6902).
Definition: JsonPatch.h:95
Object created when MessagePack or JSON is read.
Definition: MpObject.h:95
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:63
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:67
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:265
Object created when MessagePack, JSON, or CSV is read.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
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
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
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:59
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:308
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