3 #ifndef INCLUDE_NN_NLIB_BINARYWRITER_H_
4 #define INCLUDE_NN_NLIB_BINARYWRITER_H_
7 #include "nn/nlib/Swap.h"
26 #define NLIB_BINW(tp) \
27 if (NLIB_LIKELY(m_Stream)) return this->Write_(static_cast<tp>(x)); \
53 bool WriteArray(
const unsigned long* x,
size_t n) NLIB_NOEXCEPT {
55 return this->
WriteArray(reinterpret_cast<const unsigned long long*>(x), n);
57 return this->
WriteArray(reinterpret_cast<const unsigned int*>(x), n);
63 bool WriteArray(
const signed char* x,
size_t n) NLIB_NOEXCEPT {
64 return this->
WriteArray(reinterpret_cast<const unsigned char*>(x), n);
67 return this->
WriteArray(reinterpret_cast<const unsigned char*>(x), n);
69 bool WriteArray(
const short* x,
size_t n) NLIB_NOEXCEPT {
70 return this->
WriteArray(reinterpret_cast<const unsigned short*>(x), n);
73 return this->
WriteArray(reinterpret_cast<const unsigned int*>(x), n);
77 return this->
WriteArray(reinterpret_cast<const unsigned long long*>(x), n);
79 return this->
WriteArray(reinterpret_cast<const unsigned int*>(x), n);
82 bool WriteArray(
const long long* x,
size_t n) NLIB_NOEXCEPT {
83 return this->
WriteArray(reinterpret_cast<const unsigned long long*>(x), n);
87 template <
class T,
size_t N>
89 bool Flush() NLIB_NOEXCEPT;
90 bool Close() NLIB_NOEXCEPT;
92 if (m_ErrorValue == 0) m_ErrorValue = e;
100 bool Write_(uint8_t x) NLIB_NOEXCEPT;
101 bool Write_(uint16_t x) NLIB_NOEXCEPT;
102 bool Write_(uint32_t x) NLIB_NOEXCEPT;
103 bool Write_(uint64_t x) NLIB_NOEXCEPT;
104 bool Write_(
float x) NLIB_NOEXCEPT;
105 bool Write_(
double x) NLIB_NOEXCEPT;
106 bool WriteStream() NLIB_NOEXCEPT;
109 unsigned char m_Buf[512];
110 unsigned char* m_Cur;
113 unsigned char m_SwapEndian;
118 namespace binary_writer {
139 template <
class T,
size_t N>
146 #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. ...
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
OutputStream * GetStream() noexcept
Gets the stream for the text writer to write to.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#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.
errno_t GetErrorValue() const noexcept
This function can get the cause of the error when writing has failed.
bool Write(float x) noexcept
Writes float-type data as binary to a stream. Returns true if successful.
bool Write(unsigned short x) noexcept
Writes unsigned short-type data as binary to a stream. Returns true if successful.
~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.
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...
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.
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.
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.
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...