25 #include <type_traits> 36 static const int INITIAL_CAPACITY = 4096;
42 m_buffer.reserve(capacity);
49 m_buffer.reserve(INITIAL_CAPACITY);
55 m_buffer.reserve(s.length()+INITIAL_CAPACITY);
114 unsigned char *p = s;
155 output_int32(i,
false);
169 output_int32(i,
false);
177 typename std::enable_if<std::is_same<T,size_t>::value,T>::type* =
nullptr 181 output_int32(static_cast<uint32_t>(i),
false);
188 output_double(static_cast<double>(f));
203 void write(
const char *buf,
size_t len)
205 m_buffer.append(buf,len);
215 m_s->write(m_buffer.c_str(),m_buffer.length());
219 fwrite(m_buffer.c_str(),1,m_buffer.length(),m_f);
239 void str(
const std::string &s)
257 return m_buffer.empty();
265 void output_int32( uint32_t n,
bool neg )
272 n =
static_cast<uint32_t
>(-
static_cast<int32_t
>(n));
274 do { *--p = (
static_cast<char>(n%10)) +
'0'; n /= 10; }
while ( n );
275 if ( neg ) *--p =
'-';
278 void output_double(
double d)
281 snprintf(buf,64,
"%f",d);
284 std::string m_buffer;
285 std::ostream *m_s =
nullptr;
TextStream(size_t capacity=INITIAL_CAPACITY)
Creates an empty stream object.
Definition: textstream.h:40
void str(const char *s)
Sets the buffer's contents to string s Any data already in the buffer will be flushed.
Definition: textstream.h:248
~TextStream()
Writes any data that is buffered to the attached std::ostream.
Definition: textstream.h:59
Text streaming class that buffers data.
Definition: textstream.h:34
TextStream & operator<<(char c)
Adds a character to the stream.
Definition: textstream.h:97
TextStream & operator<<(signed int i)
Adds a signed integer to the stream.
Definition: textstream.h:160
TextStream & operator<<(unsigned short i)
Adds a unsigned short integer to the stream.
Definition: textstream.h:153
TextStream & operator<<(unsigned char *s)
Adds an unsigned character string to the stream.
Definition: textstream.h:110
TextStream & operator<<(unsigned int i)
Adds a unsigned integer to the stream.
Definition: textstream.h:167
void flush()
Flushes the buffer.
Definition: textstream.h:211
void str(const std::string &s)
Sets the buffer's contents to string s.
Definition: textstream.h:239
TextStream & operator<<(double d)
Adds a double to the stream.
Definition: textstream.h:193
TextStream & operator<<(const std::string &s)
Adds a std::string to the stream.
Definition: textstream.h:139
std::ostream * stream() const
Returns the attached std::ostream object.
Definition: textstream.h:86
std::string str() const
Return the contents of the buffer as a std::string object.
Definition: textstream.h:231
void write(const char *buf, size_t len)
Adds a array of character to the stream.
Definition: textstream.h:203
TextStream & operator<<(signed short i)
Adds a signed short integer to the stream.
Definition: textstream.h:146
TextStream & operator<<(float f)
Adds a float to the stream.
Definition: textstream.h:186
TextStream & operator<<(const QCString &s)
Adds a QCString to the stream.
Definition: textstream.h:132
bool empty() const
Returns true iff the buffer is empty.
Definition: textstream.h:255
TextStream(const std::string &s)
Create a text stream, initializing the buffer with string s.
Definition: textstream.h:53
void setStream(std::ostream *s)
Sets or changes the std::ostream to write to.
Definition: textstream.h:69
TextStream(std::ostream *s)
Create a text stream object for writing to a std::ostream.
Definition: textstream.h:47
This is an alternative implementation of QCString.
Definition: qcstring.h:93
void clear()
Clears any buffered data.
Definition: textstream.h:225
TextStream & operator<<(T i)
Adds a size_t integer to the stream.
Definition: textstream.h:179
TextStream & operator<<(unsigned char c)
Adds an unsigned character to the stream.
Definition: textstream.h:103
TextStream & operator<<(const char *s)
Adds a C-style string to the stream.
Definition: textstream.h:125