nlib
JsonWriter.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONWRITER_H_
4 #define INCLUDE_NN_NLIB_MSGPACK_JSONWRITER_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 class OutputStream;
15 namespace msgpack {
16 class MpObject;
17 
19  public:
20  enum Option {
21  OPTION_DEFAULT = 0x00000000,
22  OPTION_RELAXED = 0x00000001
23  };
24  JsonWriter() NLIB_NOEXCEPT : m_ErrorValue(0), m_Stream(NULL) {}
25  ~JsonWriter() NLIB_NOEXCEPT { this->Close(); }
26  bool Init(OutputStream* stream) NLIB_NOEXCEPT NLIB_NONNULL;
27  bool Flush() NLIB_NOEXCEPT;
28  bool Close() NLIB_NOEXCEPT;
29  errno_t GetErrorValue() const NLIB_NOEXCEPT { return m_ErrorValue; }
30 
31  public:
32  bool Write(const MpObject& obj, uint32_t option = 0) NLIB_NOEXCEPT;
33  OutputStream* GetStream() NLIB_NOEXCEPT { return m_Stream; }
34 
35  static bool Write(char* str, size_t n, const MpObject& obj,
36  uint32_t option = 0) NLIB_NOEXCEPT NLIB_NONNULL;
37  template <size_t n>
38  static bool Write(char (&str)[n], const MpObject& obj, uint32_t option = 0) NLIB_NOEXCEPT {
39  return Write(&str[0], n, obj, option);
40  }
41  NLIB_SAFE_BOOL(JsonWriter, GetErrorValue() == 0);
42 
43  private:
44  NLIB_VIS_HIDDEN bool Write_(const MpObject& obj) NLIB_NOEXCEPT;
45  void SetError(errno_t e) NLIB_NOEXCEPT {
46  if (m_ErrorValue == 0) m_ErrorValue = e;
47  }
48  NLIB_VIS_HIDDEN bool WriteString(const char* p, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
49 
50  private:
51  errno_t m_ErrorValue;
52  OutputStream* m_Stream;
54 };
55 
56 } // namespace msgpack
57 NLIB_NAMESPACE_END
58 
59 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
60 #undef NLIB_VIS_PUBLIC
61 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
62 #endif
63 
64 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONWRITER_H_
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Platform.h:2151
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
Definition: Platform_unix.h:66
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:126
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:141
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:50
~JsonWriter() noexcept
デストラクタです。
Definition: JsonWriter.h:25
MessagePack又はJSONを読み込むことで作成されるオブジェクトです。
Definition: MpObject.h:83
bool Write(BinaryWriter *w, T x)
この関数テンプレートを特殊化することで、ユーザー定義クラスを書きこむことができます。 ...
Definition: BinaryWriter.h:121
JsonWriter() noexcept
デフォルトコンストラクタです。
Definition: JsonWriter.h:24
JSONのジェネレータです。MpObjectをJSONに変換してストリームに書き出します。
Definition: JsonWriter.h:18
開発環境別の設定が書かれるファイルです。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:51
Option
Write()に渡すことのできるオプション値が定義されています。
Definition: JsonWriter.h:20
出力ストリームの基底クラスです。このクラスを実体化することはできません。
Definition: OutputStream.h:17
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:24