MCS  0.3.3-alpha7
mcs::RecordSet Class Reference

The base class that implement the data abstraction layer. More...

#include <mcs.hh>

+ Inheritance diagram for mcs::RecordSet:

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 ()
 
Recordmetarec ()
 
int nFields ()
 Returns number of fields. More...
 
unsigned int nRows ()
 
RecordSetoperator= (const RecordSet &)
 Declared to avoid using of default assignment operator. More...
 
unsigned int pos ()
 
RecordprepRecToSend ()
 
Recordrec ()
 
 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 RecordnewRecord ()
 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< Recordrs
 Internal Record set. More...
 

Detailed Description

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":

  • insert mode: in this case the class can be used "as is", without being derived. Records can be inserted into the set using the insert() method.
  • fetch mode: in this case the class must be derived and the fetch() virtual method must be overrided.

Definition at line 4510 of file mcs.hh.

Constructor & Destructor Documentation

◆ RecordSet() [1/2]

mcs::RecordSet::RecordSet ( const RecordSet )

Declared to avoid using of default copy constructor.

Warning
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

◆ RecordSet() [2/2]

mcs::RecordSet::RecordSet ( )

Build an empty record set.

Before fetching records you should call init(), passing all necessary parameters.

Definition at line 577 of file Record.cc.

◆ ~RecordSet()

mcs::RecordSet::~RecordSet ( )
virtual

Destructor.

Definition at line 585 of file Record.cc.

Member Function Documentation

◆ fetch()

bool mcs::RecordSet::fetch ( unsigned int  newpos,
bool  random 
)
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.

Parameters
newposThe position of the record to be fetched;
randomIf true a random access is requested.
Returns
False if there are no more records to be fetched, true otherwise.

Definition at line 743 of file Record.cc.

◆ hk_dump()

void mcs::RecordSet::hk_dump ( string  fn)
protectedvirtual

Virtual method to provide dump facility to a file.

Definition at line 928 of file Record.cc.

◆ init()

void mcs::RecordSet::init ( unsigned char  code,
unsigned int  nrows = 0,
Record meta = NULL,
short int  id = 0 
)
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:

  • MCS_RS_ACCUM
  • MCS_RS_USEMETAREC
  • MCS_RS_KNOW_NROWS
  • MCS_RS_RANDOM
  • MCS_RS_INSERT

If you want to use the meta informations you should provide them before calling this method, through the metarec() method.

Parameters
accumIf all records must be fetched during this call;
usemetarecIf the meta informations has been provided;
know_nrowsIf the number of records is known;
randomIf the random access to the set is allowed;
nrowsThe number of rows, if known.

Definition at line 638 of file Record.cc.

◆ insert() [1/2]

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.

Parameters
recAddress to a Record object.

Definition at line 673 of file Record.cc.

◆ insert() [2/2]

void mcs::RecordSet::insert ( Record rec)

Copy 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 a copy of a Record object. These objects will be copied in the set as a new record.

Parameters
recReference to a Record object.

Definition at line 683 of file Record.cc.

◆ internal_fetch()

bool mcs::RecordSet::internal_fetch ( unsigned int  newpos)
private

Fetch a new Record object in the set.

If laccum is true a new Record object will be created for each effective record, otherwise a single Record object will be used (rs[0]). Users should not override this method because it is a very important one, instead override fetch().

Definition at line 723 of file Record.cc.

◆ newRecord()

Record * mcs::RecordSet::newRecord ( )
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.;

Definition at line 601 of file Record.cc.

◆ nFields()

int mcs::RecordSet::nFields ( )

Returns number of fields.

Definition at line 765 of file Record.cc.

◆ operator=()

RecordSet& mcs::RecordSet::operator= ( const RecordSet )

Declared to avoid using of default assignment operator.

Warning
This operator is declared but not implemented. If you try to use it you will get a compilation error.

◆ setFieldMap()

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.

Definition at line 590 of file Record.cc.

◆ setFirst()

bool mcs::RecordSet::setFirst ( )

Set the record pointer to the first position.

Returns
False if there are no more records to be fetched, true otherwise (! eof).
Exceptions
ERRORMSG_NOT_A_RANDOM_ACCESS_RECORDSET.

Definition at line 829 of file Record.cc.

◆ setLast()

bool mcs::RecordSet::setLast ( )

Set the record pointer to the last position.

Returns
False if there are no more records to be fetched, true otherwise (! eof).
Exceptions
ERRORMSG_NOT_A_RANDOM_ACCESS_RECORDSET;
ERRORMSG_DONT_KNOW_NROWS.

Definition at line 839 of file Record.cc.

◆ setNext()

bool mcs::RecordSet::setNext ( )

Set the record pointer to the next position.

Returns
False if there are no more records to be fetched, true otherwise (! eof).
Exceptions
ERRORMSG_ALREADY_AT_END_OF_FILE;

Definition at line 809 of file Record.cc.

◆ setPos()

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.

Parameters
iNew position.
Returns
False if there are no more records to be fetched, true otherwise (! eof).
Exceptions
ERRORMSG_NOT_A_RANDOM_ACCESS_RECORDSET;
ERRORMSG_DONT_KNOW_NROWS;
ERRORMSG_INDEX_OUT_RANGE.

Definition at line 850 of file Record.cc.

◆ setPrev()

bool mcs::RecordSet::setPrev ( )

Set the record pointer to the previous position in the set.

Returns
Always true.
Exceptions
ERRORMSG_NOT_A_RANDOM_ACCESS_RECORDSET;
ERRORMSG_DONT_KNOW_NROWS.

Definition at line 817 of file Record.cc.

◆ setWhere() [1/2]

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

Parameters
iIndex of field on which perform the check;
equalToValue to compare with the content of the field.
Returns
True if the record was found, false otherwise, in this latter case the record pointer remain unchanged.
Exceptions
ERRORMSG_NO_SAME_META_INFO;
ERRORMSG_INDEX_OUT_RANGE.

Definition at line 865 of file Record.cc.

◆ setWhere() [2/2]

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

Parameters
iIndex of field on which perform the check;
equalToValue to compare with the content of the field.
Returns
True if the record was found, false otherwise, in this latter case the record pointer remain unchanged.
Exceptions
ERRORMSG_NO_SAME _META_INFO;
ERRORMSG_INDEX_OUT_RANGE.

Definition at line 894 of file Record.cc.

◆ startFetch()

void mcs::RecordSet::startFetch ( )
protected

Must be called when record fetching is possible.

Definition at line 693 of file Record.cc.

Member Data Documentation

◆ code

unsigned char mcs::RecordSet::code
private

Flags used in the init() method.

Definition at line 4516 of file mcs.hh.

◆ current

unsigned int mcs::RecordSet::current
private

Internal position in the Dynamic_Array object.

Definition at line 4543 of file mcs.hh.

◆ laccum

bool mcs::RecordSet::laccum
private

If all records has been fetched during the init() call.

Definition at line 4525 of file mcs.hh.

◆ leof

bool mcs::RecordSet::leof
private

If the current position (lpos) is at the end of the set.

Definition at line 4549 of file mcs.hh.

◆ lfetch

bool mcs::RecordSet::lfetch
private

If true the fetch mechanism will be used.

Definition at line 4534 of file mcs.hh.

◆ lid

short int mcs::RecordSet::lid
private

General purpose identificator.

Definition at line 4513 of file mcs.hh.

◆ linsert

bool mcs::RecordSet::linsert
private

If true the insert mechanism will be used.

Definition at line 4537 of file mcs.hh.

◆ lknow_nrows

bool mcs::RecordSet::lknow_nrows
private

If the number of records is known.

Definition at line 4519 of file mcs.hh.

◆ lmetarec

Record mcs::RecordSet::lmetarec
private

Record of meta structure, to be used only if lusemetarec is true.

Definition at line 4546 of file mcs.hh.

◆ lnrows

unsigned int mcs::RecordSet::lnrows
private

Number of records, to be used only if lknow_nrows is true.

Definition at line 4522 of file mcs.hh.

◆ lpos

unsigned int mcs::RecordSet::lpos
private

Current position in the recordset.

Definition at line 4540 of file mcs.hh.

◆ lrandom

bool mcs::RecordSet::lrandom
private

If random access (setFirst, setLast, setPos) is allowed.

Definition at line 4528 of file mcs.hh.

◆ lusemetarec

bool mcs::RecordSet::lusemetarec
private

If all records share the same meta structure.

Definition at line 4531 of file mcs.hh.

◆ rs

Dynamic_Array<Record> mcs::RecordSet::rs
private

Internal Record set.

Definition at line 4552 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