#include <chain.h>
Public Types | |
typedef chain_iterator | iterator |
Public Member Functions | |
chain () | |
chain (const char *p, unsigned int s=0) | |
chain (std::string &s) | |
~chain () | |
void | clear (void) |
unsigned int | size (void) const |
unsigned int | length (void) const |
char & | operator[] (unsigned int position) throw (Exception) |
const chain & | operator= (const chain &s) |
const chain & | assign (char *p, unsigned int s=0, bool free=false, char *allocatedbegin=NULL) |
const chain & | assign (std::string &s) |
const chain & | assign (const chain &s) |
const bool | operator< (const chain &c) const |
const chain & | operator+= (const chain &s) |
const chain & | operator+= (char *p) |
const chain & | operator+= (std::string &s) |
bool | operator== (const chain &s) const |
bool | operator!= (const chain &s) const |
void | append (const chain &s) |
void | append (const char *p, unsigned int s=0, bool free=false, char *allocatedbegin=NULL) |
void | append (std::string &s) |
void | appendcopy (chain &s) |
void | appendcopy (const char *p, unsigned int s=0) |
void | appendcopy (std::string &s) |
char * | toArray (unsigned int begin=0, unsigned int end=npos) const throw (Exception) |
std::string | toString (unsigned int begin=0, unsigned int end=npos) const throw (Exception) |
int | toInt (unsigned int begin=0) const throw (Exception) |
chain | substr (unsigned int begin, unsigned int end) const throw (Exception) |
bool | substrcopy (char *dest, unsigned int begin, unsigned int end) const throw (Exception) |
chain | duplicate (void) |
unsigned int | find (char c, unsigned int initial=0) const |
chain_iterator | begin (void) |
chain_iterator | end (void) |
void | erase (chain_iterator it) |
void | debug (void) const |
Static Public Attributes | |
static const unsigned int | npos = UINT_MAX |
Protected Attributes | |
std::list< record > | pieces |
Friends | |
class | chain_iterator |
std::ostream & | operator<< (std::ostream &o, chain &p) |
The internal implementation uses instances of the record class to keep track of the different "links" (or pieces) or the chain. The implementation uses a reference counting system, and can shared records or parts of a record between different chains.
Definition at line 182 of file chain.h.
libglass::chain::chain | ( | ) |
Default construtor.
libglass::chain::chain | ( | const char * | p, | |
unsigned int | s = 0 | |||
) |
Construtor.
p | The data array. | |
s | Data size. If zero, the length of p is calculated with strlen(). |
libglass::chain::chain | ( | std::string & | s | ) |
Construtor.
Note that unlike the const char* constructor, STL strings don't end with '' (unless created from raw data or something).
s | The string. |
libglass::chain::~chain | ( | ) |
Destructor.
void libglass::chain::append | ( | std::string & | s | ) |
void libglass::chain::append | ( | const char * | p, | |
unsigned int | s = 0 , |
|||
bool | free = false , |
|||
char * | allocatedbegin = NULL | |||
) |
Append operator.
Appends a data arra to this chain. Memory is shared.
p | The data array to append. | |
s | Array length. If zero, length is calculated with strlen(). | |
free | If true, this array will be automatically deleted when no references to it exist anymore. | |
allocatedbegin | The start address of the allocated block |
void libglass::chain::append | ( | const chain & | s | ) |
Append operator.
Appends a chain to this chain. Memory is shared.
s | The chain to append. |
Referenced by libglass::rawPack(), and libglass::toString().
void libglass::chain::appendcopy | ( | std::string & | s | ) |
void libglass::chain::appendcopy | ( | const char * | p, | |
unsigned int | s = 0 | |||
) |
Append operator.
Appends a data arra to this chain. Memory is duplicated.
p | The data array to append. | |
s | Array length. If zero, length is calculated with strlen(). |
void libglass::chain::appendcopy | ( | chain & | s | ) |
const chain& libglass::chain::assign | ( | std::string & | s | ) |
const chain& libglass::chain::assign | ( | char * | p, | |
unsigned int | s = 0 , |
|||
bool | free = false , |
|||
char * | allocatedbegin = NULL | |||
) |
Assignment operator.
p | The data array to assign. | |
s | size | |
free | If true, this array will be automatically deleted when no references to it exist anymore. | |
allocatedbegin | If you want the data to be automatically deleted, but the beginning of data starts at some other address (for example, you are ignoring a header), pass the correct address here. |
chain_iterator libglass::chain::begin | ( | void | ) |
void libglass::chain::clear | ( | void | ) |
Clears this chain.
void libglass::chain::debug | ( | void | ) | const |
chain libglass::chain::duplicate | ( | void | ) |
Duplicates this string, copying the contents.
Memory is not shared, but copied to new buffers. Use only when it's absolutely necessary to copy the chain contents, since this function is much slower than assign().
chain_iterator libglass::chain::end | ( | void | ) |
void libglass::chain::erase | ( | chain_iterator | it | ) |
unsigned int libglass::chain::find | ( | char | c, | |
unsigned int | initial = 0 | |||
) | const |
Finds the first occurrence of a given character.
c | The character to search for. | |
initial | The position to start the search. |
Referenced by libglass::Remote< T, T, T >::unpack().
bool libglass::chain::operator!= | ( | const chain & | s | ) | const |
const chain& libglass::chain::operator+= | ( | std::string & | s | ) |
Append operator. Exactly equivalent to append().
s | The data array to append. |
const chain& libglass::chain::operator+= | ( | char * | p | ) |
Append operator. Exactly equivalent to append().
p | The data array to append. Size is calculated with strlen(). |
Append operator. Exactly equivalent to append().
s | The chain to append. |
const bool libglass::chain::operator< | ( | const chain & | c | ) | const |
Assignment operator.
s |
bool libglass::chain::operator== | ( | const chain & | s | ) | const |
char& libglass::chain::operator[] | ( | unsigned int | position | ) | throw (Exception) |
Returns the character in a given position.
position | The position. |
Substring.
Creates a new chain, which is a substring to the original one. The data is shared, though, so modifications to one will result in modifications to the other.
begin | The first position of the substring. | |
end | The last position of the substring. Use npos to get the last character of the original string. |
bool libglass::chain::substrcopy | ( | char * | dest, | |
unsigned int | begin, | |||
unsigned int | end | |||
) | const throw (Exception) |
Substring copy.
Copies the substring to a given buffer. The contents are duplicated, so this function is slower than substr. User is responsible for providing a valid buffer at least (end-begin+1) bytes long.
dest | The destination buffer | |
begin | The first position of the substring. | |
end | The last position of the substring. Use npos to get the last character of the original string. |
True | if successful. | |
False | otherwise. |
Referenced by libglass::rawUnpack().
char* libglass::chain::toArray | ( | unsigned int | begin = 0 , |
|
unsigned int | end = npos | |||
) | const throw (Exception) |
Returns a character array with the contents of a range of records of this chain, but merged to a single record.
begin | The first RECORD. | |
end | The last RECORD. |
int libglass::chain::toInt | ( | unsigned int | begin = 0 |
) | const throw (Exception) |
Returns a 4-byte integer astroed at a given position.
begin | The start of the data. |
std::string libglass::chain::toString | ( | unsigned int | begin = 0 , |
|
unsigned int | end = npos | |||
) | const throw (Exception) |
Returns a std::string with the contents of a range of this chain.
begin | The index of the first character. | |
end | The index of the last character. |
Referenced by libglass::fromString().
friend class chain_iterator [friend] |
std::ostream& operator<< | ( | std::ostream & | o, | |
chain & | p | |||
) | [friend] |
const unsigned int libglass::chain::npos = UINT_MAX [static] |
std::list<record> libglass::chain::pieces [protected] |