nlib
MpWalker.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_MPWALKER_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_MPWALKER_H_
18 
19 #include "nn/nlib/Config.h"
20 #include "nn/nlib/Swap.h"
21 
22 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
23 #undef NLIB_VIS_PUBLIC
24 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
25 #endif
26 
27 NLIB_NAMESPACE_BEGIN
28 namespace msgpack {
29 
30 class MpObject;
32  public:
33  MpWalker() NLIB_NOEXCEPT : cur_(NULL), size_(0) {}
35  MpWalker(const void* p, size_t n) NLIB_NOEXCEPT;
36  bool Init(const void* p, size_t n) NLIB_NOEXCEPT NLIB_NONNULL {
37  if (n > RSIZE_MAX) return false;
38  cur_ = reinterpret_cast<const uint8_t*>(p);
39  size_ = n;
40  return true;
41  }
42 
43  MpWalker operator[](size_t array_idx) const NLIB_NOEXCEPT;
44  MpWalker operator[](const nlib_utf8_t* key) const NLIB_NOEXCEPT NLIB_NONNULL;
45  MpWalker operator[](int array_idx) const NLIB_NOEXCEPT {
46  if (array_idx < 0)
47  return MpWalker();
48  else
49  return operator[](static_cast<size_t>(array_idx));
50  }
51 
52  const void* GetPtr() const NLIB_NOEXCEPT { return cur_; }
53  size_t GetSize() const NLIB_NOEXCEPT { return size_; }
54 
55  MpWalker At(size_t idx) const NLIB_NOEXCEPT;
56  MpWalker At(size_t idx, const nlib_utf8_t** key, size_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
57  MpWalker Find(const nlib_utf8_t* key) const NLIB_NOEXCEPT NLIB_NONNULL;
58  MpWalker Skip() const NLIB_NOEXCEPT;
59  MpWalker GetString(const nlib_utf8_t** str, uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
60  MpWalker GetBinary(const void** bin, uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
61  MpWalker GetExt(int8_t* tp, const void** bin, uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
62  MpWalker GetMapCount(uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
63  MpWalker GetArrayCount(uint32_t* n) const NLIB_NOEXCEPT NLIB_NONNULL;
64  MpWalker GetNil() const NLIB_NOEXCEPT;
65  MpWalker GetBoolean(bool* val) const NLIB_NOEXCEPT NLIB_NONNULL;
66  MpWalker GetInt(int32_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
67  MpWalker GetInt(int64_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
68  MpWalker GetUint(uint32_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
69  MpWalker GetUint(uint64_t* val) const NLIB_NOEXCEPT NLIB_NONNULL;
70  MpWalker GetFloat(float* val) const NLIB_NOEXCEPT NLIB_NONNULL;
71  MpWalker GetDouble(double* val) const NLIB_NOEXCEPT NLIB_NONNULL;
72  NLIB_SAFE_BOOL(MpWalker, IsOk())
73 
74  private:
75  bool IsOk() const NLIB_NOEXCEPT { return cur_ != NULL; }
76 
77  const uint8_t* cur_;
78  size_t size_;
79 };
80 
81 } // namespace msgpack
82 NLIB_NAMESPACE_END
83 
84 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
85 #undef NLIB_VIS_PUBLIC
86 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
87 #endif
88 
89 #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:178
MpWalker() noexcept
Instantiates the object with default parameters (default constructor).
Definition: MpWalker.h:33
#define RSIZE_MAX
Defines a value somewhat smaller than the maximum value of size_t.
Definition: Platform.h:216
size_t GetSize() const noexcept
Gets the size of the MessagePack data.
Definition: MpWalker.h:53
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
MpWalker operator[](int array_idx) const noexcept
The same as operator[](size_t array_idx).
Definition: MpWalker.h:45
const void * GetPtr() const noexcept
Gets a pointer to the current location of MessagePack data.
Definition: MpWalker.h:52
#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:31
bool Init(const void *p, size_t n) noexcept
Initialize with this function when using the default constructor.
Definition: MpWalker.h:36
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
~MpWalker() noexcept
Destructor.
Definition: MpWalker.h:34
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:300