3 #ifndef INCLUDE_NN_NLIB_BINARYREADER_H_
4 #define INCLUDE_NN_NLIB_BINARYREADER_H_
7 #include "nn/nlib/Swap.h"
26 #define NLIB_BINR(tp) \
27 if (NLIB_LIKELY(x)) return this->Read_(reinterpret_cast<tp*>(x)); \
28 NLIB_STATIC_ASSERT(sizeof(*x) == sizeof(tp)); \
52 if (m_Cur == m_BufEnd)
return -1;
57 if (m_Cur + n <= m_BufEnd) {
61 return this->Skip_(n);
71 return this->
ReadArray(reinterpret_cast<unsigned long long*>(x), n);
73 return this->
ReadArray(reinterpret_cast<unsigned int*>(x), n);
81 return this->
ReadArray(reinterpret_cast<unsigned char*>(x), n);
84 return this->
ReadArray(reinterpret_cast<unsigned char*>(x), n);
87 return this->
ReadArray(reinterpret_cast<unsigned short*>(x), n);
90 return this->
ReadArray(reinterpret_cast<unsigned int*>(x), n);
94 return this->
ReadArray(reinterpret_cast<unsigned long long*>(x), n);
96 return this->
ReadArray(reinterpret_cast<unsigned int*>(x), n);
100 return this->
ReadArray(reinterpret_cast<unsigned long long*>(x), n);
105 template <
class T,
size_t N>
113 if (m_ErrorValue == 0) m_ErrorValue = e;
120 bool Skip_(
size_t n) NLIB_NOEXCEPT;
121 bool Read_(uint8_t* x) NLIB_NOEXCEPT NLIB_NONNULL;
122 bool Read_(uint16_t* x) NLIB_NOEXCEPT NLIB_NONNULL;
123 bool Read_(uint32_t* x) NLIB_NOEXCEPT NLIB_NONNULL;
124 bool Read_(uint64_t* x) NLIB_NOEXCEPT NLIB_NONNULL;
125 bool Read_(
float* x) NLIB_NOEXCEPT {
130 if (!this->Read_(&v.i))
return false;
134 bool Read_(
double* x) NLIB_NOEXCEPT {
139 if (!this->Read_(&v.i))
return false;
143 void FillBuffer() NLIB_NOEXCEPT;
146 unsigned char m_Buf[512];
147 unsigned char* m_Cur;
148 unsigned char* m_BufEnd;
149 InputStream* m_Stream;
151 unsigned char m_SwapEndian;
155 namespace binary_reader {
176 template <
class T,
size_t N>
183 #endif // INCLUDE_NN_NLIB_BINARYREADER_H_
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
bool Read(unsigned long long *x) noexcept
ストリームからバイナリでunsigned long long型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool Skip(size_t n) noexcept
ストリームからn バイトを読み飛ばします。
size_t ReadArray(unsigned char *x, size_t n) noexcept
ストリームからバイナリでunsigned char型のデータ列を読み取ります。
bool Read(unsigned char *x) noexcept
ストリームからバイナリでunsigned char型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool Read(signed char *x) noexcept
ストリームからバイナリでsigned char型のデータを読み取ります。成功した場合はtrueを返します。 ...
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
size_t ReadArray(char *x, size_t n) noexcept
ストリームからバイナリでchar型のデータ列を読み取ります。
void SetError(errno_t e) noexcept
エラーを設定します。既にエラーが設定されている場合にはエラーは設定されません。
bool Read(int *x) noexcept
ストリームからバイナリでint型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool Read(double *x) noexcept
ストリームからバイナリでdouble型のデータを読み取ります。成功した場合はtrueを返します。 ...
BinaryReader() noexcept
デフォルトコンストラクタです。
bool Read(short *x) noexcept
ストリームからバイナリでshort型のデータを読み取ります。成功した場合はtrueを返します。 ...
size_t ReadArray(unsigned long *x, size_t n) noexcept
ストリームからバイナリでunsigned long型のデータ列を読み取ります。
size_t ReadArray(int *x, size_t n) noexcept
ストリームからバイナリでint型のデータ列を読み取ります。
bool Read(unsigned int *x) noexcept
ストリームからバイナリでunsigned int型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool Read(float *x) noexcept
ストリームからバイナリでfloat型のデータを読み取ります。成功した場合はtrueを返します。 ...
size_t ReadArray(long long *x, size_t n) noexcept
ストリームからバイナリでlong long型のデータ列を読み取ります。
bool Read(unsigned short *x) noexcept
ストリームからバイナリでunsigned short型のデータを読み取ります。成功した場合はtrueを返します。 ...
size_t ReadArray(short *x, size_t n) noexcept
ストリームからバイナリでshort型のデータ列を読み取ります。
EndianSetting
エンディアンを指定します。
bool Close() noexcept
バイナリリーダをクローズします。
errno_t GetErrorValue() const noexcept
書き込み等が失敗した際に、エラーの原因を取得できます。
size_t ReadArray(signed char *x, size_t n) noexcept
ストリームからバイナリでsigned char型のデータ列を読み取ります。
int Peek() noexcept
ストリームの先頭1バイトを参照します。
bool Read(BinaryReader *r, T *x)
この関数テンプレートを特殊化することで、ユーザー定義クラスに読み込むことができます。 ...
ストリーム(InputStream)からバイナリを読み込むクラスです。
bool Read(unsigned long *x) noexcept
ストリームからバイナリでunsigned long型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool Read(long *x) noexcept
ストリームからバイナリでlong型のデータを読み取ります。成功した場合はtrueを返します。 ...
~BinaryReader() noexcept
デストラクタです。ストリームをクローズしません。
size_t ReadArray(long *x, size_t n) noexcept
ストリームからバイナリでlong型のデータ列を読み取ります。
bool Read(long long *x) noexcept
ストリームからバイナリでlong long型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool Read(char *x) noexcept
ストリームからバイナリでchar型のデータを読み取ります。成功した場合はtrueを返します。 ...
bool ReadArray(BinaryReader *r, T *x, size_t n)
この関数テンプレートを特殊化することで、ユーザー定義クラスに読み込むことができます。 ...