nlib
MpObject.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_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
Gets a string from an object.
Definition: MpObject.h:196
errno_t Unbox(T v) const
Unboxes the object.
Definition: MpObject.h:292
bool IsString() const noexcept
Determines whether the stored value is a string.
Definition: MpObject.h:372
bool IsMap() const noexcept
Determines whether the stored value is an associative array.
Definition: MpObject.h:376
MpObject & operator[](size_t n)
For an array, returns a reference to an element of the array.
Definition: MpObject.h:123
MpObjectKv() noexcept
Instantiates the object with default parameters (default constructor).
Definition: MpObject.h:411
#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:163
Represents an unsigned integer type. The internal representation is uint64_t.
Definition: MpObject.h:324
Represents an integer type. The internal representation is int64_t.
Definition: MpObject.h:325
Definition: Base64.h:21
MpObject() noexcept
Instantiates the object with default parameters (default constructor). Set to the nil type...
Definition: MpObject.h:173
~MpObject() noexcept
Destructor.
Definition: MpObject.h:174
const void * GetExt(int8_t *tp, uint32_t *n) const noexcept
Gets an extended data type from an object.
Definition: MpObject.h:236
Represents an array. The internal representation is an array of MpObject.
Definition: MpObject.h:329
iterator begin() noexcept
Returns the iterator pointing to the beginning of the container.
Definition: Nlist.h:454
const MpObject * GetArrayItem(size_t n) const noexcept
The same as GetArrayItem(size_t n).
Definition: MpObject.h:119
MpObject * SwapArrayItem(size_t n, MpObject *obj) noexcept
Swaps the content of obj and the content of the object within an array.
Definition: MpObject.h:147
const void * GetBinary(uint32_t *n) const noexcept
Gets binary from an object.
Definition: MpObject.h:224
#define NLIB_UNLIKELY(x)
Indicates to the compiler that condition x is likely to be false.
const nlib_utf8_t * GetString() const noexcept
Gets a string from an object.
Definition: MpObject.h:210
MpObject * SwapMapItem(const nlib_utf8_t *key, MpObject *obj) noexcept
Swaps the content of obj and the content of the object within an associative array.
Definition: MpObject.h:162
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are equal.
Definition: NMalloc.h:145
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are not equal.
Definition: NMalloc.h:150
errno_t Box(const T &v)
Boxes the object.
Definition: MpObject.h:264
BaseType::const_iterator const_iterator
Read-only forward iterator.
Definition: Nlist.h:371
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
Object created when MessagePack or JSON is read.
Definition: MpObject.h:95
Represents a floating point type. The internal representation is float.
Definition: MpObject.h:326
pointer push_back()
Adds an element to the end and initializes it with the default constructor.
Definition: Nlist.h:390
MpObject & operator=(const T &x)
The value is passed into MpObject.
Definition: MpObject.h:304
MpObject second
Object used as a value.
Definition: MpObject.h:408
Defines the class that resembles std::vector but can store objects that cannot be copied...
ObjectType
Data type of the object stored in MpObject.
Definition: MpObject.h:321
bool IsExt() const noexcept
Determines whether the stored value is extended data.
Definition: MpObject.h:374
errno_t InitArray(uint32_t n) noexcept
Initializes as an object with an n element array.
void clear() noexcept
Clears the container.
Definition: Nlist.h:428
Represents a floating point type. The internal representation is double.
Definition: MpObject.h:327
MpObject * SwapMapItem(const STDSTRING &key, MpObject *obj) noexcept
Swaps the content of obj and the content of the object within an associative array.
Definition: MpObject.h:153
errno_t Unbox(const MpObject *obj, T *v)
This function template can be specialized to define unboxing the user type.
bool IsNil() const noexcept
Determines whether the stored value is nil.
Definition: MpObject.h:364
void swap(MpObject &rhs) noexcept
Swaps the content of the object.
Definition: MpObject.h:310
#define NLIB_LIKELY(x)
Indicates to the compiler that condition x is likely to be true.
Definition: Platform_unix.h:99
#define NLIB_CATCH(x)
Defines catch(x) if exceptions are enabled. If not, defines if (true).
Definition: Config.h:129
errno_t InitString(uint32_t n) noexcept
Initializes the object as a string.
Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger...
Definition: Config.h:492
static errno_t nlib_memcpy(void *s1, size_t s1max, const void *s2, size_t n)
An implementation corresponding to N1078 memcpy_s.
Definition: Platform.h:2357
errno_t Box(const nlib_utf8_t *str) noexcept
Boxes the string.
#define NLIB_TRY
Defines try if exceptions are enabled. If not, defines if (true).
Definition: Config.h:128
ObjectType GetType() const noexcept
Returns the object type.
Definition: MpObject.h:355
bool IsArray() const noexcept
Determines whether the stored value is an array.
Definition: MpObject.h:375
MpObject(const T &x)
The constructor for boxing a T-type object.
Definition: MpObject.h:179
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
errno_t InitString(const nlib_utf8_t *str) noexcept
Initializes the object as a string.
Definition: MpObject.h:244
errno_t Unbox(nlib_utf8_t(&str)[n]) const noexcept
See Unbox(T (&a)[n]).
Definition: MpObject.h:283
const MpObject * GetMapItem(const STDSTRING &str) const noexcept
The same as GetMapItem(const STDSTRING& str).
Definition: MpObject.h:139
A file that contains the configuration information for each development environment.
~MpObjectKv() noexcept
Destructor.
Definition: MpObject.h:412
Represents a boolean type. The internal representation is a bool.
Definition: MpObject.h:323
bool reserve(size_type n) noexcept
Allocates memory for n number of elements.
Definition: Nlist.h:674
uint32_t GetSize() const noexcept
Returns the size of the array, associative array, string, or binary.
Definition: MpObject.h:358
A container-like class similar to std::vector that can store objects that do not have copy constructo...
Definition: Nlist.h:32
errno_t RemoveMapItem(const STDSTRING &str, MpObjectKv *kv) noexcept
Specifies a key and deletes the corresponding key and object in the associative array.
Definition: MpObject.h:206
size_type size() const noexcept
Returns the number of stored elements.
Definition: Nlist.h:378
Respresents a byte array (string).
Definition: MpObject.h:328
size_t nlib_strlen(const char *s)
Internally calls strlen(). In some cases, it may operate as an independent implementation.
bool IsBoolean() const noexcept
Determines whether the stored value is a boolean.
Definition: MpObject.h:365
void * GetBinary(uint32_t *n) noexcept
Gets binary from an object.
Definition: MpObject.h:213
Wraps functions like strlen and strcpy so they can be safely used.
void * GetExt(int8_t *tp, uint32_t *n) noexcept
Gets an extended data type from an object.
Definition: MpObject.h:227
bool IsFloat() const noexcept
Determines whether the stored value is a single precision float.
Definition: MpObject.h:370
MpObject first
Object used as a key.
Definition: MpObject.h:407
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
MpObject * GetMapItem(const STDSTRING &str) noexcept
Specifies a string and gets the object in the associative array.
Definition: MpObject.h:143
errno_t InitMap(uint32_t n) noexcept
Initializes the object as an n element associative array.
MpObject * GetArrayItem(size_t n) noexcept
Specifies an index and gets the object in the array.
Definition: MpObject.h:115
bool IsDouble() const noexcept
Determines whether the stored value is a double.
Definition: MpObject.h:371
A pair consisting of an MpObject-type key and value. Used to store an associative array...
Definition: MpObject.h:406
errno_t GetMapItem(const nlib_utf8_t *str, size_t n, MpObjectKv **obj) noexcept
Obtains the pair of a key and value from the associative array by specifying a non-null terminated st...
Definition: MpObject.h:186
Class that corresponds to nil in MessagePack and null in JSON.
Definition: MpObject.h:56
void swap(MpObjectKv &rhs) noexcept
Swaps the content of the object.
Definition: MpObject.h:414
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
bool IsInteger() const noexcept
Determines whether the stored value is an integer.
Definition: MpObject.h:366
bool IsBinary() const noexcept
Determines whether the stored value is binary.
Definition: MpObject.h:373
Represents an associative array. The internal representation is an array of MpObject pairs...
Definition: MpObject.h:330
errno_t Unbox(T(&a)[n]) const
Unboxes the object value.
Definition: MpObject.h:273
errno_t Box(MpObject *obj, const T &v)
This function template can be specialized to define boxing the user type.
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:300
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37