3 #ifndef INCLUDE_NN_NLIB_BINARYWRITER_H_ 4 #define INCLUDE_NN_NLIB_BINARYWRITER_H_ 7 #include "nn/nlib/Swap.h" 11 NLIB_EXPIMP_TEMPLATE(detail::MiniBufOut<512>);
20 swap_endian_(false) {}
26 #define NLIB_BINW(tp) return this->Write_(static_cast<tp>(x)) 27 bool Write(
char x) NLIB_NOEXCEPT { NLIB_BINW(uint8_t); }
28 bool Write(
signed char x) NLIB_NOEXCEPT { NLIB_BINW(uint8_t); }
29 bool Write(
unsigned char x) NLIB_NOEXCEPT { NLIB_BINW(uint8_t); }
30 bool Write(
short x) NLIB_NOEXCEPT { NLIB_BINW(uint16_t); }
31 bool Write(
unsigned short x) NLIB_NOEXCEPT { NLIB_BINW(uint16_t); }
32 bool Write(
int x) NLIB_NOEXCEPT { NLIB_BINW(uint32_t); }
33 bool Write(
unsigned int x) NLIB_NOEXCEPT { NLIB_BINW(uint32_t); }
36 bool Write(
long long x) NLIB_NOEXCEPT { NLIB_BINW(uint64_t); }
37 bool Write(
unsigned long long x) NLIB_NOEXCEPT { NLIB_BINW(uint64_t); }
38 bool Write(
float x) NLIB_NOEXCEPT { NLIB_BINW(
float); }
39 bool Write(
double x) NLIB_NOEXCEPT { NLIB_BINW(
double); }
49 bool WriteArray(
const unsigned long* x,
size_t n) NLIB_NOEXCEPT {
51 return this->
WriteArray(reinterpret_cast<const unsigned long long*>(x), n);
53 return this->
WriteArray(reinterpret_cast<const unsigned int*>(x), n);
59 bool WriteArray(
const signed char* x,
size_t n) NLIB_NOEXCEPT {
60 return this->
WriteArray(reinterpret_cast<const unsigned char*>(x), n);
63 return this->
WriteArray(reinterpret_cast<const unsigned char*>(x), n);
65 bool WriteArray(
const short* x,
size_t n) NLIB_NOEXCEPT {
66 return this->
WriteArray(reinterpret_cast<const unsigned short*>(x), n);
69 return this->
WriteArray(reinterpret_cast<const unsigned int*>(x), n);
73 return this->
WriteArray(reinterpret_cast<const unsigned long long*>(x), n);
75 return this->
WriteArray(reinterpret_cast<const unsigned int*>(x), n);
78 bool WriteArray(
const long long* x,
size_t n) NLIB_NOEXCEPT {
79 return this->
WriteArray(reinterpret_cast<const unsigned long long*>(x), n);
83 template <
class T,
size_t N>
88 if (errno_ == 0) errno_ = e;
108 detail::MiniBufOut<512> mini_buf_;
113 namespace binary_writer {
134 template <
class T,
size_t N>
141 #endif // INCLUDE_NN_NLIB_BINARYWRITER_H_ bool Write(unsigned long x) noexcept
Writes unsigned long-type data as binary to a stream. Returns true if successful. ...
OutputStream * GetStream() noexcept
Gets the stream for the text writer to write to.
#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...
bool WriteArray(const unsigned char *x, size_t n) noexcept
Writes an unsigned char-type array as binary to a stream. Returns true if successful. If n is 0, it will also successfully complete.
bool Write(float x) noexcept
Writes float-type data as binary to 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 Write(unsigned short x) noexcept
Writes unsigned short-type data as binary to a stream. Returns true if successful.
errno_t Init() noexcept
Initializes the binary writer using the same endianness as the machine the program is running on...
~BinaryWriter() noexcept
Destructor. This function does not close the stream.
bool Write(char x) noexcept
Writes char-type data as binary to a stream. Returns true if successful.
bool Write(BinaryWriter *w, T x)
You can write user-defined class objects by specializing this function template.
bool Write(unsigned int x) noexcept
Writes unsigned int-type data as binary to a stream. Returns true if successful.
bool Write(long long x) noexcept
Writes long long-type data as binary to a stream. Returns true if successful.
bool Write(unsigned char x) noexcept
Writes unsigned char-type data as binary to a stream. Returns true if successful. ...
bool WriteArray(BinaryWriter *w, const T *x, size_t n)
You can write user-defined class objects by specializing this function template.
void SetError(errno_t e) noexcept
Sets an error. If an error has been set already, this function does not set an error.
bool WriteArray(const long long *x, size_t n) noexcept
Writes a long long-type array as binary to a stream. Returns true if successful. If n is 0...
bool WriteArray(const long *x, size_t n) noexcept
Writes a long-type array as binary to a stream. Returns true if successful. If n is 0...
Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger...
bool Write(long x) noexcept
Writes long-type data as binary to a stream. Returns true if successful.
bool Write(int x) noexcept
Writes int-type data as binary to a stream. Returns true if successful.
bool Write(short x) noexcept
Writes short-type data as binary to a stream. Returns true if successful.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
A file that contains the configuration information for each development environment.
EndianSetting
Specifies the endianness.
bool WriteArray(const unsigned long *x, size_t n) noexcept
Writes an unsigned long-type array as binary to a stream. Returns true if successful. If n is 0, it will also successfully complete.
bool WriteArray(const int *x, size_t n) noexcept
Writes an int-type array as binary to a stream. Returns true if successful. If n is 0...
The class for writing binary to streams (to OutputStream).
bool Write(signed char x) noexcept
Writes signed char-type data as binary to a stream. Returns true if successful.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
bool WriteArray(const signed char *x, size_t n) noexcept
Writes a signed char-type array as binary to a stream. Returns true if successful. If n is 0, it will also successfully complete.
Defines the base class for output streams.
bool WriteArray(const char *x, size_t n) noexcept
Writes a char-type array as binary to a stream. Returns true if successful. If n is 0...
BinaryWriter() noexcept
Instantiates the object with default parameters (default constructor).
bool Write(double x) noexcept
Writes double-type data as binary to a stream. Returns true if successful.
The base class for output streams. This class cannot be instantiated.
bool Write(unsigned long long x) noexcept
Writes unsigned long long-type data as binary to a stream. Returns true if successful.
bool WriteArray(const short *x, size_t n) noexcept
Writes a short-type array as binary to a stream. Returns true if successful. If n is 0...