MCS  0.3.3-alpha7
mcs::Record Class Reference

A dynamic array of Data objects. More...

#include <mcs.hh>

+ Inheritance diagram for mcs::Record:

Public Member Functions

void addField (Data *d)
 Wrapper around Dynamic_Array.push. More...
 
void addField (Data &d)
 Wrapper around Dynamic_Array.push. More...
 
void addField (string s, char tag=0)
 Push a new Data object with base type STRING in the array. More...
 
void addField (int i, char tag=0)
 Push a new Data object with base type INT in the array. More...
 
void addField (long long int i, char tag=0)
 Push a new Data object with base type BIGINT in the array. More...
 
void addField (double f, char tag=0)
 Push a new Data object with base type DOUBLE in the array. More...
 
string asString (string sep="\)
 Return record content as a unique string. More...
 
string asStringNames (string sep="\)
 
string asStringTypes (string sep="\)
 
void clear ()
 
int count ()
 Wrapper around Dynamic_Array.count. More...
 
void emptyName ()
 Set all Data object's name to an empty string. More...
 
Data field (string name)
 Returns the Data object in the vector whose name is "name". More...
 
Data field (int pos)
 
unsigned int objSize ()
 Return how many bytes require the object to be serialized. More...
 
Recordoperator= (Record &from)
 Assignment operator, will copy all data objects. More...
 
Dataoperator[] (string name)
 
Dataoperator[] (int pos)
 
Data pop (int x=0)
 
int posWhoseNameIs (string name, enum ThrowExceptions throwexc=THROW)
 Return the index of the first Data objects whose name is "name". More...
 
 Record (Record &from)
 Copy constructor, will copy all data objects. More...
 
 Record (bool synchro=false)
 Constructor, build an empty record. The parameter is passed to the underlying Dynamic_Array object. More...
 
 Record (void *lbuf, bool synchro=false)
 Build a Record object from a buffer prepared with Record.prepareBuffer(). More...
 
void setFieldMap (string s="")
 Creates a new field map from the given string. More...
 
void setFieldMap (Record &rec)
 Copy the field map from one record to another. More...
 
void setNull ()
 Set all Data object's name to null values. More...
 
 ~Record ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::Serializable
void * getEntireBuffer (unsigned int &size)
 
bool knowSize ()
 Reinitialize internal data. More...
 
unsigned int maxChunkSize ()
 Return the max size allowed for a chunk. More...
 
unsigned int nChunk ()
 If knowSize() is true, return how many chunks are required to send all data. More...
 
void * nextChunk (unsigned int &chunksize)
 Fills a buffer with next chunk to be sent. More...
 
Serializableoperator= (const Serializable &)
 Declared to avoid using of default assignment operator. More...
 
 Serializable (const Serializable &)
 Declared to avoid using of default copy constructor. More...
 
 Serializable (unsigned int lmaxChunksize=16384)
 Constructor, for custom data (type = SERIAL_UNKNOWN). More...
 
 Serializable (void *from, unsigned int size, bool freeAfterUse, unsigned int lmaxChunksize=16384)
 Constructor, for memory buffers (type = SERIAL_BUFFER). More...
 
 Serializable (string filename, unsigned int lmaxChunksize=16384)
 Constructor, for files (type = SERIAL_FILENAME). More...
 
 Serializable (int type, unsigned int lmaxChunksize=16384)
 
unsigned int size ()
 If knowSize() is true, return the size of the entire block of data. More...
 
virtual ~Serializable ()
 Destructor. More...
 
- Public Member Functions inherited from mcs::Synchro
int count ()
 Return how many times the current thread has locked the section. More...
 
bool enter (int op=1, unsigned int timeout=0)
 Enter, or try to enter a critical section. More...
 
int leave ()
 Leave a critical section. More...
 
Synchrooperator= (const Synchro &)
 Declared to avoid using of default assignment operator. More...
 
 Synchro (const Synchro &)
 Declared to avoid using of default copy constructor. More...
 
 Synchro ()
 Constructor. More...
 
void synchronize (bool setactive)
 Enable or disable the synchronization feature. More...
 
bool tryenter (unsigned int timeout=0)
 Wrapper around enter(), using op=MCS_SYNCHRO_TRY_LOCK if the parameter is 0, op=MCS_SYNCHRO_TRY_TIMED otherwise. More...
 
 ~Synchro ()
 Destructor. More...
 

Private Member Functions

bool serialize_buffer (char *&from, unsigned int &size)
 Prepare a buffer with all informations contained in the object. More...
 

Private Attributes

Dynamic_Array< Dataarray
 Array of fields. More...
 
Dynamic_Array< int > lmap
 Array of mapped fields. More...
 
 MCS_DEBUG_ALLOC
 
string smap
 String representation of the map. More...
 

Detailed Description

A dynamic array of Data objects.

This class handles an array of Data objects, that are the most common way of passing information in MCS, due to their interface able to convert information between different types. This class is thread safe in the sense that it can be used from different threads without worrying about synchronization. You only have to take care when you use the operator[].

This class is simply a wrapper around a Dynamic_Array<Data> object, it is mainly used because object of this class can be serialized (with the prepareBuffer() and one of the constructor), and because it can use a name map.

Definition at line 4170 of file mcs.hh.

Constructor & Destructor Documentation

◆ Record() [1/3]

mcs::Record::Record ( Record from)

Copy constructor, will copy all data objects.

Definition at line 259 of file Record.cc.

◆ Record() [2/3]

mcs::Record::Record ( bool  synchro = false)

Constructor, build an empty record. The parameter is passed to the underlying Dynamic_Array object.

Definition at line 227 of file Record.cc.

◆ Record() [3/3]

mcs::Record::Record ( void *  lbuf,
bool  synchro = false 
)

Build a Record object from a buffer prepared with Record.prepareBuffer().

The object won't be synchronized.

Parameters
lbufPointer to the buffer in memory.

Definition at line 238 of file Record.cc.

◆ ~Record()

mcs::Record::~Record ( )

Destructor.

It calls clean() to destroy all objects.

See also
clean()

Definition at line 234 of file Record.cc.

Member Function Documentation

◆ addField() [1/6]

void mcs::Record::addField ( Data d)

Wrapper around Dynamic_Array.push.

Definition at line 364 of file Record.cc.

◆ addField() [2/6]

void mcs::Record::addField ( Data d)

Wrapper around Dynamic_Array.push.

Definition at line 372 of file Record.cc.

◆ addField() [3/6]

void mcs::Record::addField ( string  s,
char  tag = 0 
)

Push a new Data object with base type STRING in the array.

The new element contains the data passed as the "s" parameter.

Parameters
sThe data that will be contained in the new object.
tagSet a new value to internal tag.

Definition at line 380 of file Record.cc.

◆ addField() [4/6]

void mcs::Record::addField ( int  i,
char  tag = 0 
)

Push a new Data object with base type INT in the array.

The new element contains the data passed as the "i" parameter.

Parameters
iThe data that will be contained in the new object.
tagSet a new value to internal tag.

Definition at line 386 of file Record.cc.

◆ addField() [5/6]

void mcs::Record::addField ( long long int  i,
char  tag = 0 
)

Push a new Data object with base type BIGINT in the array.

The new element contains the data passed as the "i" parameter.

Parameters
iThe data that will be contained in the new object.
tagSet a new value to internal tag.

Definition at line 392 of file Record.cc.

◆ addField() [6/6]

void mcs::Record::addField ( double  f,
char  tag = 0 
)

Push a new Data object with base type DOUBLE in the array.

The new element contains the data passed as the "f" parameter.

Parameters
fThe data that will be contained in the new object;
tagSet a new value to internal tag.

Definition at line 398 of file Record.cc.

◆ asString()

string mcs::Record::asString ( string  sep = "\t")

Return record content as a unique string.

Definition at line 524 of file Record.cc.

◆ count()

int mcs::Record::count ( )

Wrapper around Dynamic_Array.count.

Definition at line 359 of file Record.cc.

◆ emptyName()

void mcs::Record::emptyName ( )

Set all Data object's name to an empty string.

When sent through the network the object will carry its name, consuming bandwidth. With this method you can save some bytes during trasmission.

Definition at line 508 of file Record.cc.

◆ field()

Data mcs::Record::field ( string  name)

Returns the Data object in the vector whose name is "name".

Definition at line 419 of file Record.cc.

◆ objSize()

unsigned int mcs::Record::objSize ( )

Return how many bytes require the object to be serialized.

Definition at line 281 of file Record.cc.

◆ operator=()

Record & mcs::Record::operator= ( Record from)

Assignment operator, will copy all data objects.

Definition at line 269 of file Record.cc.

◆ operator[]()

Data & mcs::Record::operator[] ( string  name)

Note that this returns a reference to the object, so that you can use the Data assignment operator like this:

q.addField();
q[0] = "a string";
q[0] = 12;
...

Definition at line 439 of file Record.cc.

◆ posWhoseNameIs()

int mcs::Record::posWhoseNameIs ( string  name,
enum ThrowExceptions  throwexc = THROW 
)

Return the index of the first Data objects whose name is "name".

This method work correctly only if all Data objects in the array has a name.

Parameters
nameThe field name to search for.
throwexcIf DONT_THROW will return -1 instead of throwing an exception.
Returns
Index of the field if found, or -1 if not found.
Exceptions
ERRORMSG_MISSING_FIELD.

Definition at line 457 of file Record.cc.

◆ serialize_buffer()

bool mcs::Record::serialize_buffer ( char *&  from,
unsigned int &  size 
)
privatevirtual

Prepare a buffer with all informations contained in the object.

Once the buffer is prepared you can rebuild an identical object using the Record(void*) cosntructor.

If "*lbuf" is NULL then the buffer will be allocated, otherwise "size" must be set to the length of the buffer pointed by "*lbuf";

Parameters
lbufAddress of a pointer to a buffer;
sizeSize of the buffer if it should not be allocated.
Returns
Size of the data in the buffer.
Exceptions
ERRORMSG_NOT_ENOUGH_SPACE.
Returns
Size of the buffer.

Reimplemented from mcs::Serializable.

Definition at line 299 of file Record.cc.

◆ setFieldMap() [1/2]

void mcs::Record::setFieldMap ( string  s = "")

Creates a new field map from the given string.

It often happens that user want to access a record with field names rather than indexes. This can be done with the fieldName() method. On the other hand using this method in a iteration can really slow down the execution of a program. With this method you can remap the list of indexes using field names, then access the fields with the integer provided by the map. You create the map giving a string containing, in the order you wish, the names of the fields. You don't need to citate all the fields in the list, just the ones you want to remap. Fields name must be separated by spaces.

Parameters
sString containing the map.

An example follows:

//Prepare and execute a query...
Query qry;
qry.prepare(...);
qry.execute();
//Suppose the query returned a result-set with the field named
//"Field1", "Field2" and "Field3" in this order. Now we want to
//reverse the order:
qry.newFieldMap("Field3 Field2 Field1");
//Direct access to the fields....
qry.field(0) //Field1
qry.field(1) //Field2
qry.field(2) //Field3
//Access through the map....
qry.mfield(0) //Field3
qry.mfield(1) //Field2
qry.mfield(2) //Field1

To restore the original order simply call this method without arguments.

Definition at line 480 of file Record.cc.

◆ setFieldMap() [2/2]

void mcs::Record::setFieldMap ( Record rec)

Copy the field map from one record to another.

Definition at line 500 of file Record.cc.

◆ setNull()

void mcs::Record::setNull ( )

Set all Data object's name to null values.

Definition at line 516 of file Record.cc.

Member Data Documentation

◆ array

Dynamic_Array<Data> mcs::Record::array
private

Array of fields.

Definition at line 4176 of file mcs.hh.

◆ lmap

Dynamic_Array<int> mcs::Record::lmap
private

Array of mapped fields.

Definition at line 4179 of file mcs.hh.

◆ smap

string mcs::Record::smap
private

String representation of the map.

Definition at line 4182 of file mcs.hh.


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

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018