MemoryPrintf is a dynamic memory canvas for printf().
MEMprintf.cpp
MEMprintf.h
Methods:
char* AquireBuffer()
Returns the address of the current canvas buffer.
The caller is responsible for free()'ing the storage as would the virtual method FreeBuffer() would.
The MemoryPrintf instance is in a state as though Clear() had been called.
_AttachBuffer(char *Buffer, size_t Size)
Clears the current canvas, and sets NULL TERMINATED string as the Buffer. 'Buffer' must be compatible with the virtual FreeBuffer() and ReallocBuffer() methods.
Clear()
Clears the canvas.
GetBuffer()
Returns a pointer to the current buffer. This pointer MAY BE INVALID after subsequenct calls to anyother MemoryPrintf method.
printf(const char *Format, ...)
Same semantics as c-runtime printf() only that the output goes to the canvas.
Returns the number of characters written.
fputs(const char *String)
Same semantics as c-runtime fputs() only that the output goes to the canvas.
Returns the number of characters written.
puts(const char *String)
Same semantics as c-runtime puts() (String + NewLine) only that the output goes to the canvas.
Returns the number of characters written.
Virtual Methods:
FreeBuffer(void *Buffer)
Must free Buffer' as would the c-runtime free().
The default is realloc().
ReallocBuffer(void *Buffer, size_t Size)
Must allocate and reallocate 'Buffer' as would the c-runtime realloc(). The default is realloc().
Special Formats:
64 Bit Integers Size Modifiers: "ll", "I64", "L" (e.g. "%llu", "%I64X", "Ld")
Note: Both modifiers work on all platforms.
Example:
#include <stdio.h> #include <MEMprintf.h> main() { MemoryPrintf Canvas; Canvas.printf("The %u Quick Brown ",34); Canvas.fputs("foxes "); Canvas.printf("jumped over the %g lazy ",123.456); Canvas.puts("dogs"); puts(Canvas.GetBuffer()); return 0; }