- const char *Fmt;
- virtual void home(); // Out of line virtual method.
-public:
- format_object_base(const char *fmt) : Fmt(fmt) {}
- virtual ~format_object_base() {}
-
- /// print - Format the object into the specified buffer. On success, this
- /// returns the length of the formatted string. If the buffer is too small,
- /// this returns a length to retry with, which will be larger than BufferSize.
- virtual unsigned print(char *Buffer, unsigned BufferSize) const = 0;
-};
-
-/// format_object - This is a templated helper class used by the format function
-/// that captures the object to be formated and the format string. When
-/// actually printed, this synthesizes the string into a temporary buffer
-/// provided and returns whether or not it is big enough.
-template <typename T>
- class format_object : public format_object_base {
- T Val;
-public:
- format_object(const char *fmt, const T &val)
- : format_object_base(fmt), Val(val) {
- }
-
- /// print - Format the object into the specified buffer. On success, this
- /// returns the length of the formatted string. If the buffer is too small,
- /// this returns a length to retry with, which will be larger than BufferSize.
- virtual unsigned print(char *Buffer, unsigned BufferSize) const {
-#ifdef WIN32
- int N = _snprintf(Buffer, BufferSize-1, Fmt, Val);
-#else
- int N = snprintf(Buffer, BufferSize-1, Fmt, Val);
-#endif
- if (N < 0) // VC++ and old GlibC return negative on overflow.
- return BufferSize*2;
- if (unsigned(N) >= BufferSize-1)// Other impls yield number of bytes needed.
- return N+1;
- // If N is positive and <= BufferSize-1, then the string fit, yay.
- return N;
+ /// SetBuffer - Use the provided buffer as the raw_ostream buffer. This is
+ /// intended for use only by subclasses which can arrange for the output to go
+ /// directly into the desired output buffer, instead of being copied on each
+ /// flush.
+ void SetBuffer(char *BufferStart, size_t Size) {
+ SetBufferAndMode(BufferStart, Size, ExternalBuffer);