libglass::chain Class Reference

#include <chain.h>

List of all members.

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 chainoperator= (const chain &s)
const chainassign (char *p, unsigned int s=0, bool free=false, char *allocatedbegin=NULL)
const chainassign (std::string &s)
const chainassign (const chain &s)
const bool operator< (const chain &c) const
const chainoperator+= (const chain &s)
const chainoperator+= (char *p)
const chainoperator+= (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< recordpieces

Friends

class chain_iterator
std::ostream & operator<< (std::ostream &o, chain &p)


Detailed Description

chain is a string-like class. It was written to avoid memory copying, and therefore be efficient when working with large arrays. It's basic usage is to concatenate several std::string or char *.

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.

See also:
record, chain_iterator

Definition at line 182 of file chain.h.


Member Typedef Documentation

Definition at line 185 of file chain.h.


Constructor & Destructor Documentation

libglass::chain::chain (  ) 

Default construtor.

libglass::chain::chain ( const char *  p,
unsigned int  s = 0 
)

Construtor.

Parameters:
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).

Parameters:
s The string.

libglass::chain::~chain (  ) 

Destructor.


Member Function Documentation

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.

Parameters:
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
See also:
appendcopy.

void libglass::chain::append ( const chain s  ) 

Append operator.

Appends a chain to this chain. Memory is shared.

Parameters:
s The chain to append.
See also:
appendcopy.

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.

Parameters:
p The data array to append.
s Array length. If zero, length is calculated with strlen().
See also:
appendcopy.

void libglass::chain::appendcopy ( chain s  ) 

Append operator.

Appends a chain to this chain. Memory is duplicated.

Parameters:
s The chain to append.
See also:
append.

const chain& libglass::chain::assign ( const 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.

Parameters:
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.
Returns:
This chain.

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

Returns:
The duplicated string.
See also:
substrcopy.

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.

Parameters:
c The character to search for.
initial The position to start the search.
Returns:
The position of the first occurrence of c, or npos if not found.

Referenced by libglass::Remote< T, T, T >::unpack().

unsigned int libglass::chain::length ( void   )  const

Size (in bytes) of this chain.

See also:
size.

bool libglass::chain::operator!= ( const chain s  )  const

Inequality operator.

Parameters:
s The chain to compare to.
Returns:
False if equal, true otherwise.

const chain& libglass::chain::operator+= ( std::string &  s  ) 

Append operator. Exactly equivalent to append().

Parameters:
s The data array to append.
Returns:
This chain.
See also:
append, appendcopy.

const chain& libglass::chain::operator+= ( char *  p  ) 

Append operator. Exactly equivalent to append().

Parameters:
p The data array to append. Size is calculated with strlen().
Returns:
This chain.
See also:
append, appendcopy.

const chain& libglass::chain::operator+= ( const chain s  ) 

Append operator. Exactly equivalent to append().

Parameters:
s The chain to append.
Returns:
.
See also:
append, appendcopy.

const bool libglass::chain::operator< ( const chain c  )  const

Comparison operator.

Parameters:
c The chain to compare to.
Returns:
true if this chain is less than c.

const chain& libglass::chain::operator= ( const chain s  ) 

Assignment operator.

Parameters:
s 
Returns:

bool libglass::chain::operator== ( const chain s  )  const

Equality operator.

Parameters:
s The chain to compare to.
Returns:
True if equal, false otherwise.

char& libglass::chain::operator[] ( unsigned int  position  )  throw (Exception)

Returns the character in a given position.

Parameters:
position The position.
Returns:
A reference to the character in that position, if the position is valid.

unsigned int libglass::chain::size ( void   )  const

Size (in bytes) of this chain.

See also:
length.

chain libglass::chain::substr ( unsigned int  begin,
unsigned int  end 
) const throw (Exception)

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.

Parameters:
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.
Returns:
A chain containing the substring.

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.

Parameters:
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.
Return values:
True if successful.
False otherwise.
See also:
substr, duplicate.

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.

Parameters:
begin The first RECORD.
end The last RECORD.
Returns:
A character array with the same contents of this chain. You are responsible for delete[]ing this array. If the parameters are invalid, returns NULL.

int libglass::chain::toInt ( unsigned int  begin = 0  )  const throw (Exception)

Returns a 4-byte integer astroed at a given position.

Parameters:
begin The start of the data.
Returns:
A integer.
See also:
charToNum.

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.

Parameters:
begin The index of the first character.
end The index of the last character.
Returns:
A std::string with the contents of a range of this chain.

Referenced by libglass::fromString().


Friends And Related Function Documentation

friend class chain_iterator [friend]

Definition at line 199 of file chain.h.

std::ostream& operator<< ( std::ostream &  o,
chain p 
) [friend]


Member Data Documentation

const unsigned int libglass::chain::npos = UINT_MAX [static]

Definition at line 192 of file chain.h.

Referenced by libglass::Remote< T, T, T >::unpack().

std::list<record> libglass::chain::pieces [protected]

Definition at line 201 of file chain.h.


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

Generated on Fri May 28 13:19:01 2010 for libGlass by  doxygen 1.5.8