nlib
MpObject.h
[詳解]
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_MPOBJECT_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_MPOBJECT_H_
18 
19 #include <map>
20 #include <utility>
21 #include <vector>
22 
23 #include "nn/nlib/Config.h"
24 #include "nn/nlib/Swap.h"
25 #include "nn/nlib/Cstring.h"
26 #include "nn/nlib/Nlist.h"
27 
28 #ifdef NLIB_CXX11_STDLIB_ARRAY
29 #include <array> // NOLINT
30 #endif
31 
32 #ifdef NLIB_CXX11_STDLIB_UNORDERED
33 #include <unordered_map> // NOLINT
34 #endif
35 
36 #ifdef NLIB_CXX11_STDLIB_TUPLE
37 #include <tuple> // NOLINT
38 #endif
39 
40 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
41 #undef NLIB_VIS_PUBLIC
42 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
43 #endif
44 
45 NLIB_NAMESPACE_BEGIN
46 namespace msgpack {
47 
48 class MpObject;
49 
50 template <class T>
51 errno_t Box(MpObject* obj, const T& v);
52 
53 template <class T>
54 errno_t Unbox(const MpObject* obj, T* v);
55 
56 struct nil {};
57 
58 template <class T>
59 inline bool operator==(const nil& lhs, const T& rhs) NLIB_NOEXCEPT {
60  NLIB_UNUSED(lhs);
61  NLIB_UNUSED(rhs);
62  return false;
63 }
64 template <class T>
65 inline bool operator==(const T& lhs, const nil& rhs) NLIB_NOEXCEPT {
66  NLIB_UNUSED(lhs);
67  NLIB_UNUSED(rhs);
68  return false;
69 }
70 inline bool operator==(const nil& lhs, const nil& rhs) NLIB_NOEXCEPT {
71  NLIB_UNUSED(lhs);
72  NLIB_UNUSED(rhs);
73  return true;
74 }
75 template <class T>
76 inline bool operator!=(const nil& rhs, const T& lhs) NLIB_NOEXCEPT {
77  NLIB_UNUSED(lhs);
78  NLIB_UNUSED(rhs);
79  return true;
80 }
81 template <class T>
82 inline bool operator!=(const T& rhs, const nil& lhs) NLIB_NOEXCEPT {
83  NLIB_UNUSED(lhs);
84  NLIB_UNUSED(rhs);
85  return true;
86 }
87 inline bool operator!=(const nil& rhs, const nil& lhs) NLIB_NOEXCEPT {
88  NLIB_UNUSED(lhs);
89  NLIB_UNUSED(rhs);
90  return false;
91 }
92 
93 struct MpObjectKv;
94 
96  private:
97  union UnionType {
98  uint64_t u64;
99  int64_t i64;
100  float f32;
101  double f64;
102  Nlist<MpObject>* ary;
103  Nlist<MpObjectKv>* mp;
104  nlib_utf8_t* str;
105  void* binary;
106  };
107 
108  public:
109  static errno_t ResolveJsonPointer(MpObject** result, MpObject* root,
110  const nlib_utf8_t* json_pointer) NLIB_NOEXCEPT;
111  static errno_t DigByJsonPointer(MpObject** result, MpObject* root,
112  const nlib_utf8_t* json_pointer) NLIB_NOEXCEPT;
113  static errno_t RemoveByJsonPointer(MpObjectKv* removed, MpObject* root,
114  const nlib_utf8_t* json_pointer) NLIB_NOEXCEPT;
115  MpObject* GetArrayItem(size_t n) NLIB_NOEXCEPT {
116  MpObject* obj;
117  return NLIB_LIKELY(0 == this->GetArrayItem(n, &obj)) ? obj : NULL;
118  }
119  const MpObject* GetArrayItem(size_t n) const NLIB_NOEXCEPT {
120  const MpObject* obj;
121  return NLIB_LIKELY(0 == this->GetArrayItem(n, &obj)) ? obj : NULL;
122  }
123  MpObject& operator[](size_t n) {
124  NLIB_ASSERT(this->IsArray());
125  NLIB_ASSERT(n < size_);
126  return (*via_.ary)[n];
127  }
128  const MpObject* GetMapItem(const nlib_utf8_t* str) const NLIB_NOEXCEPT;
129  MpObject* GetMapItem(const nlib_utf8_t* str) NLIB_NOEXCEPT;
130  template<size_t N>
131  MpObject* GetMapItem(const nlib_utf8_t (&str)[N]) NLIB_NOEXCEPT {
132  return GetMapItem(&str[0]);
133  }
134  template<size_t N>
135  const MpObject* GetMapItem(const nlib_utf8_t (&str)[N]) const NLIB_NOEXCEPT {
136  return GetMapItem(&str[0]);
137  }
138  template<class STDSTRING>
139  const MpObject* GetMapItem(const STDSTRING& str) const NLIB_NOEXCEPT {
140  return GetMapItem(&str[0], str.size());
141  }
142  template<class STDSTRING>
143  MpObject* GetMapItem(const STDSTRING& str) NLIB_NOEXCEPT {
144  return GetMapItem(&str[0], str.size());
145  }
146  errno_t Resize(uint32_t n);
147  MpObject* SwapArrayItem(size_t n, MpObject* obj) NLIB_NOEXCEPT {
148  MpObject* p = this->GetArrayItem(n);
149  if (NLIB_LIKELY(p)) p->swap(*obj);
150  return p;
151  }
152  template<class STDSTRING>
153  MpObject* SwapMapItem(const STDSTRING& key, MpObject* obj) NLIB_NOEXCEPT {
154  MpObject* p = this->GetMapItem(key);
155  if (NLIB_LIKELY(p)) p->swap(*obj);
156  return p;
157  }
158  template<size_t N>
159  MpObject* SwapMapItem(const nlib_utf8_t (&key)[N], MpObject* obj) NLIB_NOEXCEPT {
160  return SwapMapItem(&key[0], obj);
161  }
162  MpObject* SwapMapItem(const nlib_utf8_t* key, MpObject* obj) NLIB_NOEXCEPT {
163  MpObject* p = this->GetMapItem(key);
164  if (NLIB_LIKELY(p)) p->swap(*obj);
165  return p;
166  }
167  MpObject* AppendArrayItem() NLIB_NOEXCEPT;
168  MpObject* InsertArrayItem(size_t n) NLIB_NOEXCEPT;
169  MpObjectKv* AppendMapItem() NLIB_NOEXCEPT;
170  NLIB_OVERRIDE_NEW;
171 
172  public:
173  MpObject() NLIB_NOEXCEPT : type_(kNil) {} // only do minimum memory access
174  ~MpObject() NLIB_NOEXCEPT { ReleaseIfNeeded(); }
175  NLIB_MOVE_MEMBER_HELPER_1(MpObject, type_);
176 
177  // NOTE: implicit call was error in gcc or clang....
178  template <class T>
179  explicit MpObject(const T& x) {
180  MyBox<T, typename IsIntegral<T>::type, typename IsSigned<T>::type>::Construct(this, x);
181  }
182  errno_t GetArrayItem(size_t n, MpObject** obj) NLIB_NOEXCEPT NLIB_NONNULL;
183  errno_t GetArrayItem(size_t n, const MpObject** obj) const NLIB_NOEXCEPT NLIB_NONNULL;
184  errno_t GetMapItem(size_t n, MpObjectKv** obj) NLIB_NOEXCEPT NLIB_NONNULL;
185  errno_t GetMapItem(size_t n, const MpObjectKv** obj) const NLIB_NOEXCEPT NLIB_NONNULL;
186  errno_t GetMapItem(const nlib_utf8_t* str, size_t n,
187  MpObjectKv** obj) NLIB_NOEXCEPT NLIB_NONNULL {
188  const MpObjectKv* kv;
189  errno_t e = this->GetMapItem(str, n, &kv);
190  if (e != 0) return e;
191  *obj = const_cast<MpObjectKv*>(kv);
192  return 0;
193  }
194  errno_t GetMapItem(const nlib_utf8_t* str, size_t n,
195  const MpObjectKv** obj) const NLIB_NOEXCEPT NLIB_NONNULL;
196  nlib_utf8_t* GetString() NLIB_NOEXCEPT {
197  if (type_ == kString) return via_.str;
198  if (NLIB_LIKELY(type_ == kStringInline))
199  return reinterpret_cast<nlib_utf8_t*>(&raw14data_);
200  return NULL;
201  }
202  errno_t RemoveArrayItem(size_t n, MpObject* obj) NLIB_NOEXCEPT;
203  errno_t RemoveMapItem(size_t n, MpObjectKv* kv) NLIB_NOEXCEPT;
204  errno_t RemoveMapItem(const nlib_utf8_t* key, MpObjectKv* kv) NLIB_NOEXCEPT;
205  template<class STDSTRING>
206  errno_t RemoveMapItem(const STDSTRING& str, MpObjectKv* kv) NLIB_NOEXCEPT {
207  return RemoveMapItem(str.c_str(), kv);
208  }
209 
210  const nlib_utf8_t* GetString() const NLIB_NOEXCEPT {
211  return const_cast<MpObject*>(this)->GetString();
212  }
213  void* GetBinary(uint32_t* n) NLIB_NOEXCEPT {
214  if (type_ == kBinary) {
215  *n = size_;
216  return via_.binary;
217  }
218  if (NLIB_LIKELY(type_ == kBinaryInline)) {
219  *n = raw14size_;
220  return &raw14data_;
221  }
222  return NULL;
223  }
224  const void* GetBinary(uint32_t* n) const NLIB_NOEXCEPT {
225  return const_cast<MpObject*>(this)->GetBinary(n);
226  }
227  void* GetExt(int8_t* tp, uint32_t* n) NLIB_NOEXCEPT {
228  if (type_ == kExt) {
229  *n = size_;
230  *tp = static_cast<int8_t>(raw14data_);
231  return via_.binary;
232  } else {
233  return NULL;
234  }
235  }
236  const void* GetExt(int8_t* tp, uint32_t* n) const NLIB_NOEXCEPT {
237  return const_cast<MpObject*>(this)->GetExt(tp, n);
238  }
239 
240  errno_t InitArray(uint32_t n) NLIB_NOEXCEPT;
241  errno_t InitMap(uint32_t n) NLIB_NOEXCEPT;
242  errno_t InitString(uint32_t n) NLIB_NOEXCEPT;
243  errno_t InitString(const nlib_utf8_t* str, uint32_t n) NLIB_NOEXCEPT;
244  errno_t InitString(const nlib_utf8_t* str) NLIB_NOEXCEPT {
245  uint32_t n = static_cast<uint32_t>(nlib_strlen(str));
246  return InitString(str, n);
247  }
248  errno_t InitBinary(uint32_t n) NLIB_NOEXCEPT;
249  errno_t InitBinary(const void* p, uint32_t n) NLIB_NOEXCEPT;
250  errno_t InitExt(int8_t tp, uint32_t n) NLIB_NOEXCEPT;
251  errno_t InitExt(int8_t tp, const void* p, uint32_t n) NLIB_NOEXCEPT;
252 
253  public: // Box
254  errno_t Box(const nlib_utf8_t* str) NLIB_NOEXCEPT NLIB_NONNULL;
255  template <uint32_t n>
256  errno_t Box(const nlib_utf8_t (&str)[n]) NLIB_NOEXCEPT;
257  template <class T, uint32_t n>
258  errno_t Box(const T (&vec)[n]);
259 #ifdef NLIB_CXX11_STDLIB_ARRAY
260  template <class T, size_t n>
261  errno_t Box(const std::array<T, n>& vec);
262 #endif
263  template <class T>
264  errno_t Box(const T& v) {
265  return MyBox<T, typename IsIntegral<T>::type, typename IsSigned<T>::type>::Box(this, v);
266  }
267  // Use BoxBinary(p, n) or Box(reinterpret_cast<const nlib_utf8_t*>(p)) instead
268  errno_t BoxBinary(const void* p, uint32_t n) NLIB_NOEXCEPT NLIB_NONNULL;
269  errno_t BoxExt(int8_t tp, const void* p, uint32_t n) NLIB_NOEXCEPT NLIB_NONNULL;
270 
271  public: // Unbox
272  template <class T, size_t n>
273  errno_t Unbox(T (&a)[n]) const {
274  return this->Unbox(&a[0], n);
275  }
276 #ifdef NLIB_CXX11_STDLIB_ARRAY
277  template <class T, size_t n>
278  errno_t Unbox(std::array<T, n>& a) { // NOLINT
279  return this->Unbox(reinterpret_cast<T*>(&*a.begin()), n);
280  }
281 #endif
282  template <size_t n>
283  errno_t Unbox(nlib_utf8_t (&str)[n]) const NLIB_NOEXCEPT {
284  return this->Unbox(&str[0], n);
285  }
286  template <class T>
287  errno_t Unbox(T* a, size_t n) const NLIB_NONNULL;
288  errno_t Unbox(nlib_utf8_t* str, size_t n) const NLIB_NOEXCEPT NLIB_NONNULL;
289  errno_t UnboxBinary(void* p, size_t n) const NLIB_NOEXCEPT NLIB_NONNULL;
290  errno_t UnboxExt(int8_t* tp, void* p, size_t n) const NLIB_NOEXCEPT NLIB_NONNULL;
291  template <class T>
292  errno_t Unbox(T v) const {
293  // T cannot be T* though v is only pointer type
294  // because of conflict against array types.
295  return MyBox<typename RemovePtr<T>::type,
296  typename IsIntegral<typename RemovePtr<T>::type>::type,
297  typename IsSigned<typename RemovePtr<T>::type>::type>::Unbox(this, v);
298  }
299 
300  public:
301  // You can use operator=() only for basic types(never fails).
302  // Use Box() otherwise.
303  template <class T>
304  MpObject& operator=(const T& x) {
305  MyBox<T, typename IsIntegral<T>::type, typename IsSigned<T>::type>::Assign(this, x);
306  return *this;
307  }
308 
309  MpObject* Clone() NLIB_NOEXCEPT const;
310  void swap(MpObject& rhs) NLIB_NOEXCEPT { // NOLINT
311  using std::swap;
312  swap(type_, rhs.type_);
313  swap(raw14size_, rhs.raw14size_);
314  swap(raw14data_, rhs.raw14data_);
315  swap(_, rhs._);
316  swap(size_, rhs.size_);
317  swap(via_.u64, rhs.via_.u64);
318  }
319 
320  public:
321  enum ObjectType {
322  kNil = 0,
331  kBinary,
332  kExt,
333  kStringInline = 0x80 | kString,
334  kBinaryInline = 0x80 | kBinary,
335  kBooleanFalse = 0x00 | kBoolean,
336  kBooleanTrue = 0x80 | kBoolean,
337  NIL = kNil,
338  BOOLEAN = kBoolean,
339  UINT64 = kUint64,
340  INT64 = kInt64,
341  FLOAT = kFloat,
342  DOUBLE = kDouble,
343  STRING = kString,
344  ARRAY = kArray,
345  MAP = kMap,
346  BINARY = kBinary,
347  EXT = kExt,
348  RAW = STRING,
349  STRING_INLINE = kStringInline,
350  BINARY_INLINE = kBinaryInline,
351  RAW_INLINE = 0x80 | RAW,
352  BOOLEAN_FALSE = kBooleanFalse,
353  BOOLEAN_TRUE = kBooleanTrue
354  };
355  ObjectType GetType() const NLIB_NOEXCEPT {
356  return static_cast<ObjectType>(type_ & 0x7F);
357  }
358  uint32_t GetSize() const NLIB_NOEXCEPT {
359  if (type_ == kStringInline || type_ == kBinaryInline)
360  return raw14size_;
361  else
362  return size_;
363  }
364  bool IsNil() const NLIB_NOEXCEPT { return GetType() == kNil; }
365  bool IsBoolean() const NLIB_NOEXCEPT { return GetType() == kBoolean; }
366  bool IsInteger() const NLIB_NOEXCEPT {
367  ObjectType tp = GetType();
368  return tp == kUint64 || tp == kInt64;
369  }
370  bool IsFloat() const NLIB_NOEXCEPT { return GetType() == kFloat; }
371  bool IsDouble() const NLIB_NOEXCEPT { return GetType() == kDouble; }
372  bool IsString() const NLIB_NOEXCEPT { return GetType() == kString; }
373  bool IsBinary() const NLIB_NOEXCEPT { return GetType() == kBinary; }
374  bool IsExt() const NLIB_NOEXCEPT { return GetType() == kExt; }
375  bool IsArray() const NLIB_NOEXCEPT { return GetType() == kArray; }
376  bool IsMap() const NLIB_NOEXCEPT { return GetType() == kMap; }
377 
378  private:
379  errno_t Clone(MpObject* p) NLIB_NOEXCEPT const;
380  template <class T, class IS_INTEGRAL, class IS_SIGNED>
381  struct MyBox {
382  static errno_t Box(MpObject* This, const T& v) { return ::nlib_ns::msgpack::Box(This, v); }
383  static errno_t Unbox(const MpObject* This, T* v) {
384  if (!v) return EINVAL;
386  }
387  static void Assign(MpObject* This, const T& x);
388  static void Construct(MpObject* This, const T& x);
389  };
390  void ReleaseIfNeeded() NLIB_NOEXCEPT {
391  if (type_ >= kString && type_ <= kExt) ReleaseIfNeeded_();
392  }
393  void ReleaseIfNeeded_() NLIB_NOEXCEPT;
394 
395  private:
396  uint8_t type_;
397  uint8_t raw14size_;
398  uint8_t raw14data_;
399  uint8_t _;
400  uint32_t size_;
401  UnionType via_;
403  friend NLIB_VIS_PUBLIC bool operator==(const MpObject& lhs, const MpObject& rhs);
404 };
405 
406 struct MpObjectKv {
409 
410  public:
411  MpObjectKv() NLIB_NOEXCEPT {}
412  ~MpObjectKv() NLIB_NOEXCEPT {}
413  NLIB_MOVE_MEMBER_HELPER_2(MpObjectKv, first, second);
414  void swap(MpObjectKv& rhs) NLIB_NOEXCEPT { // NOLINT
415  first.swap(rhs.first);
416  second.swap(rhs.second);
417  }
418 
419  private:
421 };
422 
423 template <>
424 struct MpObject::MyBox<nil, FalseType, FalseType> {
425  static errno_t Box(MpObject* This, nil v) NLIB_NOEXCEPT {
426  NLIB_UNUSED(v);
427  This->ReleaseIfNeeded();
428  This->type_ = kNil;
429  return 0;
430  }
431  static void Assign(MpObject* This, nil x) NLIB_NOEXCEPT { This->Box(x); }
432  static void Construct(MpObject* This, nil) NLIB_NOEXCEPT { This->type_ = kNil; }
433 };
434 
435 template <>
436 struct MpObject::MyBox<bool, TrueType, FalseType> {
437  static errno_t Box(MpObject* This, bool v) NLIB_NOEXCEPT {
438  This->ReleaseIfNeeded();
439  This->type_ = v ? static_cast<uint8_t>(kBooleanTrue) : static_cast<uint8_t>(kBooleanFalse);
440  return 0;
441  }
442  static errno_t Unbox(const MpObject* This, bool* v) NLIB_NOEXCEPT {
443  if (This->type_ == kBooleanFalse) {
444  *v = false;
445  return 0;
446  } else if (NLIB_LIKELY(This->type_ == kBooleanTrue)) {
447  *v = true;
448  return 0;
449  }
450  *v = false; // to suppress warnings
451  return EACCES;
452  }
453  static void Assign(MpObject* This, bool x) NLIB_NOEXCEPT { This->Box(x); }
454  static void Construct(MpObject* This, bool x) NLIB_NOEXCEPT {
455  This->type_ = x ? static_cast<uint8_t>(kBooleanTrue) : static_cast<uint8_t>(kBooleanFalse);
456  }
457 };
458 
459 template <class T>
460 struct MpObject::MyBox<T, TrueType, TrueType> {
461  static errno_t Box(MpObject* This, T v) NLIB_NOEXCEPT {
462  This->ReleaseIfNeeded();
463  This->type_ = kInt64;
464  This->via_.i64 = v;
465  return 0;
466  }
467  static errno_t Unbox(const MpObject* This, T* v) NLIB_NOEXCEPT {
468  if (NLIB_UNLIKELY(!v)) return EINVAL;
469  if (This->type_ == kInt64) {
470  *v = static_cast<T>(This->via_.i64);
471  return 0;
472  } else if (NLIB_LIKELY(This->type_ == kUint64)) {
473  *v = static_cast<T>(This->via_.u64);
474  return 0;
475  }
476  *v = 0; // to suppress warnings
477  return EACCES;
478  }
479  static void Assign(MpObject* This, T x) NLIB_NOEXCEPT { This->Box(x); }
480  static void Construct(MpObject* This, T x) NLIB_NOEXCEPT {
481  This->type_ = kInt64;
482  This->via_.i64 = x;
483  }
484 };
485 
486 template <class T>
487 struct MpObject::MyBox<T, TrueType, FalseType> {
488  static errno_t Box(MpObject* This, T v) NLIB_NOEXCEPT {
489  This->ReleaseIfNeeded();
490  This->type_ = kUint64;
491  This->via_.u64 = v;
492  return 0;
493  }
494  static errno_t Unbox(const MpObject* This, T* v) NLIB_NOEXCEPT {
495  if (NLIB_UNLIKELY(!v)) return EINVAL;
496  if (This->type_ == kInt64) {
497  *v = static_cast<T>(This->via_.i64);
498  return 0;
499  } else if (NLIB_LIKELY(This->type_ == kUint64)) {
500  *v = static_cast<T>(This->via_.u64);
501  return 0;
502  }
503  *v = 0; // to suppress warnings
504  return EACCES;
505  }
506  static void Assign(MpObject* This, T x) NLIB_NOEXCEPT { This->Box(x); }
507  static void Construct(MpObject* This, T x) NLIB_NOEXCEPT {
508  This->type_ = kUint64;
509  This->via_.u64 = x;
510  }
511 };
512 
513 template <class TR1_WORKAROUND>
514 struct MpObject::MyBox<float, FalseType, TR1_WORKAROUND> {
515  static errno_t Box(MpObject* This, float v) NLIB_NOEXCEPT {
516  This->ReleaseIfNeeded();
517  This->type_ = kFloat;
518  This->via_.f32 = v;
519  return 0;
520  }
521  static errno_t Unbox(const MpObject* This, float* v) NLIB_NOEXCEPT {
522  if (NLIB_UNLIKELY(!v)) return EINVAL;
523  switch (This->type_) {
524  case kFloat:
525  *v = This->via_.f32;
526  break;
527  case kDouble:
528  *v = static_cast<float>(This->via_.f64);
529  break;
530  default:
531  *v = 0; // to suppress warnings
532  return EACCES;
533  }
534  return 0;
535  }
536  static void Assign(MpObject* This, float x) NLIB_NOEXCEPT { This->Box(x); }
537  static void Construct(MpObject* This, float x) NLIB_NOEXCEPT {
538  This->type_ = kFloat;
539  This->via_.f32 = x;
540  }
541 };
542 
543 template <class TR1_WORKAROUND>
544 struct MpObject::MyBox<double, FalseType, TR1_WORKAROUND> {
545  static errno_t Box(MpObject* This, double v) NLIB_NOEXCEPT {
546  This->ReleaseIfNeeded();
547  This->type_ = kDouble;
548  This->via_.f64 = v;
549  return 0;
550  }
551  static errno_t Unbox(const MpObject* This, double* v) NLIB_NOEXCEPT {
552  if (NLIB_UNLIKELY(!v)) return EINVAL;
553  switch (This->type_) {
554  case kFloat:
555  *v = This->via_.f32;
556  break;
557  case kDouble:
558  *v = This->via_.f64;
559  break;
560  default:
561  *v = 0; // to suppress warnings
562  return EACCES;
563  }
564  return 0;
565  }
566  static void Assign(MpObject* This, double x) NLIB_NOEXCEPT { This->Box(x); }
567  static void Construct(MpObject* This, double x) NLIB_NOEXCEPT {
568  This->type_ = kDouble;
569  This->via_.f64 = x;
570  }
571 };
572 
573 template <class STDSTRING>
574 struct MpObject::MyBox<STDSTRING, FalseType, FalseType> {
575  static errno_t Box(MpObject* This, const STDSTRING& str) NLIB_NOEXCEPT {
576  uint32_t n = static_cast<uint32_t>(str.size());
577  ErrnoT e = This->InitString(n);
578  if (NLIB_UNLIKELY(e != 0)) return e;
579  nlib_memcpy(reinterpret_cast<void*>(This->GetString()),
580  n,
581  reinterpret_cast<const void*>(&str[0]),
582  n);
583  return 0;
584  }
585  static errno_t Unbox(const MpObject* This, STDSTRING* str) NLIB_NOEXCEPT {
586  if (NLIB_UNLIKELY(!str)) return EINVAL;
587  if (NLIB_UNLIKELY(This->type_ != kString) && NLIB_UNLIKELY(This->type_ != kStringInline))
588  return EACCES;
589  const nlib_utf8_t* chr = This->GetString();
590  NLIB_TRY { (*str).assign(chr, This->GetSize()); }
591  NLIB_CATCH(std::bad_alloc&) { return ENOMEM; }
592  return 0;
593  }
594 };
595 
596 template <class T, class ALLOC>
597 struct MpObject::MyBox<std::vector<T, ALLOC>, FalseType, FalseType> {
598  static errno_t Box(MpObject* This, const std::vector<T, ALLOC>& vec) {
599  uint32_t n = static_cast<uint32_t>(vec.size());
600  MpObject tmp;
601  ErrnoT e = tmp.InitArray(n);
602  if (NLIB_UNLIKELY(e != 0)) return e;
603 
604  for (uint32_t i = 0; i < n; ++i) {
605  e = (*tmp.via_.ary)[i].Box(vec[i]);
606  if (NLIB_UNLIKELY(e != 0)) return e;
607  }
608  tmp.swap(*This);
609  return 0;
610  }
611  static errno_t Unbox(const MpObject* This, std::vector<T, ALLOC>* vec) {
612  if (NLIB_UNLIKELY(!vec)) return EINVAL;
613  if (NLIB_UNLIKELY(This->type_ != kArray)) return EACCES;
614  NLIB_TRY { vec->resize(This->size_); }
615  NLIB_CATCH(std::bad_alloc&) { return ENOMEM; }
616  for (uint32_t i = 0; i < This->size_; ++i) {
617  ErrnoT e = (*This->via_.ary)[i].Unbox(&(*vec)[i]);
618  if (NLIB_UNLIKELY(e != 0)) return e; // *vec NOT RESET
619  }
620  return 0;
621  }
622 };
623 
624 template <class T, class ALLOC>
625 struct MpObject::MyBox<Nlist<T, ALLOC>, FalseType, FalseType> {
626  static errno_t Box(MpObject* This, const Nlist<T, ALLOC>& vec) {
627  size_t n = vec.size();
628  MpObject tmp;
629  ErrnoT e = tmp.InitArray(static_cast<uint32_t>(n));
630  if (NLIB_UNLIKELY(e != 0)) return e;
631  typename Nlist<T, ALLOC>::const_iterator it = vec.begin();
632  for (size_t i = 0; i < n; ++it, ++i) {
633  e = (*tmp.via_.ary)[i].Box(*it);
634  if (NLIB_UNLIKELY(e != 0)) return e;
635  }
636  tmp.swap(*This);
637  return 0;
638  }
639  static errno_t Unbox(const MpObject* This, Nlist<T, ALLOC>* vec) {
640  if (NLIB_UNLIKELY(!vec)) return EINVAL;
641  if (NLIB_UNLIKELY(This->type_ != kArray)) return EACCES;
642  vec->clear();
643  if (NLIB_UNLIKELY(!vec->reserve(This->size_))) return ENOMEM;
644  for (uint32_t i = 0; i < This->size_; ++i) {
645  T* item = vec->push_back();
646  ErrnoT e = (*This->via_.ary)[i].Unbox(item);
647  if (NLIB_UNLIKELY(e != 0)) return e; // *vec NOT RESET
648  }
649  return 0;
650  }
651 };
652 
653 template <class T1, class T2>
654 struct MpObject::MyBox<std::pair<T1, T2>, FalseType, FalseType> {
655  static errno_t Box(MpObject* This, const std::pair<T1, T2>& p) {
656  MpObject tmp;
657  ErrnoT e = tmp.InitArray(2);
658  if (NLIB_UNLIKELY(e != 0)) return e;
659  e = (*tmp.via_.ary)[0].Box(p.first);
660  if (NLIB_UNLIKELY(e != 0)) return e;
661  e = (*tmp.via_.ary)[1].Box(p.second);
662  if (NLIB_UNLIKELY(e != 0)) return e;
663  tmp.swap(*This);
664  return 0;
665  }
666  static errno_t Unbox(const MpObject* This, std::pair<T1, T2>* p) {
667  if (NLIB_UNLIKELY(!p)) return EINVAL;
668  if (NLIB_UNLIKELY(This->type_ != kArray)) return EACCES;
669  if (NLIB_UNLIKELY(This->size_ != 2)) return EACCES;
670  ErrnoT e;
671  e = (*This->via_.ary)[0].Unbox(&p->first);
672  if (NLIB_UNLIKELY(e != 0)) return e; // *p NOT RESET
673  e = (*This->via_.ary)[1].Unbox(&p->second);
674  if (NLIB_UNLIKELY(e != 0)) return e; // *p NOT RESET
675  return 0;
676  }
677 };
678 
679 #if defined(NLIB_CXX11_STDLIB_TUPLE) && defined(NLIB_CXX11_VARIADIC_TEMPLATES)
680 template <class ...Args>
681 struct MpObject::MyBox<std::tuple<Args...>, FalseType, FalseType > {
682  private:
683  template<size_t N, class HEAD>
684  static errno_t BoxHelper(MpObject* tmp, const HEAD& head) {
685  return (*tmp->via_.ary)[N].Box(head);
686  }
687  template<size_t N, class HEAD, class ...TAIL>
688  static errno_t BoxHelper(MpObject* tmp, const HEAD& head, TAIL&... tail) {
689  ErrnoT e = (*tmp->via_.ary)[N].Box(head);
690  if (NLIB_UNLIKELY(e != 0)) return e;
691  return BoxHelper<N + 1, TAIL...>(tmp, tail...);
692  }
693  template<size_t N, class HEAD>
694  static errno_t UnboxHelper(const MpObject* This, HEAD& head) { // NOLINT
695  return (*This->via_.ary)[N].Unbox(&head);
696  }
697  template<size_t N, class HEAD, class ...TAIL>
698  static errno_t UnboxHelper(const MpObject* This, HEAD& head, TAIL&... tail) { // NOLINT
699  ErrnoT e = (*This->via_.ary)[N].Unbox(&head);
700  if (NLIB_UNLIKELY(e != 0)) return e;
701  return UnboxHelper<N + 1, TAIL...>(This, tail...);
702  }
703  template<int ...> struct seq {};
704  template<int N, int ...S> struct gens : gens<N - 1, N - 1, S...> {};
705  template<int ...S>
706  struct gens<0, S...> {
707  typedef seq<S...> type;
708  };
709  template<int ...S>
710  static errno_t Box(MpObject* tmp, seq<S...>, const std::tuple<Args...>& p) {
711  return BoxHelper<0>(tmp, std::get<S>(p)...);
712  }
713  template<int ...S>
714  static errno_t Unbox(const MpObject* This, seq<S...>, std::tuple<Args...>& p) { // NOLINT
715  return UnboxHelper<0>(This, std::get<S>(p)...);
716  }
717 
718  public:
719  static errno_t Box(MpObject* This, const std::tuple<Args...>& p) {
720  size_t count = std::tuple_size<std::tuple<Args...> >::value;
721  MpObject tmp;
722  ErrnoT e = tmp.InitArray(static_cast<uint32_t>(count));
723  if (NLIB_UNLIKELY(e != 0)) return e;
724  typedef typename gens<sizeof...(Args)>::type MySeq;
725  e = Box(&tmp, MySeq(), p);
726  if (NLIB_UNLIKELY(e != 0)) return e;
727  tmp.swap(*This);
728  return 0;
729  }
730  static errno_t Unbox(const MpObject* This, std::tuple<Args...>* p) {
731  if (NLIB_UNLIKELY(!p)) return EINVAL;
732  if (NLIB_UNLIKELY(This->type_ != kArray)) return EACCES;
733  if (NLIB_UNLIKELY(This->size_ != std::tuple_size<std::tuple<Args...> >::value))
734  return EACCES;
735  typedef typename gens<sizeof...(Args)>::type MySeq;
736  return Unbox(This, MySeq(), *p);
737  }
738 };
739 #endif
740 
741 template <class K, class V, class Pr, class Alloc>
742 struct MpObject::MyBox<std::map<K, V, Pr, Alloc>, FalseType, FalseType> {
743  static errno_t Box(MpObject* This, const std::map<K, V, Pr, Alloc>& m) {
744  typedef typename std::map<K, V, Pr, Alloc> maptype;
745  uint32_t n = static_cast<uint32_t>(m.size());
746  MpObject tmp;
747  ErrnoT e = tmp.InitMap(n);
748  if (NLIB_UNLIKELY(e != 0)) return e;
749 
750  typename maptype::const_iterator it;
751  typename maptype::const_iterator it_end = m.end();
752  uint32_t i;
753  for (i = 0, it = m.begin(); it != it_end; ++it, ++i) {
754  MpObjectKv& kv = (*tmp.via_.mp)[i];
755  e = kv.first.Box(it->first);
756  if (NLIB_UNLIKELY(e != 0)) return e;
757  e = kv.second.Box(it->second);
758  if (NLIB_UNLIKELY(e != 0)) return e;
759  }
760  tmp.swap(*This);
761  return 0;
762  }
763  static errno_t Unbox(const MpObject* This, std::map<K, V, Pr, Alloc>* m) {
764  if (NLIB_UNLIKELY(!m)) return EINVAL;
765  if (NLIB_UNLIKELY(This->type_ != kMap)) return EACCES;
766  m->clear();
767  for (uint32_t i = 0; i < This->size_; ++i) {
768  K key;
769  V value;
770  const MpObjectKv& kv = (*This->via_.mp)[i];
771  ErrnoT e;
772  e = kv.first.Unbox(&key);
773  if (NLIB_UNLIKELY(e != 0)) return e; // *m NOT RESET
774  e = kv.second.Unbox(&value);
775  if (NLIB_UNLIKELY(e != 0)) return e; // *m NOT RESET
776  NLIB_TRY { (*m)[NLIB_MOVE(key)] = NLIB_MOVE(value); }
777  NLIB_CATCH(...) { return ENOMEM; }
778  }
779  return 0;
780  }
781 };
782 
783 #ifdef NLIB_CXX11_STDLIB_UNORDERED
784 template <class K, class V, class Hash, class Pr, class Alloc>
785 struct MpObject::MyBox<std::unordered_map<K, V, Hash, Pr, Alloc>, FalseType, FalseType > {
786  static errno_t Box(MpObject* This, const std::unordered_map<K, V, Hash, Pr, Alloc>& m) {
787  typedef typename std::unordered_map<K, V, Hash, Pr, Alloc> maptype;
788  uint32_t n = static_cast<uint32_t>(m.size());
789  MpObject tmp;
790  ErrnoT e = tmp.InitMap(n);
791  if (NLIB_UNLIKELY(e != 0)) return e;
792 
793  typename maptype::const_iterator it;
794  typename maptype::const_iterator it_end = m.end();
795  uint32_t i;
796  for (i = 0, it = m.begin(); it != it_end; ++it, ++i) {
797  MpObjectKv& kv = (*tmp.via_.mp)[i];
798  e = kv.first.Box(it->first);
799  if (NLIB_UNLIKELY(e != 0)) return e;
800  e = kv.second.Box(it->second);
801  if (NLIB_UNLIKELY(e != 0)) return e;
802  }
803  tmp.swap(*This);
804  return 0;
805  }
806  static errno_t Unbox(const MpObject* This, std::unordered_map<K, V, Hash, Pr, Alloc>* m) {
807  if (NLIB_UNLIKELY(!m)) return EINVAL;
808  if (NLIB_UNLIKELY(This->type_ != kMap)) return EACCES;
809  m->clear();
810  for (uint32_t i = 0; i < This->size_; ++i) {
811  K key;
812  V value;
813  const MpObjectKv& kv = (*This->via_.mp)[i];
814  ErrnoT e;
815  e = kv.first.Unbox(&key);
816  if (NLIB_UNLIKELY(e != 0)) return e; // *m NOT RESET
817  e = kv.second.Unbox(&value);
818  if (NLIB_UNLIKELY(e != 0)) return e; // *m NOT RESET
819  NLIB_TRY { (*m)[NLIB_MOVE(key)] = NLIB_MOVE(value); }
820  NLIB_CATCH(...) { return ENOMEM; }
821  }
822  return 0;
823  }
824 };
825 #endif
826 
827 NLIB_VIS_PUBLIC bool operator==(const MpObject& lhs, const MpObject& rhs);
828 inline bool operator==(const MpObjectKv& lhs, const MpObjectKv& rhs) NLIB_NOEXCEPT {
829  return lhs.first == rhs.first && lhs.second == rhs.second;
830 }
831 inline bool operator!=(const MpObject& lhs, const MpObject& rhs) NLIB_NOEXCEPT {
832  return !(lhs == rhs);
833 }
834 inline bool operator!=(const MpObjectKv& lhs, const MpObjectKv& rhs) NLIB_NOEXCEPT {
835  return !(lhs == rhs);
836 }
837 
838 template <uint32_t n>
839 errno_t MpObject::Box(const nlib_utf8_t (&str)[n]) NLIB_NOEXCEPT {
840  uint32_t nn = static_cast<uint32_t>(nlib_strlen(str));
841  ErrnoT e = this->InitString(nn);
842  if (NLIB_UNLIKELY(e != 0)) return e;
843  nlib_memcpy(this->GetString(), nn, reinterpret_cast<const void*>(&str[0]), nn);
844  return 0;
845 }
846 
847 template <class T, uint32_t n>
848 errno_t MpObject::Box(const T (&vec)[n]) {
849  MpObject tmp;
850  ErrnoT e = tmp.InitArray(n);
851  if (NLIB_UNLIKELY(e != 0)) return e;
852  for (uint32_t i = 0; i < n; ++i) {
853  e = (*tmp.via_.ary)[i].Box(vec[i]);
854  if (NLIB_UNLIKELY(e != 0)) return e;
855  }
856  this->swap(tmp);
857  return 0;
858 }
859 
860 #ifdef NLIB_CXX11_STDLIB_ARRAY
861 template <class T, size_t n>
862 errno_t MpObject::Box(const std::array<T, n>& vec) {
863  MpObject tmp;
864  ErrnoT e = tmp.InitArray(n);
865  if (NLIB_UNLIKELY(e != 0)) return e;
866  for (uint32_t i = 0; i < n; ++i) {
867  e = (*tmp.via_.ary)[i].Box(vec[i]);
868  if (NLIB_UNLIKELY(e != 0)) return e;
869  }
870  this->swap(tmp);
871  return 0;
872 }
873 #endif
874 
875 template <class T>
876 errno_t MpObject::Unbox(T* a, size_t n) const {
877  NLIB_EINVAL_IFNULL(a);
878  if (NLIB_UNLIKELY(n == 0)) return EINVAL;
879  if (NLIB_UNLIKELY(type_ != kArray)) return EACCES;
880  if (NLIB_UNLIKELY(n != size_)) return ERANGE;
881  for (uint32_t i = 0; i < size_; ++i) {
882  ErrnoT e = (*via_.ary)[i].Unbox(&a[i]);
883  if (NLIB_UNLIKELY(e != 0)) return e;
884  }
885  return 0;
886 }
887 
888 } // namespace msgpack
889 NLIB_NAMESPACE_END
890 
891 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::MpObject)
892 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::MpObjectKv)
893 
894 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
895 #undef NLIB_VIS_PUBLIC
896 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
897 #endif
898 
899 #endif // INCLUDE_NN_NLIB_MSGPACK_MPOBJECT_H_
nlib_utf8_t * GetString() noexcept
オブジェクトから文字列を取得します。
Definition: MpObject.h:196
errno_t Unbox(T v) const
オブジェクトをアンボックス化します。
Definition: MpObject.h:292
bool IsString() const noexcept
格納されている値が文字列であるかどうかを調べます。
Definition: MpObject.h:372
bool IsMap() const noexcept
格納されている値が連想配列であるかどうかを調べます。
Definition: MpObject.h:376
MpObject & operator[](size_t n)
配列である場合に配列の要素への参照を返します。
Definition: MpObject.h:123
MpObjectKv() noexcept
デフォルトコンストラクタです。
Definition: MpObject.h:411
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:163
非負整数型を表します。内部表現はuint64_tです。
Definition: MpObject.h:324
整数型を表します。内部表現はint64_tです。
Definition: MpObject.h:325
Definition: Base64.h:21
MpObject() noexcept
デフォルトコンストラクタです。nil型に設定されます。
Definition: MpObject.h:173
~MpObject() noexcept
デストラクタです。
Definition: MpObject.h:174
const void * GetExt(int8_t *tp, uint32_t *n) const noexcept
オブジェクトから拡張データ型を取得します。
Definition: MpObject.h:236
配列を表します。内部ではMpObjectの列として表現されています。
Definition: MpObject.h:329
iterator begin() noexcept
コンテナの先頭を指す反復子を返します。
Definition: Nlist.h:454
const MpObject * GetArrayItem(size_t n) const noexcept
GetArrayItem(size_t n) と同様です。
Definition: MpObject.h:119
MpObject * SwapArrayItem(size_t n, MpObject *obj) noexcept
obj の内容と配列内のオブジェクトの内容を交換します。
Definition: MpObject.h:147
const void * GetBinary(uint32_t *n) const noexcept
オブジェクトからバイナリを取得します。
Definition: MpObject.h:224
#define NLIB_UNLIKELY(x)
条件xが偽になる傾向が高いことをコンパイラに示します。
const nlib_utf8_t * GetString() const noexcept
オブジェクトから文字列を取得します。
Definition: MpObject.h:210
MpObject * SwapMapItem(const nlib_utf8_t *key, MpObject *obj) noexcept
obj の内容と連想配列内のオブジェクトの内容を交換します。
Definition: MpObject.h:162
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価ならば、trueを返します。
Definition: NMalloc.h:145
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価でなければ、trueを返します。
Definition: NMalloc.h:150
errno_t Box(const T &v)
オブジェクトをボックス化します。
Definition: MpObject.h:264
BaseType::const_iterator const_iterator
読み取り専用フォワードイテレータ
Definition: Nlist.h:371
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
MessagePack又はJSONを読み込むことで作成されるオブジェクトです。
Definition: MpObject.h:95
浮動小数型を表します。内部表現はfloatです。
Definition: MpObject.h:326
pointer push_back()
末尾に要素を追加してデフォルトコンストラクタで初期化します。
Definition: Nlist.h:390
MpObject & operator=(const T &x)
値をMpObjectに代入します。
Definition: MpObject.h:304
MpObject second
値となるオブジェクトです。
Definition: MpObject.h:408
std::vectorに似ていますが、コピーできないオブジェクトを格納可能なクラスが定義されています。 ...
ObjectType
MpObjectに格納されているオブジェクトの型情報です。
Definition: MpObject.h:321
bool IsExt() const noexcept
格納されている値が拡張データであるかどうかを調べます。
Definition: MpObject.h:374
errno_t InitArray(uint32_t n) noexcept
オブジェクトをn 個の要素を持つ配列として初期化します。
void clear() noexcept
コンテナをクリアします。
Definition: Nlist.h:428
浮動小数型を表します。内部表現はdoubleです。
Definition: MpObject.h:327
MpObject * SwapMapItem(const STDSTRING &key, MpObject *obj) noexcept
obj の内容と連想配列内のオブジェクトの内容を交換します。
Definition: MpObject.h:153
errno_t Unbox(const MpObject *obj, T *v)
この関数テンプレートを特殊化してユーザー型のアンボックス化を定義することが可能です。 ...
bool IsNil() const noexcept
格納されている値ががnilであるかどうかを調べます。
Definition: MpObject.h:364
void swap(MpObject &rhs) noexcept
オブジェクトの中身をスワップします。
Definition: MpObject.h:310
#define NLIB_LIKELY(x)
条件xが真になる傾向が高いことをコンパイラに示します。
Definition: Platform_unix.h:99
#define NLIB_CATCH(x)
例外が有効なときはcatch(x), そうでなければif (true)が定義されます。
Definition: Config.h:129
errno_t InitString(uint32_t n) noexcept
オブジェクトを文字列として初期化します。
errno_tをラップするクラスです。Visual Studioのデバッガ上での表示を改善します。
Definition: Config.h:492
static errno_t nlib_memcpy(void *s1, size_t s1max, const void *s2, size_t n)
N1078のmemcpy_sに相当する実装です。
Definition: Platform.h:2357
errno_t Box(const nlib_utf8_t *str) noexcept
文字列をボックス化します。
#define NLIB_TRY
例外が有効なときはtry, そうでなければif (true)が定義されます。
Definition: Config.h:128
ObjectType GetType() const noexcept
オブジェクトの型を返します。
Definition: MpObject.h:355
bool IsArray() const noexcept
格納されている値が配列であるかどうかを調べます。
Definition: MpObject.h:375
MpObject(const T &x)
T型のオブジェクトをボックス化するコンストラクタです。
Definition: MpObject.h:179
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
errno_t InitString(const nlib_utf8_t *str) noexcept
オブジェクトを文字列として初期化します。
Definition: MpObject.h:244
errno_t Unbox(nlib_utf8_t(&str)[n]) const noexcept
Unbox(T (&a)[n]) を御覧ください。
Definition: MpObject.h:283
const MpObject * GetMapItem(const STDSTRING &str) const noexcept
GetMapItem(const STDSTRING& str) と同様です。
Definition: MpObject.h:139
開発環境別の設定が書かれるファイルです。
~MpObjectKv() noexcept
デストラクタです。
Definition: MpObject.h:412
真偽値型を表します。内部表現はboolです。
Definition: MpObject.h:323
bool reserve(size_type n) noexcept
n 個の要素のためのメモリをアロケート済みにします。
Definition: Nlist.h:674
uint32_t GetSize() const noexcept
配列や連想配列や文字列やバイナリの場合にそのサイズを返します。
Definition: MpObject.h:358
std::vectorに似た、コピーコンストラクタを持たないオブジェクトを格納可能なコンテナ類似クラスです。 ...
Definition: Nlist.h:32
errno_t RemoveMapItem(const STDSTRING &str, MpObjectKv *kv) noexcept
キーを指定して連想配列内のキーとオブジェクトを削除します。
Definition: MpObject.h:206
size_type size() const noexcept
格納されている要素の個数を返します。
Definition: Nlist.h:378
バイト列(文字列)を表します。
Definition: MpObject.h:328
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
bool IsBoolean() const noexcept
格納されている値が真偽値であるかどうかを調べます。
Definition: MpObject.h:365
void * GetBinary(uint32_t *n) noexcept
オブジェクトからバイナリを取得します。
Definition: MpObject.h:213
strlen, strcpy等を安全に使えるようにラップしています。
void * GetExt(int8_t *tp, uint32_t *n) noexcept
オブジェクトから拡張データ型を取得します。
Definition: MpObject.h:227
bool IsFloat() const noexcept
格納されている値が単精度浮動小数点型であるかどうかを調べます。
Definition: MpObject.h:370
MpObject first
キーとなるオブジェクトです。
Definition: MpObject.h:407
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:229
MpObject * GetMapItem(const STDSTRING &str) noexcept
文字列を指定して連想配列内のオブジェクトを取得します。
Definition: MpObject.h:143
errno_t InitMap(uint32_t n) noexcept
オブジェクトをn個の要素を持つ連想配列として初期化します。
MpObject * GetArrayItem(size_t n) noexcept
インデックスを指定して配列内のオブジェクトを取得します。
Definition: MpObject.h:115
bool IsDouble() const noexcept
格納されている値が倍精度浮動小数点型であるかどうかを調べます。
Definition: MpObject.h:371
MpObject型のキーと値のペアです。連想配列を格納するために利用されます。
Definition: MpObject.h:406
errno_t GetMapItem(const nlib_utf8_t *str, size_t n, MpObjectKv **obj) noexcept
キーとなる非ヌル終端の文字列を指定して連想配列のキーと値のペアを取得します。
Definition: MpObject.h:186
MessagePackのnil, 及びJSONのnullに対応するクラスです。
Definition: MpObject.h:56
void swap(MpObjectKv &rhs) noexcept
オブジェクトの中身をスワップします。
Definition: MpObject.h:414
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
bool IsInteger() const noexcept
格納されている値が整数値であるかどうかを調べます。
Definition: MpObject.h:366
bool IsBinary() const noexcept
格納されている値がバイナリであるかどうかを調べます。
Definition: MpObject.h:373
連想配列を表します。内部ではMpObjectのペアの列として表現されています。
Definition: MpObject.h:330
errno_t Unbox(T(&a)[n]) const
オブジェクトの値をアンボックス化します。
Definition: MpObject.h:273
errno_t Box(MpObject *obj, const T &v)
この関数テンプレートを特殊化してユーザー型のボックス化を定義することが可能です。
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:300
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37