Public Attributes | List of all members
mootio::micbuffer Class Reference

Streambuf-like class for input from C char* buffers. More...

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

Public Member Functions

Constructors etc.
 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)
 
Checks and Properties
virtual bool valid (void)
 
virtual bool eof (void)
 
Input Methods
virtual ByteCount read (char *buf, size_t n)
 
virtual int getbyte (void)
 
Utilities
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 Attributes

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...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ micbuffer() [1/2]

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

Constructor from a user-specified buffer Read operations will be performed on the buffer specified. User is responsible for freeing memory associated with data passed to this constructor.

◆ micbuffer() [2/2]

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

Copy constructor

◆ ~micbuffer()

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

Destructor

Member Function Documentation

◆ clear()

void mootio::micbuffer::clear ( void  )
inline

Clear buffer

Referenced by release(), and mootio::mcbuffer::release().

◆ release()

void mootio::micbuffer::release ( void  )
inline

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

References clear().

Referenced by mootio::mcbuffer::~mcbuffer().

◆ assign()

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

Asignment to a different data buffer

References data().

◆ valid()

virtual bool mootio::micbuffer::valid ( void  )
inlinevirtual

Check for buffer validity

Reimplemented from mootio::mstream.

◆ eof()

virtual bool mootio::micbuffer::eof ( void  )
inlinevirtual

Check for end-of-buffer (only meaningful for read operations)

Reimplemented from mootio::mstream.

References cb_used.

◆ read()

virtual ByteCount mootio::micbuffer::read ( char *  buf,
size_t  n 
)
inlinevirtual

Read up to n bytes of data into buf, returns number of bytes actually read.

Reimplemented from mootio::mistream.

References cb_offset, and cb_used.

◆ getbyte()

virtual int mootio::micbuffer::getbyte ( void  )
inlinevirtual

Read a single byte of data

Reimplemented from mootio::mistream.

◆ data()

const char* mootio::micbuffer::data ( void  ) const
inline

Get pointer to current read buffer (whole thing)

References cb_rdata.

Referenced by assign(), moot::TokenWriterNative::sentence2string(), and moot::TokenWriterNative::token2string().

◆ size()

size_t mootio::micbuffer::size ( void  ) const
inline

◆ capacity()

size_t mootio::micbuffer::capacity ( void  ) const
inline

Get current allocated size of data buffer

References cb_used.

◆ offset()

size_t mootio::micbuffer::offset ( void  ) const
inline

Get current read-offset of data buffer

References cb_offset.

◆ as_string()

std::string mootio::micbuffer::as_string ( bool  normalize_ws = false,
bool  trim_left = false,
bool  trim_right = false 
) const
inline

Return the unread portion of the buffer as a new STL string.

Parameters
normalize_wsWhether to normalize whitespace (replace all whitespace substrings with a single space).
trim_leftwhether to trim all leading whitespace
trim_rightwhether to trim all trailing whitespace

References to_string().

◆ to_string()

void mootio::micbuffer::to_string ( std::string &  str,
bool  normalize_ws = false,
bool  trim_left = false,
bool  trim_right = false 
) const
inline

Append the unread portion of the buffer to an existing STL string.

Parameters
strdestination string
normalize_wsWhether to normalize whitespace (replace all whitespace substrings with a single space).
trim_leftwhether to trim all leading whitespace
trim_rightwhether to trim all trailing whitespace

References moot::moot_normalize_ws().

Referenced by as_string().

Member Data Documentation

◆ cb_rdata

const char* mootio::micbuffer::cb_rdata

◆ cb_offset

size_t mootio::micbuffer::cb_offset

◆ cb_used

size_t mootio::micbuffer::cb_used

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