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_];
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);
96 is_buf_ =
reinterpret_cast<unsigned char*
>(p);
97 is_bufsize_ =
static_cast<int>(nbytes);
100 if (errno_ == 0) errno_ = e;
104 virtual size_t FillBuffer_(
void* p,
size_t nbytes) NLIB_NOEXCEPT = 0;
105 virtual bool Close_() NLIB_NOEXCEPT = 0;
119 size_t is_buf_curidx_;
120 size_t is_buf_endidx_;
121 unsigned char* is_buf_;
136 char dummy_buf_[256];
138 virtual bool Close_()
NLIB_NOEXCEPT NLIB_OVERRIDE {
return true; }
152 if (cur_ + n > end_) {
154 size_t rem = end_ - cur_;
157 size_t nread = stream->Read(&buf_[rem], N - rem);
159 end_ = &buf_[0] + rem + nread;
160 return (nread + rem >= n);
167 size_t nread = stream->Read(&buf_[0], N);
170 end_ = &buf_[0] + nread;
178 size_t nread = stream->Read(&buf_[0], N);
181 end_ = &buf_[0] + nread;
200 size_t ReadBytes(IS* stream,
void* data,
size_t nbytes)
NLIB_NOEXCEPT {
201 if (cur_ + nbytes <= end_) {
206 uint8_t* p =
reinterpret_cast<uint8_t*
>(data);
207 size_t rem = end_ - cur_;
208 nlib_memcpy(reinterpret_cast<void*>(p), nbytes, cur_, rem);
209 cur_ = end_ = &buf_[0];
210 size_t nread = stream->Read(p + rem, nbytes - rem);
213 template<
class IS,
class T>
217 size_t nbytes =
sizeof(*data) * count;
218 size_t nread = ReadBytes(stream, data, nbytes);
220 size_t mod = nread %
sizeof(*data);
221 uint8_t* p =
reinterpret_cast<uint8_t*
>(data);
223 p + nread - mod, mod);
225 return nread /
sizeof(*data);
238 #endif // INCLUDE_NN_NLIB_INPUTSTREAM_H_ #define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Substitute definitions for the C++11 standard header type_traits. These substitute definitions are us...
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
#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...
Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger...
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_STATIC_ASSERT(exp)
Defines a static assertion. Uses static_assert if it is available for use.
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.