Public Member Functions | Private Member Functions | Private Attributes
ecl::String Class Reference

A virtual device for manipulating strings. More...

#include <string.hpp>

List of all members.

Public Member Functions

const char * c_str ()
 Character string representation of the device's contents.
void clear ()
 Clears the device's internal buffers.
void flush ()
 Unused, but required api for an output device.
bool isOpen ()
 Unused, but required api for an ecl device.
bool open ()
 Unused, but required api for an ecl device.
long read (char &c)
 Read a character from the string device.
long read (char *s, unsigned long n)
 Reads a character string from the string device.
unsigned long remaining ()
 Specifies the number of characters remaining to be read..
unsigned long size ()
 Number of characters stored in the buffer.
std::string str ()
 String representation of the device's contents.
 String (const char *str="")
 Initialises the string device.
long write (char c)
 Write a character to the buffer.
long write (const char *s, unsigned long n)
 Write a character string to the buffer.
virtual ~String ()
 Cleans up memory allocations.

Private Member Functions

void grow (int no_bytes=256)
 Grow the buffer by the specified amount.

Private Attributes

char * buffer
char * buffer_cur_read
char * buffer_cur_write
unsigned long buffer_length

Detailed Description

A virtual device for manipulating strings.

Device for streaming to and from a string. Do not use this class directly, rather use the string stream class instead. It has flexible memory storage and will grow as needed to (similar to the c++ string class) but the growing algorithm isn't really intelligent - just jumps in leaps of 256.

Reading and writing are simplified. Two separate pointers are used to designate writing and reading locations on the internal buffer.

Reading does not remove or modify the internal buffer, it simply shifts the read location pointer along the string.

Writing always appends and reading has nothing to do whatsoever with the state of the write pointer.

Definition at line 49 of file string.hpp.


Constructor & Destructor Documentation

ecl::String::String ( const char *  str = "") [explicit]

Initialises the string device.

Configures the strings buffer with the input character string. If unspecified, it leaves the internal buffer empty.

Parameters:
str: the input string to store in the buffer.

Definition at line 27 of file string.cpp.

ecl::String::~String ( ) [virtual]

Cleans up memory allocations.

Cleans up the memory allocated to the buffer.

Definition at line 35 of file string.cpp.


Member Function Documentation

const char * ecl::String::c_str ( )

Character string representation of the device's contents.

This returns a null terminates string representing the contents of the device's internal buffer.

Returns:
const char* : pointer to the device's internal buffer.

Definition at line 38 of file string.cpp.

Clears the device's internal buffers.

Clears the internal character buffer and resets read/write location pointers.

Clear the contents of the string device (clears and deletes the buffer).

Definition at line 108 of file string.cpp.

void ecl::String::flush ( ) [inline]

Unused, but required api for an output device.

This is not used for string devices, but necessary for the concept definition of an output device.

Definition at line 172 of file string.hpp.

void ecl::String::grow ( int  no_bytes = 256) [private]

Grow the buffer by the specified amount.

Grows the buffer when necessary. This currently just grows it by 256 bytes whenever room runs out (doesn't actually grow, creates a new section in memory and copies everything over).

Parameters:
no_bytes: the number of bytes to grow by.

Definition at line 48 of file string.cpp.

bool ecl::String::isOpen ( ) [inline]

Unused, but required api for an ecl device.

Redundant api for the string device. This is not used for string devices, but necessary for the concept definition of an ecl device.

Returns:
bool : always returns true.

Definition at line 194 of file string.hpp.

bool ecl::String::open ( ) [inline]

Unused, but required api for an ecl device.

This is not used for string devices, but necessary for the concept definition of an ecl device.

Returns:
bool : always returns true.

Definition at line 185 of file string.hpp.

long ecl::String::read ( char &  c)

Read a character from the string device.

Reads a single character from the string device.

Parameters:
c: character to read into from the string device.
Returns:
long : number of bytes written.

Definition at line 63 of file string.cpp.

long ecl::String::read ( char *  s,
unsigned long  n 
)

Reads a character string from the string device.

Reads a character string from the string device.

Parameters:
s: character string to read into from the string device.
n: the number of bytes to read.

Read a character string from the buffer.

Parameters:
s: points to the beginning of the character string
n: the number of characters to read
Returns:
long : number of characters read, negative on error.

Definition at line 78 of file string.cpp.

unsigned long ecl::String::remaining ( )

Specifies the number of characters remaining to be read..

Determines the number of unread characters left in the internal buffer.

Returns:
unsigned long : number of characters remaining.

Remaining bytes (from the pointer's current position in the buffer until its end).

Returns:
unsigned long : remaining bytes in the string's buffer.

Definition at line 99 of file string.cpp.

unsigned long ecl::String::size ( )

Number of characters stored in the buffer.

This returns the size of the buffer - note that this is different to the number of characters remaining to be read. It is the sum of both read and unread parts.

Returns:
unsigned long : number of characters stored in the buffer.

Size of the string (bytes).

Returns:
long : string size (bytes)

Definition at line 160 of file string.cpp.

std::string ecl::String::str ( )

String representation of the device's contents.

This generates a c++ style string representing the contents of the device's internal buffer.

Returns:
string : string representation of the device's internal buffer.

Definition at line 42 of file string.cpp.

long ecl::String::write ( char  c)

Write a character to the buffer.

Write a character to the buffer. It will automatically grow the buffer if necessary.

Parameters:
c: the character to write.
Returns:
long : the number of bytes written.

Write a character to the buffer - we always append.

Parameters:
c: the character.
Returns:
long : number of characters written, negative on error.

Definition at line 125 of file string.cpp.

long ecl::String::write ( const char *  s,
unsigned long  n 
)

Write a character string to the buffer.

Write a character string to the buffer. It will automatically grow the buffer if necessary.

Parameters:
s: points to the beginning of the character string
n: the number of characters to write.
Returns:
long: the number of bytes written.
Exceptions:
StandardException: throws if flushing returned an error [debug mode only].

Write a character string to the buffer - we always append.

Parameters:
s: points to the beginning of the character string
n: the number of characters to write.
Returns:
long : number of characters written, negative on error.

Definition at line 141 of file string.cpp.


Member Data Documentation

char* ecl::String::buffer [private]

Definition at line 198 of file string.hpp.

Definition at line 200 of file string.hpp.

Definition at line 199 of file string.hpp.

unsigned long ecl::String::buffer_length [private]

Redundant api for the string device.

Definition at line 194 of file string.hpp.


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


ecl_devices
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:57