16 #ifndef INCLUDE_NN_NLIB_MSGPACK_MPOBJECT_H_ 17 #define INCLUDE_NN_NLIB_MSGPACK_MPOBJECT_H_ 26 #include "nn/nlib/Swap.h" 30 #ifdef __cpp_rvalue_references 32 #include <unordered_map> 36 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 37 #undef NLIB_VIS_PUBLIC 38 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 90 class MpObjectAsArray;
92 class MpObjectAsString;
93 class MpObjectAsBinary;
136 NLIB_ASSERT(this->IsArray());
137 NLIB_ASSERT(n < size_);
138 return (*via_.ary)[n];
141 NLIB_ASSERT(this->IsArray());
142 NLIB_ASSERT(n < size_);
143 return (*via_.ary)[n];
149 return GetMapItem(&str[0]);
153 return GetMapItem(&str[0]);
155 template<
class STDSTRING>
157 return GetMapItem(&str[0], str.size());
159 template<
class STDSTRING>
161 return GetMapItem(&str[0], str.size());
172 #ifdef __cpp_rvalue_references 174 nlib_memcpy(
this,
sizeof(*
this), &rhs,
sizeof(rhs));
179 nlib_memcpy(
this,
sizeof(*
this), &rhs,
sizeof(rhs));
185 nlib_memcpy(
this,
sizeof(*
this), &rhs,
sizeof(rhs));
190 nlib_memcpy(
this,
sizeof(*
this), &rhs,
sizeof(rhs));
198 MyBox<T, typename IsIntegral<T>::type,
typename IsSigned<T>::type>::Construct(
this, x);
207 errno_t e = this->GetMapItem(str, n, &kv);
208 if (e != 0)
return e;
215 if (type_ == kString)
return via_.str;
222 template<
class STDSTRING>
224 return RemoveMapItem(str.c_str(), kv);
228 return const_cast<MpObject*
>(
this)->GetString();
232 return const_cast<MpObject*
>(
this)->GetBinary(n);
236 return const_cast<MpObject*
>(
this)->GetExt(tp, n);
240 #ifdef __cpp_rvalue_references 241 std::tuple<errno_t, const nlib_byte_t*, uint32_t> GetBinary() const
NLIB_NOEXCEPT;
244 std::pair<errno_t, MpObject> rval;
245 rval.first = RemoveArrayItem(n, &rval.second);
248 std::pair<errno_t, MpObjectKv> RemoveMapItem(
size_t n)
NLIB_NOEXCEPT;
252 return std::make_pair(GetMapItem(str, n, &kv), kv);
254 std::pair<errno_t, const MpObjectKv*>
256 const MpObjectKv* kv;
257 return std::make_pair(GetMapItem(str, n, &kv), kv);
261 std::pair<errno_t, nlib_time> GetTimestamp() const
NLIB_NOEXCEPT;
268 uint32_t n =
static_cast<uint32_t
>(
nlib_strlen(str));
269 return InitString(str, n);
281 template<
class T, u
int32_t n>
283 #ifdef __cpp_rvalue_references 284 template<
class T,
size_t n>
289 return MyBox<T, typename IsIntegral<T>::type,
typename IsSigned<T>::type>
::Box(
this, v);
296 template<
class T,
size_t n>
298 return this->
Unbox(&a[0], n);
300 #ifdef __cpp_rvalue_references 301 template<
class T,
size_t n>
303 return this->
Unbox(reinterpret_cast<T*>(&*a.begin()), n);
308 return this->
Unbox(&str[0], n);
319 return MyBox<typename RemovePtr<T>::type,
320 typename IsIntegral<typename RemovePtr<T>::type>::type,
321 typename IsSigned<typename RemovePtr<T>::type>::type>
::Unbox(
this, v);
329 MyBox<T, typename IsIntegral<T>::type,
typename IsSigned<T>::type>::Assign(
this, x);
348 kStringInline = 0x80 | kString,
349 kBinaryInline = 0x80 | kBinary,
350 kBooleanFalse = 0x00 | kBoolean,
351 kBooleanTrue = 0x80 | kBoolean
355 if (type_ == kStringInline || type_ == kBinaryInline)
364 return tp == kUint64 || tp == kInt64;
376 template<
class T,
class IS_INTEGRAL,
class IS_SIGNED>
380 if (!v)
return EINVAL;
383 static void Assign(MpObject* This,
const T& x);
384 static void Construct(MpObject* This,
const T& x);
387 if (type_ >= kString && type_ <= kExt) ReleaseIfNeeded_();
399 friend
NLIB_VIS_PUBLIC bool operator==(const MpObject& lhs, const MpObject& rhs);
400 friend class MpObjectAsArray;
401 friend class MpObjectAsMap;
402 friend class MpObjectAsString;
403 friend class MpObjectAsBinary;
404 friend class MpObjectAsExt;
414 #ifdef __cpp_rvalue_references 415 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 420 second(std::move(rhs.second)) {}
422 first = std::move(rhs.first);
423 second = std::move(rhs.second);
448 #if defined(_MSC_VER) && _MSC_VER == 1800 453 NLIB_ASSERT(obj.IsArray());
464 NLIB_ASSERT(n < GetSize());
465 return (*obj_.via_.ary)[n];
468 NLIB_ASSERT(n < GetSize());
469 return (*obj_.via_.ary)[n];
474 NLIB_ASSERT(n < 0x100000000ULL);
476 if (!(*obj_.via_.ary).resize(n))
return ENOMEM;
477 obj_.size_ =
static_cast<uint32_t
>(n);
480 #ifdef __cpp_rvalue_references 482 MpObject* p = obj_.via_.ary->push_back(std::forward<MpObject>(rhs));
485 NLIB_ASSERT(obj_.size_ == obj_.via_.ary->size());
493 return Insert(it, std::move(rhs));
504 if (!obj_.via_.ary->pop_back()) {
508 NLIB_ASSERT(obj_.size_ == obj_.via_.ary->size());
542 #if defined(_MSC_VER) && _MSC_VER == 1800 552 NLIB_ASSERT(n < GetSize());
553 return (*obj_.via_.mp)[n];
556 NLIB_ASSERT(n < GetSize());
557 return (*obj_.via_.mp)[n];
561 template<
class StringIterator>
562 iterator GetByKey(StringIterator first, StringIterator last)
NLIB_NOEXCEPT;
563 template<
class StringIterator>
564 const_iterator GetByKey(StringIterator first, StringIterator last)
const NLIB_NOEXCEPT;
571 NLIB_ASSERT(n < 0x100000000ULL);
573 if (!(*obj_.via_.mp).resize(n))
return ENOMEM;
574 obj_.size_ =
static_cast<uint32_t
>(n);
577 #ifdef __cpp_rvalue_references 579 MpObjectKv* p = obj_.via_.mp->push_back(std::forward<MpObjectKv>(rhs));
588 kv.
second = std::move(value);
589 return PushBack(std::move(kv));
593 if (!obj_.via_.mp->pop_back()) {
599 #ifdef __cpp_rvalue_references 628 #if defined(_MSC_VER) && _MSC_VER == 1800 633 NLIB_ASSERT(obj.IsString());
642 return std::reverse_iterator<const_iterator>(end());
645 return std::reverse_iterator<const_iterator>(begin());
651 NLIB_ASSERT(n < GetSize());
652 return *(begin() + n);
655 NLIB_ASSERT(n < GetSize());
656 return *(begin() + n);
660 return (obj_.type_ == MpObject::kStringInline) ? obj_.raw14size_ : obj_.size_;
672 if (obj_.type_ == MpObject::kString)
return obj_.via_.str;
673 NLIB_ASSERT(obj_.type_ == MpObject::kStringInline);
674 return reinterpret_cast<const nlib_utf8_t*
>(&obj_.raw14data_);
677 if (obj_.type_ == MpObject::kString)
return obj_.via_.str;
678 NLIB_ASSERT(obj_.type_ == MpObject::kStringInline);
679 return reinterpret_cast<nlib_utf8_t*
>(&obj_.raw14data_);
701 #if defined(_MSC_VER) && _MSC_VER == 1800 706 NLIB_ASSERT(obj.IsBinary());
715 return std::reverse_iterator<const_iterator>(end());
718 return std::reverse_iterator<const_iterator>(begin());
723 return (obj_.type_ == MpObject::kBinaryInline) ? obj_.raw14size_ : obj_.size_;
728 if (obj_.type_ == MpObject::kBinary)
729 return static_cast<const nlib_byte_t*
>(obj_.via_.binary);
730 NLIB_ASSERT(obj_.type_ == MpObject::kBinaryInline);
731 return reinterpret_cast<const nlib_byte_t*
>(&obj_.raw14data_);
734 if (obj_.type_ == MpObject::kBinary)
return static_cast<nlib_byte_t*
>(obj_.via_.binary);
735 NLIB_ASSERT(obj_.type_ == MpObject::kBinaryInline);
736 return reinterpret_cast<nlib_byte_t*
>(&obj_.raw14data_);
752 return &*bin.
begin();
754 #ifdef __cpp_rvalue_references 755 inline std::tuple<errno_t, const nlib_byte_t*, uint32_t> MpObject::GetBinary() const
NLIB_NOEXCEPT {
756 if (
NLIB_UNLIKELY(!IsBinary()))
return std::make_tuple(EACCES,
nullptr, 0);
758 return std::make_tuple(0, &*bin.
begin(), bin.
GetSize());
764 #if defined(_MSC_VER) && _MSC_VER == 1800 790 #ifdef __cpp_rvalue_references 791 inline std::tuple<errno_t, int8_t, const nlib_byte_t*, uint32_t>
793 if (
NLIB_UNLIKELY(!IsExt()))
return std::make_tuple(EACCES, static_cast<int8_t>(0),
nullptr, 0);
800 template<
class StringIterator>
802 MpObjectAsMap::GetByKey(StringIterator first, StringIterator last)
NLIB_NOEXCEPT {
805 for (; it != itend; ++it) {
806 if (!it->first.IsString())
continue;
807 uint32_t len = it->first.GetSize();
808 if (len != last - first)
continue;
810 while (first != last) {
811 if (*k++ != *first++)
break;
813 if (first == last)
break;
817 template<
class StringIterator>
819 MpObjectAsMap::GetByKey(StringIterator first, StringIterator last)
const NLIB_NOEXCEPT {
822 for (; it != itend; ++it) {
823 if (!it->first.IsString())
continue;
824 uint32_t len = it->first.GetSize();
825 if (len != last - first)
continue;
827 while (first != last) {
828 if (*k++ != *first++)
break;
830 if (first == last)
break;
835 #ifdef __cpp_rvalue_references 836 inline std::pair<errno_t, MpObjectKv> MpObject::RemoveMapItem(
size_t n)
NLIB_NOEXCEPT {
837 std::pair<errno_t, MpObjectKv> rval;
838 rval.first = RemoveMapItem(n, &rval.second);
844 struct MpObject::MyBox<nil, FalseType, FalseType> {
847 This->ReleaseIfNeeded();
851 static void Assign(MpObject* This, nil x)
NLIB_NOEXCEPT { This->Box(x); }
852 static void Construct(MpObject* This, nil)
NLIB_NOEXCEPT { This->type_ = kNil; }
856 struct MpObject::MyBox<bool, TrueType, FalseType> {
858 This->ReleaseIfNeeded();
859 This->type_ = v ?
static_cast<uint8_t
>(kBooleanTrue) : static_cast<uint8_t>(kBooleanFalse);
863 if (This->type_ == kBooleanFalse) {
866 }
else if (
NLIB_LIKELY(This->type_ == kBooleanTrue)) {
873 static void Assign(MpObject* This,
bool x)
NLIB_NOEXCEPT { This->Box(x); }
874 static void Construct(MpObject* This,
bool x)
NLIB_NOEXCEPT {
875 This->type_ = x ?
static_cast<uint8_t
>(kBooleanTrue) : static_cast<uint8_t>(kBooleanFalse);
880 struct MpObject::MyBox<T, TrueType, TrueType> {
882 This->ReleaseIfNeeded();
883 This->type_ = kInt64;
889 if (This->type_ == kInt64) {
890 *v =
static_cast<T
>(This->via_.i64);
893 *v =
static_cast<T
>(This->via_.u64);
899 static void Assign(MpObject* This, T x)
NLIB_NOEXCEPT { This->Box(x); }
901 This->type_ = kInt64;
907 struct MpObject::MyBox<T, TrueType, FalseType> {
909 This->ReleaseIfNeeded();
910 This->type_ = kUint64;
916 if (This->type_ == kInt64) {
917 *v =
static_cast<T
>(This->via_.i64);
920 *v =
static_cast<T
>(This->via_.u64);
926 static void Assign(MpObject* This, T x)
NLIB_NOEXCEPT { This->Box(x); }
928 This->type_ = kUint64;
933 template<
class TR1_WORKAROUND>
934 struct MpObject::MyBox<float, FalseType, TR1_WORKAROUND> {
936 This->ReleaseIfNeeded();
937 This->type_ = kFloat;
943 switch (This->type_) {
948 *v =
static_cast<float>(This->via_.f64);
956 static void Assign(MpObject* This,
float x)
NLIB_NOEXCEPT { This->Box(x); }
957 static void Construct(MpObject* This,
float x)
NLIB_NOEXCEPT {
958 This->type_ = kFloat;
963 template<
class TR1_WORKAROUND>
964 struct MpObject::MyBox<double, FalseType, TR1_WORKAROUND> {
966 This->ReleaseIfNeeded();
967 This->type_ = kDouble;
973 switch (This->type_) {
986 static void Assign(MpObject* This,
double x)
NLIB_NOEXCEPT { This->Box(x); }
987 static void Construct(MpObject* This,
double x)
NLIB_NOEXCEPT {
988 This->type_ = kDouble;
994 struct MpObject::MyBox<
std::string, FalseType, FalseType> {
996 uint32_t n =
static_cast<uint32_t
>(str.size());
997 ErrnoT e = This->InitString(n);
999 nlib_memcpy(static_cast<void*>(This->GetString()), n, static_cast<const void*>(&str[0]), n);
1007 NLIB_TRY { (*str).assign(chr, This->GetSize()); }
1008 NLIB_CATCH(std::bad_alloc&) {
return ENOMEM; }
1013 template<
class T,
class ALLOC>
1014 struct MpObject::MyBox<
std::vector<T, ALLOC>, FalseType, FalseType> {
1015 static errno_t Box(MpObject* This,
const std::vector<T, ALLOC>& vec) {
1016 uint32_t n =
static_cast<uint32_t
>(vec.size());
1018 ErrnoT e = tmp.InitArray(n);
1021 for (uint32_t i = 0; i < n; ++i) {
1022 e = (*tmp.via_.ary)[i].
Box(vec[i]);
1025 This->assign(tmp, move_tag());
1028 static errno_t Unbox(
const MpObject* This, std::vector<T, ALLOC>* vec) {
1031 NLIB_TRY { vec->resize(This->size_); }
1032 NLIB_CATCH(std::bad_alloc&) {
return ENOMEM; }
1033 for (uint32_t i = 0; i < This->size_; ++i) {
1034 ErrnoT e = (*This->via_.ary)[i].
Unbox(&(*vec)[i]);
1041 template<
class T,
class ALLOC>
1042 struct MpObject::MyBox<Nlist<T, ALLOC>, FalseType, FalseType> {
1043 static errno_t Box(MpObject* This,
const Nlist<T, ALLOC>& vec) {
1044 size_t n = vec.size();
1046 ErrnoT e = tmp.InitArray(static_cast<uint32_t>(n));
1048 typename Nlist<T, ALLOC>::const_iterator it = vec.begin();
1049 for (
size_t i = 0; i < n; ++it, ++i) {
1050 e = (*tmp.via_.ary)[i].
Box(*it);
1053 This->assign(tmp, move_tag());
1056 static errno_t Unbox(
const MpObject* This, Nlist<T, ALLOC>* vec) {
1060 if (
NLIB_UNLIKELY(!vec->reserve(This->size_)))
return ENOMEM;
1061 for (uint32_t i = 0; i < This->size_; ++i) {
1062 T* item = vec->push_back();
1063 ErrnoT e = (*This->via_.ary)[i].
Unbox(item);
1070 template<
class T1,
class T2>
1071 struct MpObject::MyBox<
std::pair<T1, T2>, FalseType, FalseType> {
1072 static errno_t Box(MpObject* This,
const std::pair<T1, T2>& p) {
1074 ErrnoT e = tmp.InitArray(2);
1076 e = (*tmp.via_.ary)[0].
Box(p.first);
1078 e = (*tmp.via_.ary)[1].
Box(p.second);
1080 This->assign(tmp, move_tag());
1083 static errno_t Unbox(
const MpObject* This, std::pair<T1, T2>* p) {
1088 e = (*This->via_.ary)[0].
Unbox(&p->first);
1090 e = (*This->via_.ary)[1].
Unbox(&p->second);
1096 #if defined(__cpp_rvalue_references) && defined(__cpp_variadic_templates) 1097 template<
class... Args>
1098 struct MpObject::MyBox<
std::tuple<Args...>, FalseType, FalseType> {
1100 template<
size_t N,
class HEAD>
1101 static errno_t BoxHelper(MpObject* tmp,
const HEAD& head) {
1102 return (*tmp->via_.ary)[N].Box(head);
1104 template<
size_t N,
class HEAD,
class... TAIL>
1105 static errno_t BoxHelper(MpObject* tmp,
const HEAD& head, TAIL&... tail) {
1106 ErrnoT e = (*tmp->via_.ary)[N].
Box(head);
1108 return BoxHelper<N + 1, TAIL...>(tmp, tail...);
1110 template<
size_t N,
class HEAD>
1111 static errno_t UnboxHelper(
const MpObject* This, HEAD& head) {
1112 return (*This->via_.ary)[N].Unbox(&head);
1114 template<
size_t N,
class HEAD,
class... TAIL>
1115 static errno_t UnboxHelper(
const MpObject* This, HEAD& head, TAIL&... tail) {
1116 ErrnoT e = (*This->via_.ary)[N].
Unbox(&head);
1118 return UnboxHelper<N + 1, TAIL...>(This, tail...);
1122 template<
int N,
int... S>
1123 struct gens : gens<N - 1, N - 1, S...> {};
1125 struct gens<0, S...> {
1126 typedef seq<S...> type;
1129 static errno_t Box(MpObject* tmp, seq<S...>,
const std::tuple<Args...>& p) {
1130 return BoxHelper<0>(tmp, std::get<S>(p)...);
1133 static errno_t Unbox(
const MpObject* This, seq<S...>, std::tuple<Args...>& p) {
1134 return UnboxHelper<0>(This, std::get<S>(p)...);
1138 static errno_t Box(MpObject* This,
const std::tuple<Args...>& p) {
1139 size_t count = std::tuple_size<std::tuple<Args...> >::value;
1141 ErrnoT e = tmp.InitArray(static_cast<uint32_t>(count));
1143 typedef typename gens<
sizeof...(Args)>::type MySeq;
1144 e =
Box(&tmp, MySeq(), p);
1146 This->assign(tmp, move_tag());
1149 static errno_t Unbox(
const MpObject* This, std::tuple<Args...>* p) {
1152 if (
NLIB_UNLIKELY(This->size_ != std::tuple_size<std::tuple<Args...> >::value))
1154 typedef typename gens<
sizeof...(Args)>::type MySeq;
1155 return Unbox(This, MySeq(), *p);
1160 template<
class K,
class V,
class Pr,
class Alloc>
1161 struct MpObject::MyBox<
std::map<K, V, Pr, Alloc>, FalseType, FalseType> {
1162 static errno_t Box(MpObject* This,
const std::map<K, V, Pr, Alloc>& m) {
1163 typedef typename std::map<K, V, Pr, Alloc> maptype;
1164 uint32_t n =
static_cast<uint32_t
>(m.size());
1166 ErrnoT e = tmp.InitMap(n);
1169 typename maptype::const_iterator it;
1170 typename maptype::const_iterator it_end = m.end();
1172 for (i = 0, it = m.begin(); it != it_end; ++it, ++i) {
1173 MpObjectKv& kv = (*tmp.via_.mp)[i];
1174 e = kv.first.Box(it->first);
1176 e = kv.second.Box(it->second);
1179 This->assign(tmp, move_tag());
1182 static errno_t Unbox(
const MpObject* This, std::map<K, V, Pr, Alloc>* m) {
1186 for (uint32_t i = 0; i < This->size_; ++i) {
1189 const MpObjectKv& kv = (*This->via_.mp)[i];
1191 e = kv.first.Unbox(&key);
1193 e = kv.second.Unbox(&value);
1195 NLIB_TRY { (*m)[NLIB_MOVE(key)] = NLIB_MOVE(value); }
1202 #ifdef __cpp_rvalue_references 1203 template<
class K,
class V,
class Hash,
class Pr,
class Alloc>
1204 struct MpObject::MyBox<
std::unordered_map<K, V, Hash, Pr, Alloc>, FalseType, FalseType> {
1205 static errno_t Box(MpObject* This,
const std::unordered_map<K, V, Hash, Pr, Alloc>& m) {
1206 typedef typename std::unordered_map<K, V, Hash, Pr, Alloc> maptype;
1207 uint32_t n =
static_cast<uint32_t
>(m.size());
1209 ErrnoT e = tmp.InitMap(n);
1212 typename maptype::const_iterator it;
1213 typename maptype::const_iterator it_end = m.end();
1215 for (i = 0, it = m.begin(); it != it_end; ++it, ++i) {
1216 MpObjectKv& kv = (*tmp.via_.mp)[i];
1217 e = kv.first.Box(it->first);
1219 e = kv.second.Box(it->second);
1222 This->assign(tmp, move_tag());
1225 static errno_t Unbox(
const MpObject* This, std::unordered_map<K, V, Hash, Pr, Alloc>* m) {
1229 for (uint32_t i = 0; i < This->size_; ++i) {
1232 const MpObjectKv& kv = (*This->via_.mp)[i];
1234 e = kv.first.Unbox(&key);
1236 e = kv.second.Unbox(&value);
1238 NLIB_TRY { (*m)[NLIB_MOVE(key)] = NLIB_MOVE(value); }
1248 return lhs.first == rhs.first && lhs.second == rhs.second;
1251 return !(lhs == rhs);
1254 return !(lhs == rhs);
1257 template<u
int32_t n>
1262 nlib_memcpy(this->GetString(),
nn, static_cast<const void*>(&str[0]),
nn);
1266 template<
class T, u
int32_t n>
1271 for (uint32_t i = 0; i < n; ++i) {
1272 e = (*tmp.via_.ary)[i].
Box(vec[i]);
1279 #ifdef __cpp_rvalue_references 1280 template<
class T,
size_t n>
1285 for (uint32_t i = 0; i < n; ++i) {
1286 e = (*tmp.via_.ary)[i].
Box(vec[i]);
1296 NLIB_EINVAL_IFNULL(a);
1300 for (uint32_t i = 0; i < size_; ++i) {
1310 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::MpObject)
1311 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::MpObjectKv)
1313 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 1314 #undef NLIB_VIS_PUBLIC 1315 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 1318 #endif // INCLUDE_NN_NLIB_MSGPACK_MPOBJECT_H_ const nlib_utf8_t * const_iterator
Read-only random-access iterator.
nlib_utf8_t * GetString() noexcept
Gets a string from an object.
The class for providing access with character elements for MpObject that has the string (ASCII or UTF...
std::reverse_iterator< iterator > reverse_iterator
A reverse iterator.
iterator begin() noexcept
Gets the iterator pointing to the first element.
iterator end() noexcept
Gets the iterator pointing beyond the last element.
iterator end() noexcept
Gets the iterator pointing beyond the last element.
const_reverse_iterator rbegin() const noexcept
Gets the read-only reverse iterator pointing to the last element.
The class for providing access with MpObject stored in an array as an element for MpObject that has a...
errno_t Unbox(T v) const
Unboxes the object.
MpObject * pointer
Pointer to the element.
bool IsString() const noexcept
Determines whether the stored value is a string.
bool IsMap() const noexcept
Determines whether the stored value is an associative array.
size_t size() const noexcept
Returns the length of the string.
reference operator[](size_t n) noexcept
Gets the nth element. n must be less than the number of stored elements.
The class for providing access with a pair of the key and the value as an element for MpObject that h...
reference operator[](size_t n) noexcept
Returns a reference to the character at the specified position.
MpObjectKv() noexcept
Instantiates the object with default parameters (default constructor).
const_reference back() const noexcept
Gets a reference to the last element.
reference operator[](size_t n) noexcept
Gets the nth element. n must be less than the number of stored elements.
The class for providing access for extended data type MpObject.
const nlib_byte_t * const_iterator
Read-only random-access iterator.
size_t GetSize() const noexcept
Returns the number of stored elements.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
The class to provide access with byte data as an element for MpObject.
Represents an unsigned integer type. The internal representation is uint64_t.
const MpObject & operator[](size_t n) const
The const decoration version of the above function.
const void * GetExtData() const noexcept
The const decoration version of the above function.
errno_t PopBack() noexcept
Removes the end element.
Represents an integer type. The internal representation is int64_t.
std::reverse_iterator< iterator > reverse_iterator
A reverse iterator.
int8_t GetExtType() const noexcept
Returns a signed 8-bit integer indicating the extended data type.
void * GetExtData() noexcept
Returns the pointer to the beginning of binary data.
uint32_t GetSize() const noexcept
Returns the number of stored elements.
MpObjectAsString(MpObject &obj) noexcept
const_reference at(size_t n) const noexcept
Returns a reference to the character at the specified position.
~MpObject() noexcept
Destructor.
const void * GetExt(int8_t *tp, uint32_t *n) const noexcept
Gets an extended data type from an object.
Represents an array. The internal representation is an array of MpObject.
const_reference front() const noexcept
Gets a reference to the first element.
const_iterator begin() const noexcept
Gets the read-only iterator pointing to the first element.
const_reference operator[](size_t n) const noexcept
The const decoration version of the above function.
Nlist< MpObjectKv >::iterator iterator
A forward iterator.
size_t max_size() const noexcept
Returns the length of the string. (The string length is not altered).
const void * GetBinary(uint32_t *n) const noexcept
Gets binary from an object.
errno_t Resize(size_t n) noexcept
Changes the number of elements for an associative array.
const nlib_utf8_t * GetString() const noexcept
The const decoration version of the above function.
const_iterator begin() const noexcept
Gets the read-only iterator pointing to the first element.
const_iterator end() const noexcept
Gets the read-only iterator pointing beyond the last element.
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are equal.
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are not equal.
const_reverse_iterator rend() const noexcept
Gets the read-only reverse iterator pointing ahead of the first element.
const nlib_utf8_t * data() const noexcept
Returns a C string.
errno_t Box(const T &v)
Boxes the object.
uint32_t GetSize() const noexcept
Returns the length of binary data.
MpObjectKv & reference
A reference to an element.
BaseType::const_iterator const_iterator
Read-only forward iterator.
Represents binary data only for msgpack.
const_reference operator[](size_t n) const noexcept
The const decoration version of the above function.
MpObjectAsBinary(MpObject &obj) noexcept
nlib_utf8_t & reference
A reference to an element.
Nlist< MpObjectKv >::const_iterator const_iterator
Read-only forward iterator.
Object created when MessagePack or JSON is read.
Represents a floating point type. The internal representation is float.
const MpObjectKv * const_pointer
Read-only pointer to an element.
MpObjectKv & assign(MpObjectKv &rhs, move_tag) noexcept
Corresponds to a move assignment operator.
iterator end() noexcept
Gets the iterator pointing beyond the last element.
const_iterator end() const noexcept
Gets the read-only iterator pointing beyond the last element.
reference operator[](size_t n) noexcept
Gets the nth element. n must be less than the number of stored elements.
errno_t PushBack(MpObject &&rhs) noexcept
Adds an element to the end of an array. The content in rhs is moved.
const_reverse_iterator rbegin() const noexcept
Gets the read-only reverse iterator pointing to the last element.
MpObject(MpObject &rhs, move_tag) noexcept
Corresponds to a move constructor.
MpObject(MpObject &&rhs) noexcept
Instantiates the object (move constructor).
errno_t PushBack(const nlib_utf8_t *key, MpObject &&value) noexcept
Adds a pair of the key and the value to the end of an associative array. The content in value is move...
MpObject & operator=(const T &x)
The value is passed into MpObject.
size_t length() const noexcept
Returns the length of the string.
MpObject second
Object used as a value.
const_iterator end() const noexcept
Gets the read-only iterator pointing beyond the last element.
Defines the class that resembles std::vector but can store objects that cannot be copied...
ObjectType
Data type of the object stored in MpObject.
const MpObject * const_pointer
Read-only pointer to an element.
errno_t Resize(size_t n) noexcept
Changes the number of elements for an array.
An empty structure indicating that an argument to a function needs to be moved.
bool IsExt() const noexcept
Determines whether the stored value is extended data.
errno_t Insert(size_t n, MpObject &&rhs) noexcept
Inserts rhs immediately before the nth element.
MpObject & operator=(MpObject &&rhs) noexcept
Move assignment operator.
errno_t InitArray(uint32_t n) noexcept
Initializes as an object with an n element array.
iterator begin() noexcept
Gets the iterator pointing to the first element.
Represents a floating point type. The internal representation is double.
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.
bool empty() const noexcept
Returns true for an empty string.
MpObjectAsMap(MpObject &obj) noexcept
reference front() noexcept
Gets a reference to the first element.
const nlib_utf8_t * c_str() const noexcept
Returns a C string.
#define NLIB_CATCH(x)
Defines catch(x) if exceptions are enabled. If not, defines if (true).
errno_t Erase(size_t n) noexcept
Removes the nth element.
errno_t Erase(size_t n) noexcept
Removes the pair of the nth key in an associative array and the value.
const_iterator begin() const noexcept
Gets the read-only iterator pointing to the first element.
nlib_utf8_t * iterator
A random-access iterator.
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...
const_reverse_iterator rend() const noexcept
Gets the read-only reverse iterator pointing ahead of the first element.
#define NLIB_TRY
Defines try if exceptions are enabled. If not, defines if (true).
nlib_byte_t & reference
A reference to an element.
ObjectType GetType() const noexcept
Returns the object type.
reverse_iterator rend() noexcept
Gets the reverse iterator pointing ahead of the first element.
BaseType::iterator iterator
A forward iterator.
errno_t PushBack(MpObjectKv &&rhs) noexcept
Adds a pair of the key and the value to the end of an associative array. The content in rhs is moved...
bool IsArray() const noexcept
Determines whether the stored value is an array.
MpObject(const T &x)
The constructor for boxing a T-type object.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
MpObjectAsExt(MpObject &obj) noexcept
const nlib_byte_t & const_reference
Read-only reference to an element.
const MpObjectKv & const_reference
Read-only reference to an element.
errno_t Unbox(nlib_utf8_t(&str)[n]) const noexcept
See Unbox(T (&a)[n]).
const MpObject * GetMapItem(const STDSTRING &str) const noexcept
The const decoration version of the above function.
A file that contains the configuration information for each development environment.
~MpObjectKv() noexcept
Destructor.
Represents a boolean type. The internal representation is a bool.
reverse_iterator rend() noexcept
Gets the reverse iterator pointing ahead of the first element.
uint32_t GetSize() const noexcept
Returns the size of the array, associative array, string, or binary.
iterator end() noexcept
Gets the iterator pointing beyond the last element.
MpObjectAsArray(MpObject &obj) noexcept
A container-like class similar to std::vector that can store objects that do not have copy constructo...
uint32_t GetSize() const noexcept
Returns the length of the string.
Nlist< MpObject >::iterator iterator
A forward iterator.
reference back() noexcept
Gets a reference to the last element.
errno_t RemoveMapItem(const STDSTRING &str, MpObjectKv *kv) noexcept
Specifies a key and deletes the corresponding key and object in the associative array.
MpObject & assign(MpObject &rhs, move_tag) noexcept
Assigns the object by using swap for a move.
Respresents a byte array (string).
const_iterator end() const noexcept
Gets the read-only iterator pointing beyond the last element.
const MpObject & const_reference
Read-only reference to an element.
static bool IsJsonPointer(const nlib_utf8_t *str) noexcept
A parameter omitted version of the above function which receives a null terminated string...
bool IsBoolean() const noexcept
Determines whether the stored value is a boolean.
Wraps functions like strlen and strcpy so they can be safely used.
bool IsFloat() const noexcept
Determines whether the stored value is a single precision float.
MpObject first
Object used as a key.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
MpObject * GetMapItem(const STDSTRING &str) noexcept
Specifies a string and gets the object in the associative array.
nlib_byte_t * iterator
A random-access iterator.
iterator begin() noexcept
Gets the iterator pointing to the first element.
uint32_t GetSize() const noexcept
Returns the number of stored elements.
bool IsDouble() const noexcept
Determines whether the stored value is a double.
A pair consisting of an MpObject-type key and value. Used to store an associative array...
reverse_iterator rbegin() noexcept
Gets the reverse iterator pointing to the last element.
const_reference operator[](size_t n) const noexcept
The const decoration version of the above function.
const_reference operator[](size_t n) const noexcept
The const decoration version of the above function.
const_iterator begin() const noexcept
Gets the read-only iterator pointing to the first element.
MpObject & reference
A reference to an element.
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...
reverse_iterator rbegin() noexcept
Gets the reverse iterator pointing to the last element.
iterator begin() noexcept
Gets the iterator pointing to the first element.
const nlib_utf8_t & const_reference
Read-only reference to an element.
errno_t PopBack() noexcept
Removes the end element.
Class that corresponds to nil in MessagePack and null in JSON.
MpObjectKv * pointer
Pointer to the element.
bool IsInteger() const noexcept
Determines whether the stored value is an integer.
bool IsBinary() const noexcept
Determines whether the stored value is binary.
Represents an associative array. The internal representation is an array of MpObject pairs...
MpObjectKv(MpObjectKv &rhs, move_tag) noexcept
Corresponds to a move constructor.
std::reverse_iterator< const_iterator > const_reverse_iterator
Read-only reverse iterator.
errno_t Unbox(T(&a)[n]) const
Unboxes the object value.
errno_t Box(MpObject *obj, const T &v)
This function template can be specialized to define boxing the user type.
Represents the extended data type only for msgpack.
Nlist< MpObject >::const_iterator const_iterator
Read-only forward iterator.
std::reverse_iterator< const_iterator > const_reverse_iterator
Read-only reverse iterator.
reference at(size_t n) noexcept
Returns a reference to the character at the specified position.