A virtual device for manipulating strings. More...
#include <string.hpp>
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 |
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.
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.
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.
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.
Definition at line 38 of file string.cpp.
void ecl::String::clear | ( | ) |
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).
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.
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.
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.
c | : character to read into from the string device. |
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.
s | : character string to read into from the string device. |
n | : the number of bytes to read. |
Read a character string from the buffer.
s | : points to the beginning of the character string |
n | : the number of characters to read |
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.
Remaining bytes (from the pointer's current position in the buffer until its end).
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.
Size of the string (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.
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.
c | : the character to write. |
Write a character to the buffer - we always append.
c | : the character. |
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.
s | : points to the beginning of the character string |
n | : the number of characters to write. |
StandardException | : throws if flushing returned an error [debug mode only]. |
Write a character string to the buffer - we always append.
s | : points to the beginning of the character string |
n | : the number of characters to write. |
Definition at line 141 of file string.cpp.
char* ecl::String::buffer [private] |
Definition at line 198 of file string.hpp.
char* ecl::String::buffer_cur_read [private] |
Definition at line 200 of file string.hpp.
char* ecl::String::buffer_cur_write [private] |
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.