nlib
MpWalker.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
4 #define INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
5 
6 #include "nn/nlib/Config.h"
7 
8 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
9 #undef NLIB_VIS_PUBLIC
10 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
11 #endif
12 
13 NLIB_NAMESPACE_BEGIN
14 namespace msgpack {
15 
16 class MpObject;
18  public:
19  MpWalker() NLIB_NOEXCEPT : m_Cur(NULL), m_nBytes(0) {}
21  MpWalker(const void* p, size_t n) NLIB_NOEXCEPT;
22  bool Init(const void* p, size_t n) NLIB_NOEXCEPT NLIB_NONNULL {
23  if (n > RSIZE_MAX) return false;
24  m_Cur = reinterpret_cast<const uint8_t*>(p);
25  m_nBytes = n;
26  return true;
27  }
28 
29  MpWalker operator[](size_t array_idx) const NLIB_NOEXCEPT;
30  MpWalker operator[](const char* key) const NLIB_NOEXCEPT NLIB_NONNULL;
31  MpWalker operator[](int array_idx) const NLIB_NOEXCEPT {
32  if (array_idx < 0)
33  return MpWalker();
34  else
35  return operator[](static_cast<size_t>(array_idx));
36  }
37  const void* GetRaw(uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
38 
39  const void* GetPtr() const NLIB_NOEXCEPT { return m_Cur; }
40  size_t GetSize() const NLIB_NOEXCEPT { return m_nBytes; }
41 
42  NLIB_SAFE_BOOL(MpWalker, IsOk())
43 
44  private:
45  bool IsOk() const NLIB_NOEXCEPT { return m_Cur != NULL && m_nBytes > 0; }
46 
47  const uint8_t* m_Cur;
48  size_t m_nBytes;
49 };
50 
51 } // namespace msgpack
52 NLIB_NAMESPACE_END
53 
54 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
55 #undef NLIB_VIS_PUBLIC
56 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
57 #endif
58 
59 #endif // INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
Definition: Platform_unix.h:66
#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:141
MpWalker() noexcept
Instantiates the object with default parameters (default constructor).
Definition: MpWalker.h:19
#define RSIZE_MAX
Defines a value somewhat smaller than the maximum value of size_t.
Definition: Platform.h:295
MpWalker operator[](int array_idx) const noexcept
The same as operator[](size_t array_idx).
Definition: MpWalker.h:31
A file that contains the configuration information for each development environment.
Quickly accesses MessagePack expanded in memory.
Definition: MpWalker.h:17
bool Init(const void *p, size_t n) noexcept
Initialize with this function when using the default constructor.
Definition: MpWalker.h:22
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
const void * GetPtr() const noexcept
Gets a pointer to the current location of MessagePack data.
Definition: MpWalker.h:39
~MpWalker() noexcept
Destructor.
Definition: MpWalker.h:20
size_t GetSize() const noexcept
Gets the size of the MessagePack data.
Definition: MpWalker.h:40