oasys::StringBuffer Class Reference

#include <StringBuffer.h>

Inheritance diagram for oasys::StringBuffer:

oasys::HexDumpBuffer oasys::StaticStringBuffer< _sz > List of all members.

Detailed Description

Utility class that wraps a growable string buffer, similar to std::ostringstream, but with printf() style arguments instead of the << operator.

The initial size of the buffer is 256 bytes, but can be overridden at the constructor and/or through the reserve() function call.

Definition at line 59 of file StringBuffer.h.

Public Member Functions

 StringBuffer (size_t initsz=256, const char *initstr=0)
 StringBuffer (const char *fmt,...)
 
Parameters:
fmt the initial buffer contents

 ~StringBuffer ()
ExpandableBufferexpandable_buf ()
 
Returns:
Expandable buffer.

const char * data () const
 
Returns:
the data buffer (const variant).

char * data ()
 
Returns:
the data buffer (non-const variant)

size_t length () const
 
Returns:
String length of the buffer (excluding any '' character that is added by c_str().

const char * c_str () const
 
Returns:
the data buffer, ensuring null termination.

size_t append (const char *str, size_t len=0)
 Append the string to the tail of the buffer.
size_t append (const std::string &str)
 Append the string to the tail of the buffer.
size_t append (char c)
 Append the character to the tail of the buffer.
size_t appendf (const char *fmt,...)
 Formatting append function.
size_t vappendf (const char *fmt, va_list ap)
 Formatting append function.
size_t append_int (u_int32_t val, int base)
 Append an ascii representation of the given integer.
void trim (size_t cnt)
 Trim cnt characters from the tail of the string.
void set_length (size_t len)
 Forcibly set the buffer length to len.

Private Attributes

ExpandableBufferbuf_
bool own_buf_


Constructor & Destructor Documentation

oasys::StringBuffer::StringBuffer ( size_t  initsz = 256,
const char *  initstr = 0 
)

Parameters:
initsz the initial buffer size
initstr the initial buffer contents

Definition at line 49 of file StringBuffer.cc.

References append(), ASSERT, buf_, and oasys::ExpandableBuffer::reserve().

oasys::StringBuffer::StringBuffer ( const char *  fmt,
  ... 
)

Parameters:
fmt the initial buffer contents

Definition at line 63 of file StringBuffer.cc.

References ASSERT, buf_, oasys::ExpandableBuffer::reserve(), and vappendf().

oasys::StringBuffer::StringBuffer ( ExpandableBuffer buffer,
bool  own_buf 
)

Create a string buffer with an expandable buffer.

Definition at line 79 of file StringBuffer.cc.

References ASSERT, buf_, and oasys::ExpandableBuffer::reserve().

oasys::StringBuffer::~StringBuffer (  ) 

Definition at line 86 of file StringBuffer.cc.

References buf_, delete_z, and own_buf_.

oasys::StringBuffer::StringBuffer ( ExpandableBuffer buffer,
bool  own_buf 
)

Create a string buffer with an expandable buffer.

Definition at line 79 of file StringBuffer.cc.

References ASSERT, buf_, and oasys::ExpandableBuffer::reserve().


Member Function Documentation

ExpandableBuffer* oasys::StringBuffer::expandable_buf (  )  [inline]

Returns:
Expandable buffer.

Definition at line 79 of file StringBuffer.h.

References buf_.

Referenced by oasys::TextMarshal::process().

const char* oasys::StringBuffer::data (  )  const [inline]

Returns:
the data buffer (const variant).

Definition at line 84 of file StringBuffer.h.

References buf_, and oasys::ExpandableBuffer::raw_buf().

Referenced by oasys::SQLTableFormat::append(), c_str(), oasys::MemoryTable::del(), oasys::SQLTableFormat::end_action(), oasys::SQLUpdate::end_action(), oasys::SQLInsert::end_action(), dtn::BundleCommand::exec(), oasys::URL::format(), oasys::MemoryTable::get(), dtn::APIClient::handle_send(), oasys::HexDumpBuffer::hexify(), and oasys::MemoryTable::put().

char* oasys::StringBuffer::data (  )  [inline]

Returns:
the data buffer (non-const variant)

Definition at line 89 of file StringBuffer.h.

References buf_, and oasys::ExpandableBuffer::raw_buf().

size_t oasys::StringBuffer::length (  )  const [inline]

Returns:
String length of the buffer (excluding any '' character that is added by c_str().

Definition at line 95 of file StringBuffer.h.

References buf_, and oasys::ExpandableBuffer::len().

Referenced by oasys::SQLTableFormat::append(), oasys::MemoryTable::del(), oasys::StringSerialize::end_action(), oasys::SQLTableFormat::end_action(), oasys::SQLUpdate::end_action(), oasys::SQLInsert::end_action(), oasys::URL::format(), oasys::MemoryTable::get(), oasys::HexDumpBuffer::hexify(), oasys::SQLTableFormat::process(), and oasys::MemoryTable::put().

const char * oasys::StringBuffer::c_str (  )  const

Returns:
the data buffer, ensuring null termination.

Definition at line 93 of file StringBuffer.cc.

References oasys::ExpandableBuffer::at(), buf_, data(), oasys::ExpandableBuffer::end(), oasys::ExpandableBuffer::len(), oasys::ExpandableBuffer::nfree(), and oasys::ExpandableBuffer::reserve().

Referenced by dtn::LoggingRegistration::deliver_bundle(), dtn::RouteCommand::exec(), dtn::RegistrationCommand::exec(), oasys::LogCommand::exec(), dtn::LinkCommand::exec(), dtn::InterfaceCommand::exec(), oasys::HelpCommand::exec(), dtn::BundleCommand::exec(), dtn::BundleProtocol::format_header_blocks(), dtn::BundleDaemon::handle_bundle_received(), oasys::TclCommand::help_string(), dtn::BundlePayload::init(), dtn::BundlePayload::init_from_store(), oasys::PrettyPrintBuf::next_str(), dtn::BundleProtocol::parse_header_blocks(), oasys::IO::poll_with_notifier(), oasys::SQLQuery::query(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::send_announce(), dtnsim::Connectivity::set_state(), and oasys::BerkeleyDBStore::~BerkeleyDBStore().

size_t oasys::StringBuffer::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 110 of file StringBuffer.cc.

References ASSERT, buf_, oasys::ExpandableBuffer::end(), oasys::ExpandableBuffer::len(), oasys::ExpandableBuffer::reserve(), and oasys::ExpandableBuffer::set_len().

Referenced by oasys::TextMarshal::add_indent(), oasys::TclCommand::add_to_help(), oasys::TextCode::append(), append(), dtn::ContactManager::dump(), oasys::HelpCommand::exec(), dtn::BundleCommand::exec(), oasys::URL::format(), dtn::TableBasedRouter::get_routing_state(), oasys::HexDumpBuffer::hexify(), dtn::InterfaceTable::list(), oasys::PrettyPrintBuf::next_str(), oasys::StringSerialize::process(), oasys::SQLInsert::process(), StringBuffer(), oasys::TextCode::textcodify(), oasys::TextMarshal::TextMarshal(), oasys::TextUncode::textuncodify(), oasys::XMLObject::to_string(), oasys::XMLDocument::to_string(), and oasys::BerkeleyDBStore::~BerkeleyDBStore().

size_t oasys::StringBuffer::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 117 of file StringBuffer.h.

References append().

size_t oasys::StringBuffer::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 127 of file StringBuffer.cc.

References buf_, oasys::ExpandableBuffer::end(), oasys::ExpandableBuffer::len(), oasys::ExpandableBuffer::reserve(), and oasys::ExpandableBuffer::set_len().

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

Formatting append function.

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

Definition at line 197 of file StringBuffer.cc.

References vappendf().

Referenced by oasys::TclCommand::add_to_help(), oasys::TextCode::append(), oasys::SQLTableFormat::append(), oasys::SQLTableFormat::begin_action(), oasys::SQLUpdate::begin_action(), oasys::SQLInsert::begin_action(), dtn::RouteEntry::dump(), dtn::RegistrationTable::dump(), dtn::Link::dump(), dtn::ForwardingLog::dump(), dtn::ContactManager::dump(), dtn::RouteEntry::dump_header(), dtn::UDPConvergenceLayer::dump_interface(), dtn::TCPConvergenceLayer::dump_interface(), dtn::BluetoothConvergenceLayer::dump_interface(), dtn::UDPConvergenceLayer::dump_link(), dtn::TCPConvergenceLayer::dump_link(), dtn::StreamConvergenceLayer::dump_link(), dtn::ConnectionConvergenceLayer::dump_link(), dtn::BluetoothConvergenceLayer::dump_link(), oasys::Log::dump_rules(), dtn::Link::dump_stats(), dtn::LinkStateGraph::dumpGraph(), oasys::HelpCommand::exec(), dtn::BundleCommand::exec(), oasys::URL::format(), dtn::BundleProtocol::format_header_blocks(), dtn::Bundle::format_verbose(), dtn::BundleDaemon::get_bundle_stats(), dtn::BundleDaemon::get_daemon_stats(), dtn::TableBasedRouter::get_routing_state(), dtn::BundleDaemon::handle_bundle_received(), oasys::HexDumpBuffer::hexify(), dtn::InterfaceTable::list(), dtn::BundleProtocol::parse_header_blocks(), oasys::IO::poll_with_notifier(), oasys::TextMarshal::process(), oasys::SQLTableFormat::process(), oasys::SQLUpdate::process(), oasys::SQLInsert::process(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), dtn::BluetoothConvergenceLayer::Connection::send_announce(), oasys::XMLObject::to_string(), dtn::Bundle::validate(), and oasys::BerkeleyDBStore::~BerkeleyDBStore().

size_t oasys::StringBuffer::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 152 of file StringBuffer.cc.

References ASSERT, buf_, oasys::ExpandableBuffer::buf_len(), oasys::ExpandableBuffer::end(), oasys::ExpandableBuffer::len(), oasys::ExpandableBuffer::nfree(), oasys::ExpandableBuffer::reserve(), and oasys::ExpandableBuffer::set_len().

Referenced by appendf(), oasys::StaticStringBuffer< _sz >::StaticStringBuffer(), StringBuffer(), and oasys::TclCommandInterp::TclCommandInterp().

size_t oasys::StringBuffer::append_int ( u_int32_t  val,
int  base 
)

Append an ascii representation of the given integer.

This is the same as calling appendf("%d", val), only faster.

Definition at line 137 of file StringBuffer.cc.

References ASSERT, buf_, oasys::ExpandableBuffer::end(), oasys::fast_ultoa(), oasys::ExpandableBuffer::len(), oasys::ExpandableBuffer::reserve(), and oasys::ExpandableBuffer::set_len().

Referenced by oasys::StringSerialize::process().

void oasys::StringBuffer::trim ( size_t  cnt  )  [inline]

Trim cnt characters from the tail of the string.

Definition at line 157 of file StringBuffer.h.

References ASSERT, buf_, oasys::ExpandableBuffer::len(), and oasys::ExpandableBuffer::set_len().

Referenced by oasys::StringSerialize::end_action(), oasys::HexDumpBuffer::hexify(), and oasys::SQLTableFormat::process().

void oasys::StringBuffer::set_length ( size_t  len  )  [inline]

Forcibly set the buffer length to len.

Definition at line 166 of file StringBuffer.h.

References ASSERT, buf_, oasys::ExpandableBuffer::buf_len(), and oasys::ExpandableBuffer::set_len().


Member Data Documentation

ExpandableBuffer* oasys::StringBuffer::buf_ [mutable, private]

Definition at line 173 of file StringBuffer.h.

Referenced by append(), append_int(), c_str(), data(), expandable_buf(), length(), set_length(), StringBuffer(), trim(), vappendf(), and ~StringBuffer().

bool oasys::StringBuffer::own_buf_ [private]

Definition at line 174 of file StringBuffer.h.

Referenced by ~StringBuffer().


The documentation for this class was generated from the following files:
Generated on Fri Dec 22 14:48:08 2006 for DTN Reference Implementation by  doxygen 1.5.1