MCS
0.3.3-alpha7
|
The base class that implement the data abstraction layer. More...
#include <mcs.hh>
Public Member Functions | |
bool | alwaysSameStructure () |
void | dump (string fn) |
bool | eof () |
void | insert (Record *rec) |
Insert a new record in the set. More... | |
void | insert (Record &rec) |
Copy a new record in the set. More... | |
bool | know_nRows () |
Record & | metarec () |
int | nFields () |
Returns number of fields. More... | |
unsigned int | nRows () |
RecordSet & | operator= (const RecordSet &) |
Declared to avoid using of default assignment operator. More... | |
unsigned int | pos () |
Record * | prepRecToSend () |
Record & | rec () |
RecordSet (const RecordSet &) | |
Declared to avoid using of default copy constructor. More... | |
RecordSet () | |
Build an empty record set. More... | |
void | setFieldMap (string s="") |
Set up a field map for each record in the recordset. More... | |
bool | setFirst () |
Set the record pointer to the first position. More... | |
bool | setLast () |
Set the record pointer to the last position. More... | |
bool | setNext () |
Set the record pointer to the next position. More... | |
bool | setPos (unsigned int i) |
Set the record pointer to the i-th position. More... | |
bool | setPrev () |
Set the record pointer to the previous position in the set. More... | |
bool | setWhere (int i, string equalTo) |
Set the record pointer to the position which satisfies a string condition. More... | |
bool | setWhere (int field, int equalTo) |
Set the record pointer to the position which satisfies an integer condition. More... | |
virtual | ~RecordSet () |
Destructor. More... | |
Protected Member Functions | |
virtual bool | fetch (unsigned int newpos, bool random) |
The virtual method to fetch new records. More... | |
virtual void | hk_dump (string fn) |
Virtual method to provide dump facility to a file. More... | |
void | init (unsigned char code, unsigned int nrows=0, Record *meta=NULL, short int id=0) |
Initailize the Record set. More... | |
void | startFetch () |
Must be called when record fetching is possible. More... | |
Private Member Functions | |
void | clear () |
bool | internal_fetch (unsigned int newpos) |
Fetch a new Record object in the set. More... | |
virtual Record * | newRecord () |
Creates a new Record object in the heap. More... | |
Private Attributes | |
unsigned char | code |
Flags used in the init() method. More... | |
unsigned int | current |
Internal position in the Dynamic_Array object. More... | |
bool | laccum |
If all records has been fetched during the init() call. More... | |
bool | leof |
If the current position (lpos) is at the end of the set. More... | |
bool | lfetch |
If true the fetch mechanism will be used. More... | |
short int | lid |
General purpose identificator. More... | |
bool | linsert |
If true the insert mechanism will be used. More... | |
bool | lknow_nrows |
If the number of records is known. More... | |
Record | lmetarec |
Record of meta structure, to be used only if lusemetarec is true. More... | |
unsigned int | lnrows |
Number of records, to be used only if lknow_nrows is true. More... | |
unsigned int | lpos |
Current position in the recordset. More... | |
bool | lrandom |
If random access (setFirst, setLast, setPos) is allowed. More... | |
bool | lusemetarec |
If all records share the same meta structure. More... | |
Dynamic_Array< Record > | rs |
Internal Record set. More... | |
The base class that implement the data abstraction layer.
This class provide the basic framework of the data abstraction layer, in particular it offer to the user a uniform interface to access the Record objects read from the source. Each class used as a data source through the data abstraction layer must derive this class.
This class basically represent a collection (or set) of records. When the set is not empty there is always a "current" record, available through the rec() method. To change the current record you can use the setNext() method to move to the next record. Depending on the set there are also other method to browse the set (setFirst(), setPrev(), setLast(), setWhere()).
This class can work in two "modes":
mcs::RecordSet::RecordSet | ( | const RecordSet & | ) |
Declared to avoid using of default copy constructor.
mcs::RecordSet::RecordSet | ( | ) |
|
protectedvirtual |
The virtual method to fetch new records.
This method is automatically called from internal_fetch() to fetch new records. It must be overrided in a derived class, otherwise an exception will be thrown. If the "accum" parameter in the init() call was true, then all records will be fetched during the init() call, otherwise they'll be fetched when they are needed.
The record to be fetched is the one in the position (of the set) indicated by the "newpos" parameter. Anyway not all Record set can provide random access, so if you pass "random = false" in the init() call you are guaranteed that "newpos" will be incremented by one in each call, starting from zero. If the random access is allowed you will know if the record to be fetched is really the next in the set from the second parameter. When this is false the next record in the set is to be fetched, when this is true the position requested is random, that is not predictable.
newpos | The position of the record to be fetched; |
random | If true a random access is requested. |
|
protectedvirtual |
|
protected |
Initailize the Record set.
This metod must be called from a derived class to provide information about the Record set to the parent one.
The first argument is a combination of one or more of the following flags:
If you want to use the meta informations you should provide them before calling this method, through the metarec() method.
accum | If all records must be fetched during this call; |
usemetarec | If the meta informations has been provided; |
know_nrows | If the number of records is known; |
random | If the random access to the set is allowed; |
nrows | The number of rows, if known. |
void mcs::RecordSet::insert | ( | Record * | rec | ) |
Insert a new record in the set.
The insert() method provide an alternative method to fetch() to insert records in the set. With this method you can insert Record objects allocated in the heap. These objects will not be copied and will be destroyed by the RecordSet object.
rec | Address to a Record object. |
void mcs::RecordSet::insert | ( | Record & | rec | ) |
|
private |
|
privatevirtual |
Creates a new Record object in the heap.
If lusemetarec is true then the record will be created with the same meta structure as the lmetarec object.
Users can override this method to provide a customized build Record object.
This method is automatically called by internal_fetch() when a new record is required.;
Declared to avoid using of default assignment operator.
void mcs::RecordSet::setFieldMap | ( | string | s = "" | ) |
Set up a field map for each record in the recordset.
This method can be used only on those recordsets which have a "meta" record, that is MCS_RS_USEMETAREC has been used while calling init(). With this method you set a field map in the "meta" recordset which will be automatically replicated in all records belonging to the set.
bool mcs::RecordSet::setFirst | ( | ) |
bool mcs::RecordSet::setLast | ( | ) |
bool mcs::RecordSet::setNext | ( | ) |
bool mcs::RecordSet::setPos | ( | unsigned int | i | ) |
Set the record pointer to the i-th position.
Index must be in the allowed range (0 <= i < nRows()). Throw a Event exception if i is beyond eof() or if the record set doen'st allow random access.
i | New position. |
ERROR | MSG_NOT_A_RANDOM_ACCESS_RECORDSET; |
ERROR | MSG_DONT_KNOW_NROWS; |
ERROR | MSG_INDEX_OUT_RANGE. |
bool mcs::RecordSet::setPrev | ( | ) |
bool mcs::RecordSet::setWhere | ( | int | i, |
string | equalTo | ||
) |
Set the record pointer to the position which satisfies a string condition.
The condition is that the value on i-th field must be equal to the "equalTo" string. The index "i" must be in the allowed range (0<= i < nFields()).
i | Index of field on which perform the check; |
equalTo | Value to compare with the content of the field. |
ERROR | MSG_NO_SAME_META_INFO; |
ERROR | MSG_INDEX_OUT_RANGE. |
bool mcs::RecordSet::setWhere | ( | int | field, |
int | equalTo | ||
) |
Set the record pointer to the position which satisfies an integer condition.
The condition is that the value on i-th field must be equal to the "equalTo" integer. The index "i" must be in the allowed range (0<= i < nFields()).
i | Index of field on which perform the check; |
equalTo | Value to compare with the content of the field. |
ERROR | MSG_NO_SAME _META_INFO; |
ERROR | MSG_INDEX_OUT_RANGE. |
|
protected |
|
private |
|
private |
Internal position in the Dynamic_Array object.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha7
|