3 #ifndef INCLUDE_NN_NLIB_BINARYREADER_H_ 4 #define INCLUDE_NN_NLIB_BINARYREADER_H_ 7 #include "nn/nlib/Swap.h" 11 NLIB_EXPIMP_TEMPLATE(detail::MiniBufIn<512>);
20 swap_endian_(false) {}
26 #define NLIB_BINR(tp) return this->Read_(reinterpret_cast<tp*>(x)) 28 bool Read(
char* x) NLIB_NOEXCEPT { NLIB_BINR(uint8_t); }
29 bool Read(
signed char* x) NLIB_NOEXCEPT { NLIB_BINR(uint8_t); }
30 bool Read(
unsigned char* x) NLIB_NOEXCEPT { NLIB_BINR(uint8_t); }
31 bool Read(
short* x) NLIB_NOEXCEPT { NLIB_BINR(uint16_t); }
32 bool Read(
unsigned short* x) NLIB_NOEXCEPT { NLIB_BINR(uint16_t); }
33 bool Read(
int* x) NLIB_NOEXCEPT { NLIB_BINR(uint32_t); }
34 bool Read(
unsigned int* x) NLIB_NOEXCEPT { NLIB_BINR(uint32_t); }
37 bool Read(
long long* x) NLIB_NOEXCEPT { NLIB_BINR(uint64_t); }
38 bool Read(
unsigned long long* x) NLIB_NOEXCEPT { NLIB_BINR(uint64_t); }
39 bool Read(
float* x) NLIB_NOEXCEPT { NLIB_BINR(
float); }
40 bool Read(
double* x) NLIB_NOEXCEPT { NLIB_BINR(
double); }
46 return mini_buf_.Peek(stream_);
48 bool Skip(
size_t n) NLIB_NOEXCEPT {
49 size_t rem = mini_buf_.size();
54 mini_buf_.Advance(rem);
56 return this->Skip_(n);
65 size_t ReadArray(
unsigned long* x,
size_t n) NLIB_NOEXCEPT {
67 return this->
ReadArray(reinterpret_cast<unsigned long long*>(x), n);
69 return this->
ReadArray(reinterpret_cast<unsigned int*>(x), n);
76 size_t ReadArray(
signed char* x,
size_t n) NLIB_NOEXCEPT {
77 return this->
ReadArray(reinterpret_cast<unsigned char*>(x), n);
80 return this->
ReadArray(reinterpret_cast<unsigned char*>(x), n);
82 size_t ReadArray(
short* x,
size_t n) NLIB_NOEXCEPT {
83 return this->
ReadArray(reinterpret_cast<unsigned short*>(x), n);
86 return this->
ReadArray(reinterpret_cast<unsigned int*>(x), n);
90 return this->
ReadArray(reinterpret_cast<unsigned long long*>(x), n);
92 return this->
ReadArray(reinterpret_cast<unsigned int*>(x), n);
95 size_t ReadArray(
long long* x,
size_t n) NLIB_NOEXCEPT {
96 return this->
ReadArray(reinterpret_cast<unsigned long long*>(x), n);
101 template <
class T,
size_t N>
109 if (errno_ == 0) errno_ = e;
121 bool Read_(
float* x) NLIB_NOEXCEPT {
126 if (!this->Read_(&v.i))
return false;
130 bool Read_(
double* x) NLIB_NOEXCEPT {
135 if (!this->Read_(&v.i))
return false;
144 detail::MiniBufIn<512> mini_buf_;
149 namespace binary_reader {
170 template <
class T,
size_t N>
177 #endif // INCLUDE_NN_NLIB_BINARYREADER_H_ bool Read(unsigned long long *x) noexcept
Reads unsigned long long-type data as binary from a stream. Returns true if successful.
bool Skip(size_t n) noexcept
Skips over n bytes when reading from stream.
size_t ReadArray(unsigned char *x, size_t n) noexcept
Reads an unsigned char-type data string as binary from a stream.
bool Read(unsigned char *x) noexcept
Reads unsigned char-type data as binary from a stream. Returns true if successful.
errno_t GetErrorValue() const noexcept
This function can get the cause of the error when writing has failed.
bool Read(signed char *x) noexcept
Reads signed char-type data as binary from a stream. Returns true if successful.
#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...
size_t ReadArray(char *x, size_t n) noexcept
Reads a char-type data string as binary from a stream.
void SetError(errno_t e) noexcept
Sets an error. If an error has been set already, this function does not set an error.
bool Read(int *x) noexcept
Reads int-type data as binary from a stream. Returns true if successful.
bool Read(double *x) noexcept
Reads double-type data as binary from a stream. Returns true if successful.
BinaryReader() noexcept
Instantiates the object with default parameters (default constructor).
bool Read(short *x) noexcept
Reads short-type data as binary from a stream. Returns true if successful.
size_t ReadArray(unsigned long *x, size_t n) noexcept
Reads an unsigned long-type data string as binary from a stream.
size_t ReadArray(int *x, size_t n) noexcept
Reads an int-type data string as binary from a stream.
Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger...
bool Read(unsigned int *x) noexcept
Reads unsigned int-type data as binary from a stream. Returns true if successful. ...
bool Read(float *x) noexcept
Reads float-type data as binary from a stream. Returns true if successful.
size_t ReadArray(long long *x, size_t n) noexcept
Reads a long long-type data string as binary from a stream.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
A file that contains the configuration information for each development environment.
bool Read(unsigned short *x) noexcept
Reads unsigned short-type data as binary from a stream. Returns true if successful.
size_t ReadArray(short *x, size_t n) noexcept
Reads a short-type data string as binary from a stream.
EndianSetting
Specifies the endianness.
bool Close() noexcept
Closes the binary reader.
size_t ReadArray(signed char *x, size_t n) noexcept
Reads a signed char-type data string as binary from a stream.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
int Peek() noexcept
References the first byte of the stream.
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.
The class for reading binary from streams (from InputStream).
bool Read(unsigned long *x) noexcept
Reads unsigned long-type data as binary from a stream. Returns true if successful.
errno_t Init() noexcept
Initializes the binary reader using the same endianness as the machine the program is running on...
bool Read(long *x) noexcept
Reads long-type data as binary from a stream. Returns true if successful.
~BinaryReader() noexcept
Destructor. This function does not close the stream.
size_t ReadArray(long *x, size_t n) noexcept
Reads a long-type data string as binary from a stream.
bool Read(long long *x) noexcept
Reads long long-type data as binary from a stream. Returns true if successful.
bool Read(char *x) noexcept
Reads char-type data as binary from a stream. Returns true if successful.
bool ReadArray(BinaryReader *r, T *x, size_t n)
You can read to user-defined class objects by specializing this function template.