16 #ifndef INCLUDE_NN_NLIB_REALLOCOUTPUTSTREAM_H_ 17 #define INCLUDE_NN_NLIB_REALLOCOUTPUTSTREAM_H_ 30 typedef void* (*ReallocFunc)(
void* ptr,
size_t n) NLIB_NOEXCEPT_FUNCPTR;
32 explicit ReallocDeleter(ReallocFunc reallocfunc)
NLIB_NOEXCEPT : realloc_(reallocfunc) {}
34 ReallocFunc GetFunc()
const NLIB_NOEXCEPT {
return realloc_; }
42 typedef void* (*ReallocFunc)(
void* ptr,
size_t n) NLIB_NOEXCEPT_FUNCPTR;
45 : data_(
nullptr), realloc_func_(
nlib_realloc), capacity_(0) {}
47 : data_(
nullptr), realloc_func_(func), capacity_(0) {}
55 if (this->ExpandOrShrink(this->Pos()) == 0) {
56 this->ResetBuffer(data_ + capacity_, 0);
67 errno_t Expand(
size_t newcap) NLIB_NOEXCEPT {
68 return (newcap > capacity_) ? this->ExpandOrShrink(newcap) : 0;
71 virtual bool PushBuffer_(
const void* p,
size_t nbytes,
74 virtual void* GetWorkBuffer_(
size_t* nbytes) NLIB_NOEXCEPT
NLIB_OVERRIDE;
78 ReallocFunc realloc_func_;
85 #endif // INCLUDE_NN_NLIB_REALLOCOUTPUTSTREAM_H_ #define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
ReallocOutputStream() noexcept
Instantiates the object with default parameters (default constructor). Configures the object to expan...
UniquePtr< char[], ReallocDeleter > CharPtrType
The typedefed UniquePtr to a char array.
#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...
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 > UniquePtrType
The typedefed UniquePtr to a uint8_t array.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
uint8_t * Data() noexcept
Gets the pointer to the start of the data that is in the process of being written.
ReallocOutputStream(ReallocFunc func) noexcept
Specifies a realloc function and instantiates an object.
#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 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.