oasys::StringAppender Class Reference

#include <StringAppender.h>

List of all members.


Detailed Description

Enable appending to a statically sized string without overflow and be able to return the length of buffer needed if the static buffer was not the correct size. Useful for implementing Formatter::format().

Definition at line 32 of file StringAppender.h.


Public Member Functions

 StringAppender (char *buf, size_t size)
size_t append (const char *str, size_t len=0)
size_t append (const std::string &str)
size_t append (char c)
size_t appendf (const char *fmt,...)
size_t vappendf (const char *fmt, va_list ap)
size_t length ()
size_t desired_length ()

Private Attributes

char * cur_
size_t remaining_
size_t len_
size_t desired_

Constructor & Destructor Documentation

oasys::StringAppender::StringAppender ( char *  buf,
size_t  size 
)

Parameters:
buf Buffer to append strings to.
size Size of buf. This includes room for the terminating ''.

Definition at line 7 of file StringAppender.cc.


Member Function Documentation

size_t oasys::StringAppender::append ( const char *  str,
size_t  len = 0 
)

Append the string to the tail of the buffer.

Parameters:
str string data
len string length (if unspecified, will call strlen())
Returns:
the number of bytes written

Definition at line 13 of file StringAppender.cc.

References ASSERT, cur_, desired_, len_, and remaining_.

Referenced by append().

size_t oasys::StringAppender::append ( const std::string &  str  )  [inline]

Append the string to the tail of the buffer.

Parameters:
str string data
Returns:
the number of bytes written

Definition at line 55 of file StringAppender.h.

References append().

size_t oasys::StringAppender::append ( char  c  ) 

Append the character to the tail of the buffer.

Parameters:
c the character
Returns:
the number of bytes written (always one)

Definition at line 42 of file StringAppender.cc.

References ASSERT, cur_, desired_, len_, and remaining_.

size_t oasys::StringAppender::appendf ( const char *  fmt,
  ... 
)

Formatting append function.

Parameters:
fmt the format string
Returns:
the number of bytes written

Definition at line 64 of file StringAppender.cc.

References vappendf().

size_t oasys::StringAppender::vappendf ( const char *  fmt,
va_list  ap 
)

Formatting append function.

Parameters:
fmt the format string
ap the format argument list
Returns:
the number of bytes written

Definition at line 76 of file StringAppender.cc.

References ASSERT, cur_, desired_, len_, remaining_, and vsnprintf().

Referenced by appendf().

size_t oasys::StringAppender::length (  )  [inline]

Returns:
resulting length of the buffer.

Definition at line 88 of file StringAppender.h.

References len_.

size_t oasys::StringAppender::desired_length (  )  [inline]

Returns:
Length of the whole string, if there was infinite space.

Definition at line 94 of file StringAppender.h.

References desired_.


Member Data Documentation

char* oasys::StringAppender::cur_ [private]

Definition at line 97 of file StringAppender.h.

Referenced by append(), and vappendf().

size_t oasys::StringAppender::remaining_ [private]

Definition at line 98 of file StringAppender.h.

Referenced by append(), and vappendf().

size_t oasys::StringAppender::len_ [private]

Definition at line 99 of file StringAppender.h.

Referenced by append(), length(), and vappendf().

size_t oasys::StringAppender::desired_ [private]

Definition at line 100 of file StringAppender.h.

Referenced by append(), desired_length(), and vappendf().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:43:56 2007 for DTN Reference Implementation by  doxygen 1.5.3