mcs::RecordSet Class Reference

#include <mcs.hh>

Inheritance diagram for mcs::RecordSet:

Inheritance graph
[legend]

List of all members.


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

Definition at line 4525 of file mcs.hh.


Public Member Functions

bool alwaysSameStructure ()
void dump (string fn)
bool eof ()
void insert (Record &rec)
 Copy a new record in the set.
void insert (Record *rec)
 Insert a new record in the set.
bool know_nRows ()
Recordmetarec ()
int nFields ()
 Returns number of fields.
unsigned int nRows ()
RecordSetoperator= (const RecordSet &)
 Declared to avoid using of default assignment operator.
unsigned int pos ()
RecordprepRecToSend ()
Recordrec ()
 RecordSet ()
 Build an empty record set.
 RecordSet (const RecordSet &)
 Declared to avoid using of default copy constructor.
void setFieldMap (string s="")
 Set up a field map for each record in the recordset.
bool setFirst ()
 Set the record pointer to the first position.
bool setLast ()
 Set the record pointer to the last position.
bool setNext ()
 Set the record pointer to the next position.
bool setPos (unsigned int i)
 Set the record pointer to the i-th position.
bool setPrev ()
 Set the record pointer to the previous position in the set.
bool setWhere (int field, int equalTo)
 Set the record pointer to the position which satisfies an integer condition.
bool setWhere (int i, string equalTo)
 Set the record pointer to the position which satisfies a string condition.
virtual ~RecordSet ()
 Destructor.

Protected Member Functions

virtual bool fetch (unsigned int newpos, bool random)
 The virtual method to fetch new records.
virtual void hk_dump (string fn)
 Virtual method to provide dump facility to a file.
void init (unsigned char code, unsigned int nrows=0, Record *meta=NULL, short int id=0)
 Initailize the Record set.
void startFetch ()
 Must be called when record fetching is possible.

Private Member Functions

void clear ()
bool internal_fetch (unsigned int newpos)
 Fetch a new Record object in the set.
virtual RecordnewRecord ()
 Creates a new Record object in the heap.

Private Attributes

unsigned char code
 Flags used in the init() method.
unsigned int current
 Internal position in the Dynamic_Array object.
bool laccum
 If all records has been fetched during the init() call.
bool leof
 If the current position (lpos) is at the end of the set.
bool lfetch
 If true the fetch mechanism will be used.
short int lid
 General purpose identificator.
bool linsert
 If true the insert mechanism will be used.
bool lknow_nrows
 If the number of records is known.
Record lmetarec
 Record of meta structure, to be used only if lusemetarec is true.
unsigned int lnrows
 Number of records, to be used only if lknow_nrows is true.
unsigned int lpos
 Current position in the recordset.
bool lrandom
 If random access (setFirst, setLast, setPos) is allowed.
bool lusemetarec
 If all records share the same meta structure.
Dynamic_Array< Recordrs
 Internal Record set.

Constructor & Destructor Documentation

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.

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.

mcs::RecordSet::~RecordSet (  )  [virtual]

Destructor.

Definition at line 585 of file Record.cc.


Member Function Documentation

bool mcs::RecordSet::fetch ( unsigned int  newpos,
bool  random 
) [protected, virtual]

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:
newpos The position of the record to be fetched;
random If true a random access is requested.
Returns:
False if there are no more records to be fetched, true otherwise.

Reimplemented in mcs::Query, mcs::Client, and mcs::FITSReader.

Definition at line 743 of file Record.cc.

void mcs::RecordSet::hk_dump ( string  fn  )  [protected, virtual]

Virtual method to provide dump facility to a file.

Definition at line 928 of file Record.cc.

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:

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

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

Definition at line 638 of file Record.cc.

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:
rec Reference to a Record object.

Definition at line 683 of file Record.cc.

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:
rec Address to a Record object.

Definition at line 673 of file Record.cc.

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.

Record * mcs::RecordSet::newRecord (  )  [private, virtual]

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.;

Reimplemented in mcs::Query.

Definition at line 601 of file Record.cc.

int mcs::RecordSet::nFields (  ) 

Returns number of fields.

Definition at line 765 of file Record.cc.

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.

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.

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:
ERROR MSG_NOT_A_RANDOM_ACCESS_RECORDSET.

Definition at line 829 of file Record.cc.

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:
ERROR MSG_NOT_A_RANDOM_ACCESS_RECORDSET;
ERROR MSG_DONT_KNOW_NROWS.

Definition at line 839 of file Record.cc.

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:
ERROR MSG_ALREADY_AT_END_OF_FILE;

Definition at line 809 of file Record.cc.

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:
i New position.
Returns:
False if there are no more records to be fetched, true otherwise (! eof).
Exceptions:
ERROR MSG_NOT_A_RANDOM_ACCESS_RECORDSET;
ERROR MSG_DONT_KNOW_NROWS;
ERROR MSG_INDEX_OUT_RANGE.

Definition at line 850 of file Record.cc.

bool mcs::RecordSet::setPrev (  ) 

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

Returns:
Always true.
Exceptions:
ERROR MSG_NOT_A_RANDOM_ACCESS_RECORDSET;
ERROR MSG_DONT_KNOW_NROWS.

Definition at line 817 of file Record.cc.

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:
i Index of field on which perform the check;
equalTo Value 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:
ERROR MSG_NO_SAME _META_INFO;
ERROR MSG_INDEX_OUT_RANGE.

Definition at line 894 of file Record.cc.

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:
i Index of field on which perform the check;
equalTo Value 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:
ERROR MSG_NO_SAME_META_INFO;
ERROR MSG_INDEX_OUT_RANGE.

Definition at line 865 of file Record.cc.

void mcs::RecordSet::startFetch (  )  [protected]

Must be called when record fetching is possible.

Definition at line 693 of file Record.cc.


Member Data Documentation

unsigned char mcs::RecordSet::code [private]

Flags used in the init() method.

Reimplemented in mcs::Client.

Definition at line 4531 of file mcs.hh.

unsigned int mcs::RecordSet::current [private]

Internal position in the Dynamic_Array object.

Definition at line 4558 of file mcs.hh.

bool mcs::RecordSet::laccum [private]

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

Definition at line 4540 of file mcs.hh.

bool mcs::RecordSet::leof [private]

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

Definition at line 4564 of file mcs.hh.

bool mcs::RecordSet::lfetch [private]

If true the fetch mechanism will be used.

Definition at line 4549 of file mcs.hh.

short int mcs::RecordSet::lid [private]

General purpose identificator.

Definition at line 4528 of file mcs.hh.

bool mcs::RecordSet::linsert [private]

If true the insert mechanism will be used.

Definition at line 4552 of file mcs.hh.

bool mcs::RecordSet::lknow_nrows [private]

If the number of records is known.

Definition at line 4534 of file mcs.hh.

Record mcs::RecordSet::lmetarec [private]

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

Definition at line 4561 of file mcs.hh.

unsigned int mcs::RecordSet::lnrows [private]

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

Definition at line 4537 of file mcs.hh.

unsigned int mcs::RecordSet::lpos [private]

Current position in the recordset.

Definition at line 4555 of file mcs.hh.

bool mcs::RecordSet::lrandom [private]

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

Definition at line 4543 of file mcs.hh.

bool mcs::RecordSet::lusemetarec [private]

If all records share the same meta structure.

Definition at line 4546 of file mcs.hh.

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

Internal Record set.

Definition at line 4567 of file mcs.hh.


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

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012