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 38 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, size_t *lenp, va_list ap)
 Formatting append function.
size_t append_int (u_int32_t val, int base)
 Append an ascii representation of the given integer.
size_t append_int (u_int64_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 28 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 42 of file StringBuffer.cc.

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

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

Create a string buffer with an expandable buffer.

Definition at line 55 of file StringBuffer.cc.

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

oasys::StringBuffer::~StringBuffer (  ) 

Definition at line 62 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 55 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 58 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 63 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(), oasys::XMLMarshal::process(), and oasys::MemoryTable::put().

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

Returns:
the data buffer (non-const variant)

Definition at line 68 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 74 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 69 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::IPDiscovery::configure(), dtn::IPAnnounce::configure(), dtn::PrimaryBlockProcessor::debug_dump_dictionary(), dtn::LoggingRegistration::deliver_bundle(), dtn::RouteCommand::exec(), dtn::RegistrationCommand::exec(), oasys::LogCommand::exec(), dtn::LinkCommand::exec(), dtn::InterfaceCommand::exec(), oasys::HelpCommand::exec(), dtn::DiscoveryCommand::exec(), dtn::BundleCommand::exec(), oasys::InlineFormatter< _T >::format(), dtn::BundleDaemon::handle_bundle_received(), dtn::ProphetEncounter::handle_prophet_tlv(), oasys::TclCommand::help_string(), oasys::PrettyPrintBuf::next_str(), dtn::IPDiscovery::parse_advertisement(), oasys::IO::poll_with_notifier(), oasys::SQLQuery::query(), dtn::ProphetEncounter::send_prophet_tlv(), dtnsim::Connectivity::set_state(), oasys::TclCommandInterp::shutdown(), 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 86 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::StringSerialize::add_preamble(), oasys::TclCommand::add_to_help(), oasys::TextCode::append(), append(), dtn::ContactManager::dump(), oasys::HelpCommand::exec(), dtn::BundleCommand::exec(), oasys::URL::format(), oasys::InlineFormatter< _T >::format(), oasys::EnumOpt::get(), dtn::EndpointIDOpt::get(), dtn::APIEndpointIDOpt::get(), 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 96 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 108 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 172 of file StringBuffer.cc.

References buf_, oasys::ExpandableBuffer::len(), and STRINGBUFFER_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::PrimaryBlockProcessor::debug_dump_dictionary(), dtn::RouteEntry::dump(), dtn::RegistrationTable::dump(), dtn::ProphetTLV::dump(), dtn::BundleTLV::dump(), dtn::RIBTLV::dump(), dtn::RIBDTLV::dump(), dtn::HelloTLV::dump(), dtn::BaseTLV::dump(), dtn::BundleOffer::dump(), dtn::ProphetNode::dump(), dtn::RIBNode::dump(), dtn::ProphetDictionary::dump(), dtn::Link::dump(), dtn::ForwardingLog::dump(), dtn::DiscoveryTable::dump(), dtn::Discovery::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::ProphetEncounter::dump_state(), dtn::ProphetController::dump_state(), dtn::Link::dump_stats(), dtn::LinkStateGraph::dumpGraph(), oasys::HelpCommand::exec(), dtn::BundleCommand::exec(), oasys::TclCommandInterp::exec_file(), oasys::URL::format(), oasys::InlineFormatter< _T >::format(), dtn::Bundle::format_verbose(), oasys::BdAddrOpt::get(), oasys::InAddrOpt::get(), oasys::CharBufOpt::get(), oasys::StringOpt::get(), oasys::DoubleOpt::get(), oasys::UInt8Opt::get(), oasys::UInt16Opt::get(), oasys::UInt64Opt::get(), oasys::UIntOpt::get(), oasys::IntOpt::get(), oasys::BoolOpt::get(), 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(), oasys::IO::poll_with_notifier(), oasys::XMLMarshal::process(), oasys::TextMarshal::process(), oasys::SQLTableFormat::process(), oasys::SQLUpdate::process(), oasys::SQLInsert::process(), oasys::XMLObject::to_string(), dtn::Bundle::validate(), and oasys::BerkeleyDBStore::~BerkeleyDBStore().

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

Formatting append function.

Note that this may not actually format the full string if there's not enough space in the buffer, so the STRINGBUFFER_VAPPENDF macro below should be used in most cases instead.

The lenp parameter can be used to pass in the length that the buffer should be set to (if known) and returns the length of the buffer after formatting. If *lenp is less than the return value, the format string was truncated.

Parameters:
fmt the format string
lenp length of the underlying buffer
ap the format argument list
Returns:
the return value from vsnprintf, i.e. the length of the full formatted string

Definition at line 148 of file StringBuffer.cc.

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

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 118 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().

size_t oasys::StringBuffer::append_int ( u_int64_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 133 of file StringBuffer.cc.

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

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

Trim cnt characters from the tail of the string.

Definition at line 154 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 163 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 170 of file StringBuffer.h.

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

bool oasys::StringBuffer::own_buf_ [private]

Definition at line 171 of file StringBuffer.h.

Referenced by ~StringBuffer().


The documentation for this class was generated from the following files:
Generated on Thu Jun 7 12:54:37 2007 for DTN Reference Implementation by  doxygen 1.5.1