16 #ifndef INCLUDE_NN_NLIB_INPUTSTREAM_H_ 17 #define INCLUDE_NN_NLIB_INPUTSTREAM_H_ 34 is_buf_markidx_(static_cast<
size_t>(-1)),
37 is_buf_readonly_(false),
38 is_mark_supported_(false),
44 is_buf_markidx_(static_cast<size_t>(-1)),
47 is_buf_readonly_(is_buf_readonly),
48 is_mark_supported_(is_mark_supported),
62 if (*
this && is_buf_curidx_ == is_buf_endidx_) {
64 return *
this && is_buf_curidx_ == is_buf_endidx_;
72 if (
NLIB_UNLIKELY(is_buf_curidx_ == is_buf_endidx_))
return -1;
74 return is_buf_[is_buf_curidx_++];
80 if (
NLIB_UNLIKELY(is_buf_curidx_ == is_buf_endidx_))
return -1;
82 return is_buf_[is_buf_curidx_];
87 #ifndef NLIB_NONNULL_ENABLED 89 this->SetError(EINVAL);
94 this->SetError(EINVAL);
97 if (is_buf_curidx_ + nbytes <= is_buf_endidx_) {
98 nlib_memcpy(ptr, nbytes, &is_buf_[is_buf_curidx_], nbytes);
99 is_buf_curidx_ += nbytes;
102 return this->Read_(ptr, nbytes);
106 return Read(&buf[0], N);
116 SetBuffer(
void* p,
size_t nbytes,
bool is_mark_supported,
bool is_buf_readonly)
NLIB_NOEXCEPT {
117 NLIB_ASSERT(is_buf_readonly || !is_mark_supported);
119 NLIB_ASSERT(!is_mark_supported_ || is_buf_readonly_ || nbytes >= 1024);
120 is_buf_ =
static_cast<unsigned char*
>(p);
121 is_bufsize_ =
static_cast<int>(nbytes);
122 is_mark_supported_ = is_mark_supported;
123 is_buf_readonly_ = is_buf_readonly;
127 NLIB_ASSERT(!is_mark_supported_ || is_buf_readonly_ || nbytes >= 1024);
128 is_buf_ =
static_cast<unsigned char*
>(p);
129 is_bufsize_ =
static_cast<int>(nbytes);
132 if (errno_ == 0) errno_ = e;
136 virtual size_t FillBuffer_(
void* p,
size_t nbytes)
NLIB_NOEXCEPT = 0;
148 size_t is_buf_curidx_;
149 size_t is_buf_endidx_;
150 size_t is_buf_markidx_;
151 unsigned char* is_buf_;
153 bool is_buf_readonly_;
154 bool is_mark_supported_;
168 char dummy_buf_[256];
184 if (cur_ + n > end_) {
186 size_t rem = end_ - cur_;
187 nlib_memmove(static_cast<void*>(&buf_[0]), N, cur_, rem);
188 size_t nread = stream->Read(&buf_[rem], N - rem);
190 end_ = &buf_[0] + rem + nread;
191 return (nread + rem >= n);
198 size_t nread = stream->Read(&buf_[0], N);
201 end_ = &buf_[0] + nread;
208 size_t nread = stream->Read(&buf_[0], N);
211 end_ = &buf_[0] + nread;
230 if (cur_ + nbytes <= end_) {
231 nlib_memcpy(data, nbytes, cur_, nbytes);
235 uint8_t* p =
static_cast<uint8_t*
>(data);
236 size_t rem = end_ - cur_;
237 nlib_memcpy(static_cast<void*>(p), nbytes, cur_, rem);
238 cur_ = end_ = &buf_[0];
239 size_t nread = stream->Read(p + rem, nbytes - rem);
242 template<
class IS,
class T>
246 size_t nbytes =
sizeof(*data) * count;
247 size_t nread = ReadBytes(stream, data, nbytes);
249 size_t mod = nread %
sizeof(*data);
250 uint8_t* p =
static_cast<uint8_t*
>(
static_cast<void*
>(data));
251 nlib_memcpy(static_cast<void*>(&buf_[0]), N, p + nread - mod, mod);
253 return nread /
sizeof(*data);
266 #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.