Public Attributes | Static Public Attributes | List of all members
mootio::mcbuffer Class Reference

Streambuf-like class for I/O on C char* buffers. More...

Inheritance diagram for mootio::mcbuffer:
Inheritance graph
[legend]
Collaboration diagram for mootio::mcbuffer:
Collaboration graph
[legend]

Public Member Functions

Constructors etc.
 mcbuffer (size_t size=CB_DEFAULT_SIZE)
 
 mcbuffer (void *data, size_t used, size_t alloc=0, size_t get=CB_DEFAULT_GET)
 
 mcbuffer (const micbuffer &cb)
 
void assign (const void *data, size_t len)
 
virtual ~mcbuffer (void)
 
void clear (void)
 
void release (void)
 
Output Methods
virtual bool flush (void)
 
virtual bool write (const char *buf, size_t n)
 
virtual bool putbyte (unsigned char c)
 
virtual bool puts (const char *s)
 
virtual bool puts (const std::string &s)
 
virtual bool vprintf (const char *fmt, va_list &ap)
 
Utilities
bool reserve (size_t size, size_t pad=0)
 
- Public Member Functions inherited from mootio::micbuffer
 micbuffer (const void *data, size_t len)
 
 micbuffer (const micbuffer &cb)
 
virtual ~micbuffer (void)
 
void clear (void)
 
void release (void)
 
void assign (const void *data, size_t len)
 
virtual bool valid (void)
 
virtual bool eof (void)
 
virtual ByteCount read (char *buf, size_t n)
 
virtual int getbyte (void)
 
const char * data (void) const
 
size_t size (void) const
 
size_t capacity (void) const
 
size_t offset (void) const
 
std::string as_string (bool normalize_ws=false, bool trim_left=false, bool trim_right=false) const
 
void to_string (std::string &str, bool normalize_ws=false, bool trim_left=false, bool trim_right=false) const
 
- Public Member Functions inherited from mootio::mistream
 mistream (void)
 
virtual ~mistream (void)
 
virtual ByteCount getline (std::string &s, const std::string &delim="\")
 
- Public Member Functions inherited from mootio::mstream
 mstream (const std::string &myname="")
 
virtual ~mstream (void)
 
 operator bool (void)
 
virtual std::string errmsg (void)
 
virtual bool reopen (void)
 
virtual bool close (void)
 
- Public Member Functions inherited from mootio::mostream
 mostream (void)
 
virtual ~mostream (void)
 
bool printf (const char *fmt,...)
 

Public Attributes

char * cb_wdata
 underlying character data buffer (write) More...
 
size_t cb_alloc
 allocated size of buffer (in bytes) More...
 
size_t cb_get
 number of extra bytes to get on internal reserve() calls More...
 
bool cb_created
 whether we allocated the cb_wdata buffer ourself More...
 
- Public Attributes inherited from mootio::micbuffer
const char * cb_rdata
 underlying character data buffer More...
 
size_t cb_offset
 current read offset position in buffer More...
 
size_t cb_used
 used length of buffer (in bytes) More...
 
- Public Attributes inherited from mootio::mstream
std::string name
 symbolic name of this stream More...
 

Static Public Attributes

static const size_t CB_DEFAULT_SIZE = 32
 Default initial buffer size. More...
 
static const size_t CB_DEFAULT_GET = 32
 Default number of extra bytes to get on reserve() More...
 

Detailed Description

This class provides an API for in-memory I/O which does not resort to C++ sstream : this is a Good Thing, because:

Constructor & Destructor Documentation

◆ mcbuffer() [1/3]

mootio::mcbuffer::mcbuffer ( size_t  size = CB_DEFAULT_SIZE)
inline

Default constructor, given optional initial buffer size

References mootio::micbuffer::size().

◆ mcbuffer() [2/3]

mootio::mcbuffer::mcbuffer ( void *  data,
size_t  used,
size_t  alloc = 0,
size_t  get = CB_DEFAULT_GET 
)
inline

Constructor from a user-specified buffer Read/write operations will be performed on this buffer as long as possible. On write overflow, a new local buffer will be allocated (which will be freed on release()). User is responsible for freeing memory associated with data passed to this constructor.

References mootio::micbuffer::cb_rdata, and mootio::micbuffer::cb_used.

◆ mcbuffer() [3/3]

mootio::mcbuffer::mcbuffer ( const micbuffer cb)
inline

◆ ~mcbuffer()

virtual mootio::mcbuffer::~mcbuffer ( void  )
inlinevirtual

Destructor

References mootio::micbuffer::release().

Member Function Documentation

◆ assign()

void mootio::mcbuffer::assign ( const void *  data,
size_t  len 
)
inline

Asignment to a different data buffer (always copies)

References mootio::micbuffer::cb_offset, mootio::micbuffer::cb_rdata, and mootio::micbuffer::cb_used.

◆ clear()

void mootio::mcbuffer::clear ( void  )
inline

◆ release()

void mootio::mcbuffer::release ( void  )
inline

Free locally allocated data buffer, if any. Implicitly calls clear()

References mootio::micbuffer::cb_rdata, and mootio::micbuffer::clear().

◆ flush()

virtual bool mootio::mcbuffer::flush ( void  )
inlinevirtual

"Flush" all data before offset() from the buffer.

Reimplemented from mootio::mostream.

References mootio::micbuffer::cb_offset, and mootio::micbuffer::cb_used.

◆ write()

virtual bool mootio::mcbuffer::write ( const char *  buf,
size_t  n 
)
inlinevirtual

Write n bytes from buf to the buffer

Reimplemented from mootio::mostream.

References mootio::micbuffer::cb_used.

◆ putbyte()

virtual bool mootio::mcbuffer::putbyte ( unsigned char  c)
inlinevirtual

Write a single byte to the buffer

Reimplemented from mootio::mostream.

References mootio::micbuffer::cb_used.

◆ puts() [1/2]

virtual bool mootio::mcbuffer::puts ( const char *  s)
inlinevirtual

Write a C string to the buffer

Reimplemented from mootio::mostream.

◆ puts() [2/2]

virtual bool mootio::mcbuffer::puts ( const std::string &  s)
inlinevirtual

Write a C++ string to the buffer

Reimplemented from mootio::mostream.

◆ vprintf()

virtual bool mootio::mcbuffer::vprintf ( const char *  fmt,
va_list &  ap 
)
inlinevirtual

printf() to the buffer, va_list version

Reimplemented from mootio::mostream.

References mootio::micbuffer::cb_used.

◆ reserve()

bool mootio::mcbuffer::reserve ( size_t  size,
size_t  pad = 0 
)
inline

Grow the buffer to fit at least size + pad bytes in it

References mootio::micbuffer::cb_rdata, and mootio::micbuffer::cb_used.

Member Data Documentation

◆ CB_DEFAULT_SIZE

const size_t mootio::mcbuffer::CB_DEFAULT_SIZE = 32
static

◆ CB_DEFAULT_GET

const size_t mootio::mcbuffer::CB_DEFAULT_GET = 32
static

◆ cb_wdata

char* mootio::mcbuffer::cb_wdata

◆ cb_alloc

size_t mootio::mcbuffer::cb_alloc

◆ cb_get

size_t mootio::mcbuffer::cb_get

◆ cb_created

bool mootio::mcbuffer::cb_created

The documentation for this class was generated from the following file: