3 #ifndef INCLUDE_NN_NLIB_REALLOCOUTPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_REALLOCOUTPUTSTREAM_H_
16 typedef void (*FreeFunc)(
void* ptr);
18 explicit FreeDeleter(FreeFunc freefunc)
NLIB_NOEXCEPT : m_Free(freefunc) {}
35 class ReallocDeleter {
37 typedef void* (*ReallocFunc)(
void* ptr,
size_t n);
39 explicit ReallocDeleter(ReallocFunc reallocfunc)
NLIB_NOEXCEPT : m_Realloc(reallocfunc) {}
42 m_Realloc = rhs.m_Realloc;
49 ReallocFunc GetFunc() const
NLIB_NOEXCEPT {
return m_Realloc; }
52 ReallocFunc m_Realloc;
55 NLIB_STATIC_ASSERT(!IsEmpty<FreeDeleter<int> >::value && !IsEmpty<ReallocDeleter<int> >::value);
58 class ReallocOutputStream
NLIB_FINAL :
public OutputStream {
66 typedef void* (*ReallocFunc)(
void* ptr,
size_t n);
73 const uint8_t* Data() const
NLIB_NOEXCEPT {
return m_Data.get(); }
77 if (this->ExpandOrShrink(this->Pos()) == 0) {
78 this->ResetBuffer(m_Data.get() + m_Capacity, 0);
89 errno_t Expand(
size_t newCap) NLIB_NOEXCEPT {
90 return (newCap > m_Capacity) ? this->ExpandOrShrink(newCap) : 0;
96 NLIB_VIS_PUBLIC virtual
void* GetWorkBuffer_(
size_t* nBytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
106 #endif // INCLUDE_NN_NLIB_REALLOCOUTPUTSTREAM_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
ReallocOutputStream() noexcept
Instantiates the object with default parameters (default constructor). Configures the object to expan...
UniquePtr< char[], ReallocDeleter< char > > CharPtrType
The typedefed UniquePtr to a char array.
#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...
The class for output streams written to memory expanded using nlib_realloc or another realloc functio...
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
UniquePtr owns the pointer, and when it goes out of scope, the pointer is released by the destructor ...
Defines that class that is corresponding to std::unique_ptr.
void ShrinkToFit() noexcept
Makes the buffer size fit to the current write position.
UniquePtr< uint8_t[], ReallocDeleter< uint8_t > > UniquePtrType
The typedefed UniquePtr to a uint8_t array.
#define NLIB_STATIC_ASSERT(exp)
Defines a static assertion. Uses static_assert if it is available for use.
bool Reserve(size_t n) noexcept
Allocates a buffer of the specified size for writing to.
Defines the base class for output streams.
The base class for output streams. This class cannot be instantiated.