nlib
MpWalker.h
[詳解]
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)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:178
MpWalker() noexcept
デフォルトコンストラクタです。
Definition: MpWalker.h:33
#define RSIZE_MAX
size_tの最大値よりいくらか小さい値が定義されています。
Definition: Platform.h:216
size_t GetSize() const noexcept
MessagePackデータのサイズを取得します。
Definition: MpWalker.h:53
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
MpWalker operator[](int array_idx) const noexcept
operator[](size_t array_idx) と同様です。
Definition: MpWalker.h:45
const void * GetPtr() const noexcept
MessagePackデータの現在位置へのポインタを取得します。
Definition: MpWalker.h:52
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
開発環境別の設定が書かれるファイルです。
メモリ上に展開されたMessagePackのデータに高速にアクセスします。
Definition: MpWalker.h:31
bool Init(const void *p, size_t n) noexcept
デフォルトコンストラクタを利用した場合はこの関数で初期化します。
Definition: MpWalker.h:36
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:229
~MpWalker() noexcept
デストラクタです。
Definition: MpWalker.h:34
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:300