Public Member Functions | Private Member Functions | Private Attributes | List of all members
ecl::String Class Reference

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

Private Member Functions

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

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 55 of file string.hpp.

Constructor & Destructor Documentation

◆ String()

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 31 of file string.cpp.

◆ ~String()

ecl::String::~String ( )
virtual

Cleans up memory allocations.

Cleans up the memory allocated to the buffer.

Definition at line 39 of file string.cpp.

Member Function Documentation

◆ c_str()

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 42 of file string.cpp.

◆ clear()

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 112 of file string.cpp.

◆ flush()

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 186 of file string.hpp.

◆ grow()

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 52 of file string.cpp.

◆ isOpen()

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 208 of file string.hpp.

◆ open()

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 199 of file string.hpp.

◆ read() [1/2]

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 67 of file string.cpp.

◆ read() [2/2]

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 82 of file string.cpp.

◆ remaining()

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 103 of file string.cpp.

◆ size()

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 164 of file string.cpp.

◆ str()

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 46 of file string.cpp.

◆ write() [1/2]

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 129 of file string.cpp.

◆ write() [2/2]

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 145 of file string.cpp.

Member Data Documentation

◆ buffer

char* ecl::String::buffer
private

Definition at line 212 of file string.hpp.

◆ buffer_cur_read

char* ecl::String::buffer_cur_read
private

Definition at line 214 of file string.hpp.

◆ buffer_cur_write

char* ecl::String::buffer_cur_write
private

Definition at line 213 of file string.hpp.

◆ buffer_length

unsigned long ecl::String::buffer_length
private

Redundant api for the string device.

Definition at line 208 of file string.hpp.


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


ecl_devices
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:45