3 #ifndef INCLUDE_NN_NLIB_INPUTSTREAM_H_ 4 #define INCLUDE_NN_NLIB_INPUTSTREAM_H_ 36 if (*
this && is_buf_curidx_ == is_buf_endidx_) {
38 return *
this && is_buf_curidx_ == is_buf_endidx_;
46 if (
NLIB_UNLIKELY(is_buf_curidx_ == is_buf_endidx_))
return -1;
48 return is_buf_[is_buf_curidx_++];
54 if (
NLIB_UNLIKELY(is_buf_curidx_ == is_buf_endidx_))
return -1;
56 return is_buf_[is_buf_curidx_];
61 #ifndef NLIB_NONNULL_ENABLED 63 this->SetError(EINVAL);
68 this->SetError(EINVAL);
71 if (is_buf_curidx_ + nbytes <= is_buf_endidx_) {
72 nlib_memcpy(ptr, nbytes, &is_buf_[is_buf_curidx_], nbytes);
73 is_buf_curidx_ += nbytes;
76 return this->Read_(ptr, nbytes);
83 is_buf_ =
reinterpret_cast<unsigned char*
>(p);
84 is_bufsize_ =
static_cast<int>(nbytes);
87 if (errno_ == 0) errno_ = e;
91 virtual size_t FillBuffer_(
void* p,
size_t nbytes) NLIB_NOEXCEPT = 0;
92 virtual bool Close_() NLIB_NOEXCEPT = 0;
106 size_t is_buf_curidx_;
107 size_t is_buf_endidx_;
108 unsigned char* is_buf_;
123 char dummy_buf_[256];
125 virtual bool Close_()
NLIB_NOEXCEPT NLIB_OVERRIDE {
return true; }
139 if (cur_ + n > end_) {
141 size_t rem = end_ - cur_;
144 size_t nread = stream->Read(&buf_[rem], N - rem);
146 end_ = &buf_[0] + rem + nread;
147 return (nread + rem >= n);
154 size_t nread = stream->Read(&buf_[0], N);
157 end_ = &buf_[0] + nread;
165 size_t nread = stream->Read(&buf_[0], N);
168 end_ = &buf_[0] + nread;
187 size_t ReadBytes(IS* stream,
void* data,
size_t nbytes)
NLIB_NOEXCEPT {
188 if (cur_ + nbytes <= end_) {
193 uint8_t* p =
reinterpret_cast<uint8_t*
>(data);
194 size_t rem = end_ - cur_;
195 nlib_memcpy(reinterpret_cast<void*>(p), nbytes, cur_, rem);
196 cur_ = end_ = &buf_[0];
197 size_t nread = stream->Read(p + rem, nbytes - rem);
200 template<
class IS,
class T>
204 size_t nbytes =
sizeof(*data) * count;
205 size_t nread = ReadBytes(stream, data, nbytes);
207 size_t mod = nread %
sizeof(*data);
208 uint8_t* p =
reinterpret_cast<uint8_t*
>(data);
210 p + nread - mod, mod);
212 return nread /
sizeof(*data);
225 #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.