PData Class Reference

Class PData allows the construction of arbitrary data structures. More...

List of all members.

Static Public Member Functions

static string & quoteString (string &s)
 Replaces all single quotes (') in the string with quoted single quotes (\').
static string & unquoteString (string &s)
 Replaces all quotes single quotes (\') in the string with single quotes (') Reverses what quoteString did.

Default constructor

Parameters:
owner Internal use only.


 PData (PData *owner=NULL)
 Default constructor.

Conversion constructors

These constructors make PData objects that represent their argument values and types.

Parameters:
owner Internal use only.


 PData (int v, PData *owner=NULL)
 Conversion constructor.
 PData (long v, PData *owner=NULL)
 Conversion constructor.
 PData (float v, PData *owner=NULL)
 Conversion constructor.
 PData (double v, PData *owner=NULL)
 Conversion constructor.
 PData (string v, PData *owner=NULL)
 Conversion constructor.

Copy constructor



 PData (const PData &v, PData *owner=NULL)
 Copy constructor.

Command constructors

These construct new PData objects via a three different methods, "eval", "init" and "raw", corresponding to the PData.eval(), PData.init() and PData.raw() methods which do the same thing after construction.



 PData (const char *command, const char *evalstring, int len=-1)
 Command constructor.
 PData (const char *command, string evalstring)
 Command constructor.
 PData (string command, string evalstring)
 Command constructor.

Assignment operators

Each of these sets the value of the PData object, changing its type as appropriate.

Each of them returns the value just set.



int operator= (int v)
 Assignment operator. Overwrites the type of the PData.
long operator= (long v)
 Assignment operator. Overwrites the type of the PData.
float operator= (float v)
 Assignment operator. Overwrites the type of the PData.
double operator= (double v)
 Assignment operator. Overwrites the type of the PData.
string operator= (string v)
 Assignment operator. Overwrites the type of the PData.
PDataoperator= (PData &v)
 Assignment operator. Overwrites the type of the PData.
int set (int v)
 Assignment operator. Overwrites the type of the PData.
long set (long v)
 Assignment operator. Overwrites the type of the PData.
float set (float v)
 Assignment operator. Overwrites the type of the PData.
double set (double v)
 Assignment operator. Overwrites the type of the PData.
string set (string v)
 Assignment operator. Overwrites the type of the PData.
PDataset (PData &v)
 Assignment operator. Overwrites the type of the PData.

String evaluation functions

Each of these returns a reference to the PData object it is called on.



PDataeval (string evalstring)
 Evaluate a representation string and make it the new value of this PData.
PDataeval (const char *evalstring, int len=-1)
 Evaluate a representation string and make it the new value of this PData.
PDatainit (string typestring)
 Initialize the PData to the given type (int, float, string, list, map).
PDatainit (const char *typestring, int len=-1)
 Initialize the PData to the given type (int, float, string, list, map).
PDataraw (string rawbytes)
 Initialize the PData to hold a string of raw bytes.
PDataraw (const char *rawbytes, int len=-1)
 Initialize the PData to hold a string of raw bytes.

Conversion operators

Each of these casts a pdata to a type (if possible, throw exception otherwise)



 operator int ()
 Perform a type-cast.
 operator long ()
 Perform a type-cast.
 operator float ()
 Perform a type-cast.
 operator double ()
 Perform a type-cast.
 operator string ()
 Perform a type-cast.
int getInt ()
 Extract the value held by the PData.
long getLong ()
 Extract the value held by the PData.
float getFloat ()
 Extract the value held by the PData.
double getDouble ()
 Extract the value held by the PData.
string getString ()
 Extract the value held by the PData.

Extraction operators



PDataoperator[] (string index)
 Get the map value corresponding to a given key; adds the key/value if not already present..
PDataoperator[] (const char *index)
 Get the map value corresponding to a given key; adds the key/value if not already present..
PDataoperator[] (int index)
 Get the list value corresponding to a given index.
PDataget (string index)
 Get the map value corresponding to a given key; adds the key/value if not already present..
PDataget (const char *index)
 Get the map value corresponding to a given key; adds the key/value if not already present..
PDataget (int index)
 Get the list value corresponding to a given index.

Manipulations



void clear ()
 Clear the PData but retain its type.
void setNull ()
 Clear the PData, change its type to null.
void append (const PData &v)
 Append to a list.
void erase (int index)
 Erase a given list index.
void erase (string index)
 Erase a given map key/value pair.
void erase (const char *index)
 Erase a given map key/value pair.
void resize (int size)
 Resize a list.

Information



string getType ()
 Get the type of a PData.
int getTypeEnum ()
 Get the type enum of a PData (compare against enums in PDataNull.h).
int size ()
 Get the number of elements in a list or map.
int isRaw ()
 Return 1 if this PData holds only raw bytes.
long getIndex ()
int has (const PData &v)
 Return 1 if a given PData is present in a list.
int hasKey (const char *v)
 Return 1 if a given key string is present in a map.
vector< string > keys ()
 Return a vector of keys in a map.
void iterateKeys ()
 Begin iterating over the map's keys, in case you can't get access to C++ vectors from your favorite language.
int hasNextKey ()
 Return 1 if there is another key in the map's iterator.
string getNextKey ()
 Get the next key in the map.
int operator== (const PData &v)
 Check value equivalence of two PData's.
int equals (const PData &v)
 Check value equivalence of two PData's.
int find (const PData &v)
 Return the index at which something is found in a list.

Output functions



string toString ()
 Output to string.
void exportBuffer (void(*receiveCallback)(const char *buffer, int size))
 Export the output buffer for the purpose of efficient parsing by another thread.
char * insertTransmit (char *buf_start, char *buf_end)
 Insert string representation into given char buffer.
int getTransmitSize ()
 Return the size of the transmit buffer, not including a trailing null, i.e.
ostream & operator<< (ostream &o, PData &p)
 Output to ostream.

Detailed Description

Class PData allows the construction of arbitrary data structures.


Constructor & Destructor Documentation

PData::PData ( PData owner = NULL  ) 

Default constructor.

Parameters:
owner Internal use only.
PData::PData ( int  v,
PData owner = NULL 
)

Conversion constructor.

Parameters:
v initial value and type
owner Internal use only.
PData::PData ( long  v,
PData owner = NULL 
)

Conversion constructor.

Parameters:
v initial value and type
owner Internal use only.
PData::PData ( float  v,
PData owner = NULL 
)

Conversion constructor.

Parameters:
v initial value and type
owner Internal use only.
PData::PData ( double  v,
PData owner = NULL 
)

Conversion constructor.

Parameters:
v initial value and type
owner Internal use only.
PData::PData ( string  v,
PData owner = NULL 
)

Conversion constructor.

Parameters:
v initial value and type
owner Internal use only.
PData::PData ( const PData v,
PData owner = NULL 
)

Copy constructor.

Parameters:
v initial value and type
owner Internal use only.
PData::PData ( const char *  command,
const char *  evalstring,
int  len = -1 
)

Command constructor.

Parameters:
command,: 
  1. If this string is "eval", evalstring should be a formatted representation string. See README.txt for details on the representation string format.
  2. If it is "init", evalstring should be one of the valid typenames ("int", "float", "string", "list", "map").
  3. If this is "raw", evalstring should be a raw buffer.
evalstring,: a formatted representation string, initializer type name or raw buffer, depending on the value of command.
len,: Specify the size of the buffer, if not null-terminated. Leave it as -1 to pass a null-terminated string.
PData::PData ( const char *  command,
string  evalstring 
)

Command constructor.

See above.

See also:
PData(const char*, const char*, int)
PData::PData ( string  command,
string  evalstring 
)

Command constructor.

See above.

See also:
PData(const char*, const char*, int)

Member Function Documentation

PData& PData::eval ( string  evalstring  ) 

Evaluate a representation string and make it the new value of this PData.

Parameters:
evalstring,: See README.txt for details on the format of the string.
PData& PData::eval ( const char *  evalstring,
int  len = -1 
)

Evaluate a representation string and make it the new value of this PData.

Parameters:
evalstring,: see README.txt for details on the format of the string.
len Specify the length of the char* input, or leave it as -1 to indicate it is null-terminated.
PData& PData::init ( string  typestring  ) 

Initialize the PData to the given type (int, float, string, list, map).

Parameters:
typestring "int" or "float" or "string" or "list" or "map"
PData& PData::init ( const char *  typestring,
int  len = -1 
)

Initialize the PData to the given type (int, float, string, list, map).

Parameters:
typestring "int" or "float" or "string" or "list" or "map"
len Specify the length of the char* input, or leave it as -1 to indicate it is null-terminated.
PData& PData::raw ( string  rawbytes  ) 

Initialize the PData to hold a string of raw bytes.

Parameters:
rawbytes,: the raw bytes to store
PData& PData::raw ( const char *  rawbytes,
int  len = -1 
)

Initialize the PData to hold a string of raw bytes.

Parameters:
rawbytes,: the raw bytes to store
len Specify the length of the char* input, or leave it as -1 to indicate it is null-terminated.
void PData::iterateKeys (  )  [inline]

Begin iterating over the map's keys, in case you can't get access to C++ vectors from your favorite language.

int PData::find ( const PData v  )  [inline]

Return the index at which something is found in a list.

Returns the size of the list if item is not found (which equals size() and is out-of-bounds).

void PData::exportBuffer ( void(*)(const char *buffer, int size)  receiveCallback  ) 

Export the output buffer for the purpose of efficient parsing by another thread.

For thread safety this must be done by submitting a callback function that, in turn, receives the pointer to the buffer and its size. The callback function will be called immediately upon calling exportBuffer().

char* PData::insertTransmit ( char *  buf_start,
char *  buf_end 
)

Insert string representation into given char buffer.

Parameters:
buf_start The start of the transmit buffer.
buf_end The first byte we must NOT write to.
Returns:
Pointer to the trailing null character for next buffer insertion. If buf_end is returned, then we overflowed the buffer (otherwise the trailing null would have been written to (buf_end - 1).
int PData::getTransmitSize (  ) 

Return the size of the transmit buffer, not including a trailing null, i.e.

number of characters in the buffer without including the null.

static string& PData::quoteString ( string &  s  )  [static]

Replaces all single quotes (') in the string with quoted single quotes (\').

This is necessary if you want to send strings containing single quotes via netp.

Parameters:
s,: string to quote
Returns:
: the quoted string (input arg)
static string& PData::unquoteString ( string &  s  )  [static]

Replaces all quotes single quotes (\') in the string with single quotes (') Reverses what quoteString did.

Parameters:
s,: string to unquote
Returns:
: the unquoted string (input arg)

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

Generated on Wed Mar 9 12:04:24 2011 for netp2 by  doxygen 1.6.1