nlib
MpWalker.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
18 
19 #include "nn/nlib/Config.h"
20 
21 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
22 #undef NLIB_VIS_PUBLIC
23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
24 #endif
25 
26 NLIB_NAMESPACE_BEGIN
27 namespace msgpack {
28 
29 class MpObject;
31  public:
32  MpWalker() NLIB_NOEXCEPT : cur_(NULL), size_(0) {}
34  MpWalker(const void* p, size_t n) NLIB_NOEXCEPT;
35  bool Init(const void* p, size_t n) NLIB_NOEXCEPT NLIB_NONNULL {
36  if (n > RSIZE_MAX) return false;
37  cur_ = reinterpret_cast<const uint8_t*>(p);
38  size_ = n;
39  return true;
40  }
41 
42  MpWalker operator[](size_t array_idx) const NLIB_NOEXCEPT;
43  MpWalker operator[](const char* key) const NLIB_NOEXCEPT NLIB_NONNULL;
44  MpWalker operator[](int array_idx) const NLIB_NOEXCEPT {
45  if (array_idx < 0)
46  return MpWalker();
47  else
48  return operator[](static_cast<size_t>(array_idx));
49  }
50 
51  const void* GetPtr() const NLIB_NOEXCEPT { return cur_; }
52  size_t GetSize() const NLIB_NOEXCEPT { return size_; }
53 
54  MpWalker At(size_t idx) const NLIB_NOEXCEPT;
55  MpWalker At(size_t idx, const char** key, size_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
56  MpWalker Find(const char* key) const NLIB_NOEXCEPT NLIB_NONNULL;
57  MpWalker Skip() const NLIB_NOEXCEPT;
58  MpWalker GetString(const char** str, uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
59  MpWalker GetBinary(const void** bin, uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
60  MpWalker GetExt(int8_t* tp, const void** bin, uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
61  MpWalker GetMapCount(uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
62  MpWalker GetArrayCount(uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
63  MpWalker GetNil() const NLIB_NOEXCEPT;
64  MpWalker GetBoolean(bool* val) const NLIB_NOEXCEPT NLIB_NONNULL;
65  MpWalker GetInt(int32_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
66  MpWalker GetInt(int64_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
67  MpWalker GetUint(uint32_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
68  MpWalker GetUint(uint64_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
69  MpWalker GetFloat(float* val) const NLIB_NOEXCEPT NLIB_NONNULL;
70  MpWalker GetDouble(double* val) const NLIB_NOEXCEPT NLIB_NONNULL;
71  NLIB_SAFE_BOOL(MpWalker, IsOk())
72 
73  private:
74  bool IsOk() const NLIB_NOEXCEPT { return cur_ != NULL && size_ > 0; }
75 
76  const uint8_t* cur_;
77  size_t size_;
78 };
79 
80 } // namespace msgpack
81 NLIB_NAMESPACE_END
82 
83 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
84 #undef NLIB_VIS_PUBLIC
85 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
86 #endif
87 
88 #endif // INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:173
MpWalker() noexcept
Instantiates the object with default parameters (default constructor).
Definition: MpWalker.h:32
#define RSIZE_MAX
Defines a value somewhat smaller than the maximum value of size_t.
Definition: Platform.h:553
size_t GetSize() const noexcept
Gets the size of the MessagePack data.
Definition: MpWalker.h:52
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
MpWalker operator[](int array_idx) const noexcept
The same as operator[](size_t array_idx).
Definition: MpWalker.h:44
const void * GetPtr() const noexcept
Gets a pointer to the current location of MessagePack data.
Definition: MpWalker.h:51
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
A file that contains the configuration information for each development environment.
Quickly accesses MessagePack expanded in memory.
Definition: MpWalker.h:30
bool Init(const void *p, size_t n) noexcept
Initialize with this function when using the default constructor.
Definition: MpWalker.h:35
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:224
~MpWalker() noexcept
Destructor.
Definition: MpWalker.h:33
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.