16 #ifndef INCLUDE_NN_NLIB_INPUTSTREAM_H_ 17 #define INCLUDE_NN_NLIB_INPUTSTREAM_H_ 49 if (*
this && is_buf_curidx_ == is_buf_endidx_) {
51 return *
this && is_buf_curidx_ == is_buf_endidx_;
59 if (
NLIB_UNLIKELY(is_buf_curidx_ == is_buf_endidx_))
return -1;
61 return is_buf_[is_buf_curidx_++];
67 if (
NLIB_UNLIKELY(is_buf_curidx_ == is_buf_endidx_))
return -1;
69 return is_buf_[is_buf_curidx_];
73 size_t Read(
void* ptr,
size_t nbytes) NLIB_NOEXCEPT {
74 #ifndef NLIB_NONNULL_ENABLED 76 this->SetError(EINVAL);
81 this->SetError(EINVAL);
84 if (is_buf_curidx_ + nbytes <= is_buf_endidx_) {
85 nlib_memcpy(ptr, nbytes, &is_buf_[is_buf_curidx_], nbytes);
86 is_buf_curidx_ += nbytes;
89 return this->Read_(ptr, nbytes);
98 is_buf_ =
static_cast<unsigned char*
>(p);
99 is_bufsize_ =
static_cast<int>(nbytes);
102 if (errno_ == 0) errno_ = e;
106 virtual size_t FillBuffer_(
void* p,
size_t nbytes) NLIB_NOEXCEPT = 0;
107 virtual bool Close_() NLIB_NOEXCEPT = 0;
121 size_t is_buf_curidx_;
122 size_t is_buf_endidx_;
123 unsigned char* is_buf_;
138 char dummy_buf_[256];
140 virtual bool Close_()
NLIB_NOEXCEPT NLIB_OVERRIDE {
return true; }
154 if (cur_ + n > end_) {
156 size_t rem = end_ - cur_;
159 size_t nread = stream->Read(&buf_[rem], N - rem);
161 end_ = &buf_[0] + rem + nread;
162 return (nread + rem >= n);
169 size_t nread = stream->Read(&buf_[0], N);
172 end_ = &buf_[0] + nread;
179 size_t nread = stream->Read(&buf_[0], N);
182 end_ = &buf_[0] + nread;
201 size_t ReadBytes(IS* stream,
void* data,
size_t nbytes)
NLIB_NOEXCEPT {
202 if (cur_ + nbytes <= end_) {
207 uint8_t* p =
static_cast<uint8_t*
>(data);
208 size_t rem = end_ - cur_;
209 nlib_memcpy(static_cast<void*>(p), nbytes, cur_, rem);
210 cur_ = end_ = &buf_[0];
211 size_t nread = stream->Read(p + rem, nbytes - rem);
214 template<
class IS,
class T>
218 size_t nbytes =
sizeof(*data) * count;
219 size_t nread = ReadBytes(stream, data, nbytes);
221 size_t mod = nread %
sizeof(*data);
222 uint8_t* p =
static_cast<uint8_t*
>(
static_cast<void*
>(data));
224 p + nread - mod, mod);
226 return nread /
sizeof(*data);
239 #endif // INCLUDE_NN_NLIB_INPUTSTREAM_H_ #define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
C++11の標準ヘッダとなるtype_traitsの代用定義です。 コンパイラや標準ライブラリによってサポートされてい...
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
errno_tをラップするクラスです。Visual Studioのデバッガ上での表示を改善します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
bool Read(BinaryReader *r, T *x)
この関数テンプレートを特殊化することで、ユーザー定義クラスに読み込むことができます。 ...