Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

GenericDB Class Reference

Generic Database class This contains the basic database functionality that does not depend on the record structre. More...

#include <GenericDB.h>

Inheritance diagram for GenericDB:

Database Database< accountStructure, packedAccountStructure > Database< currencyStructure, packedCurrencyStructure > Database< splitStructure, packedSplitStructure > Database< transactionStructure, packedTransactionStructure > AccountsDB CurrencyDB SplitsDB TransactionsDB List of all members.

Public Methods

DmOpenRef getRef () DB_SECTION2
 get the pointer to the db (to use for calling PalmOS db functions directly). More...

Boolean isNew () DB_SECTION2
 
Returns:
true if the constructor created the db instead of just opening it.
More...


UInt32 getSelectedUid () DB_SECTION2
 
Returns:
the uid of the selected_record.
More...


UInt32 getRecordUid (UInt16 id) DB_SECTION2
 Fetch the uid of a record. More...

UInt32 getRecordUid () DB_SECTION2
 Fetch the uid of the current record. More...

UInt16 getRecordId (UInt32 uid) DB_SECTION2
 Fetch the uid of a record. More...

UInt16 getRecordCategory (UInt16 id) DB_SECTION2
 Returns the category of a given record. More...

UInt16 getRecordCategory (UInt32 uid) DB_SECTION2
 Returns the category of a given record. More...

void setRecordCategory (UInt16 id, UInt16 cat) DB_SECTION2
 sets the category of a given record. More...

void setRecordCategory (UInt32 uid, UInt16 cat) DB_SECTION2
 sets the category of a given record. More...

UInt16 findCategory (Char *cat_name) DB_SECTION2
 finds a category in this db by its name. More...

void getCategoryName (UInt16 cat_id, Char *cat_name) DB_SECTION2
 fetches the name of a category in an allocated buffer. More...

void selectRecord (UInt16 id) DB_SECTION2
 sets the selected_record to id and sets record_selected flag to false. More...

void selectRecord (UInt32 uid) DB_SECTION2
 sets the selected_record from an unique and sets record_selected flag to false. More...

void unselectRecord () DB_SECTION2
 if a record is selected this function unselects it (by setting the record_selected flag). More...

Boolean isRecordSelected () DB_SECTION2
 use this function to find out whether a record from the database is currently selected. More...

UInt16 getSelectedRecord () DB_SECTION2
 use this function to retrieve the currently selected record. More...

 GenericDB (DmOpenRef db_open_ref) DB_SECTION2
 create a database using a reference to an already opened database. More...

 GenericDB (UInt32 type, UInt32 creator, Char *db_name) DB_SECTION2
 create a database without using categories. More...

 GenericDB (UInt32 type, UInt32 creator, Char *db_name, UInt16 categ_string) DB_SECTION2
 create a database with category support. More...

virtual ~GenericDB () DB_SECTION2
void writeAndAdvance (MemPtr s, UInt32 &offset, Char *str) DB_SECTION2
 This function writes a given string into a structure; it is meant as a helper function for Database::packRecord. More...

template<class Field> void writeAndAdvance (MemPtr s, UInt32 &offset, Field *f) DB_SECTION2
 This is a helper function for pack record. More...

virtual bool deleteRecord (UInt16 id) DB_SECTION2
 Deletes a record given by its id. More...

virtual bool deleteRecord (UInt32 uid) DB_SECTION2
 Deletes a record given by its uid. More...


Public Attributes

UInt16 current_cat
 the currenct category. More...


Protected Methods

Err openOrCreate (UInt32 type, UInt32 creator, UInt16 mode, UInt16 cardNo, Char *name) DB_SECTION2
 opens or creates a database. More...

MemPtr getLockedAppInfo () DB_SECTION2
 returns a pointer to the app info record. More...

MemPtr getLockedAppInfo (UInt16 categ_string) DB_SECTION2
 returns a pointer to the app info record. More...

MemPtr appInfoInit (LocalID dbID, UInt16 cardNo) DB_SECTION2
 used by the func above to initialise the app info rec if it is empty. More...

MemPtr appInfoInit (LocalID dbID, UInt16 cardNo, UInt16 categ_string) DB_SECTION2
 used by the func above to initialise the app info rec if it is empty. More...


Protected Attributes

DmOpenRef ref
 reference to the database. More...

UInt32 num_cat
 total number of categories. More...

Boolean created
 true if the db had to be created when it was opened. More...

Boolean record_selected
 true if a record is selected, false otherwise. More...

UInt16 selected_record
 the current record. More...


Detailed Description

Generic Database class This contains the basic database functionality that does not depend on the record structre.

Definition at line 41 of file GenericDB.h.


Constructor & Destructor Documentation

GenericDB::GenericDB (  DmOpenRef    db_open_ref ) 
 

create a database using a reference to an already opened database.

GenericDB::GenericDB (  UInt32    type,
UInt32    creator,
Char *    db_name
) 
 

create a database without using categories.

GenericDB::GenericDB (  UInt32    type,
UInt32    creator,
Char *    db_name,
UInt16    categ_string
) 
 

create a database with category support.

virtual GenericDB::~GenericDB (    )  [virtual]
 


Member Function Documentation

MemPtr GenericDB::appInfoInit (  LocalID    dbID,
UInt16    cardNo,
UInt16    categ_string
)  [protected]
 

used by the func above to initialise the app info rec if it is empty.

MemPtr GenericDB::appInfoInit (  LocalID    dbID,
UInt16    cardNo
)  [protected]
 

used by the func above to initialise the app info rec if it is empty.

virtual bool GenericDB::deleteRecord (  UInt32    uid )  [virtual]
 

Deletes a record given by its uid.

Parameters:
uid  the unique id of the record to be deleted
Returns:
true if deleted successfuly, false otherwise

virtual bool GenericDB::deleteRecord (  UInt16    id )  [virtual]
 

Deletes a record given by its id.

Parameters:
id  the id of the record to be deleted
Returns:
true if deleted successfuly, false otherwise

Reimplemented in AccountsDB.

UInt16 GenericDB::findCategory (  Char *    cat_name ) 
 

finds a category in this db by its name.

Parameters:
cat_name  the name of the category to be found
Returns:
the category id

void GenericDB::getCategoryName (  UInt16    cat_id,
Char *    cat_name
) 
 

fetches the name of a category in an allocated buffer.

Parameters:
cat_id  the id of the category (in the current db only)
cat_name  allocated buffer to which the name will be written

MemPtr GenericDB::getLockedAppInfo (  UInt16    categ_string )  [protected]
 

returns a pointer to the app info record.

Parameters:
categ_string  the function will use this id to initialise the categories for the db

MemPtr GenericDB::getLockedAppInfo (    )  [protected]
 

returns a pointer to the app info record.

UInt16 GenericDB::getRecordCategory (  UInt32    uid ) 
 

Returns the category of a given record.

Parameters:
index  unique id of the record
Returns:
the record category

UInt16 GenericDB::getRecordCategory (  UInt16    id ) 
 

Returns the category of a given record.

Parameters:
id  the id of the record
Returns:
the record category

UInt16 GenericDB::getRecordId (  UInt32    uid ) 
 

Fetch the uid of a record.

Parameters:
uid  the record uid
Returns:
the record id

Referenced by Database::getUnpackedRecord.

UInt32 GenericDB::getRecordUid (    ) 
 

Fetch the uid of the current record.

Returns:
the record uid

UInt32 GenericDB::getRecordUid (  UInt16    id ) 
 

Fetch the uid of a record.

Parameters:
id  the record id
Returns:
the record uid

DmOpenRef GenericDB::getRef (    ) 
 

get the pointer to the db (to use for calling PalmOS db functions directly).

Returns:
pointer to the db (DmOpenRef)

UInt16 GenericDB::getSelectedRecord (    ) 
 

use this function to retrieve the currently selected record.

Returns:
the index of the selected record

UInt32 GenericDB::getSelectedUid (    ) 
 

Returns:
the uid of the selected_record.

Boolean GenericDB::isNew (    ) 
 

Returns:
true if the constructor created the db instead of just opening it.

Boolean GenericDB::isRecordSelected (    ) 
 

use this function to find out whether a record from the database is currently selected.

Returns:
true if a record is selected, false otherwise

Referenced by Database::getUnpackedRecord.

Err GenericDB::openOrCreate (  UInt32    type,
UInt32    creator,
UInt16    mode,
UInt16    cardNo,
Char *    name
)  [protected]
 

opens or creates a database.

Parameters:
type  database type
creator  database creator
mode  mode in which to open the database
name  db name
created  on return is set to true if the db had to be created

void GenericDB::selectRecord (  UInt32    uid ) 
 

sets the selected_record from an unique and sets record_selected flag to false.

Parameters:
id  id of the record to be selected

void GenericDB::selectRecord (  UInt16    id ) 
 

sets the selected_record to id and sets record_selected flag to false.

Parameters:
id  id of the record to be selected

void GenericDB::setRecordCategory (  UInt32    uid,
UInt16    cat
) 
 

sets the category of a given record.

Parameters:
uid  unique id of the record
cat  the record category

void GenericDB::setRecordCategory (  UInt16    id,
UInt16    cat
) 
 

sets the category of a given record.

Parameters:
id  id of the record
cat  the record category

Referenced by Database::newRecord.

void GenericDB::unselectRecord (    ) 
 

if a record is selected this function unselects it (by setting the record_selected flag).

template<class Field>
void GenericDB::writeAndAdvance (  MemPtr    s,
UInt32 &    offset,
Field *    f
) 
 

This is a helper function for pack record.

Given a field from a structure together with a destination pointer and an offset it will write the field in the specified location.

Parameters:
s  pointer to the start of the block where the str is to be written
offset  offset within the block. note that offset is changed by the function
f  a pointer to the field to be written. if it is a char* it will (hopefully) be handled by the other writeAndAdvance funcition

Definition at line 155 of file Database.h.

void GenericDB::writeAndAdvance (  MemPtr    s,
UInt32 &    offset,
Char *    str
) 
 

This function writes a given string into a structure; it is meant as a helper function for Database::packRecord.

Also see Database::writeAndAdvance.

Note:
I am actually amazed that C++ can handle polymorphism in this way...
Parameters:
s  pointer to the start of the block where the str is to be written
offset  offset within the block. note that offset is changed by the function
str  string to be written


Member Data Documentation

Boolean GenericDB::created [protected]
 

true if the db had to be created when it was opened.

Definition at line 163 of file GenericDB.h.

UInt16 GenericDB::current_cat
 

the currenct category.

Definition at line 45 of file GenericDB.h.

Referenced by Database::newRecord.

UInt32 GenericDB::num_cat [protected]
 

total number of categories.

Definition at line 161 of file GenericDB.h.

Boolean GenericDB::record_selected [protected]
 

true if a record is selected, false otherwise.

Definition at line 165 of file GenericDB.h.

DmOpenRef GenericDB::ref [protected]
 

reference to the database.

Definition at line 159 of file GenericDB.h.

Referenced by Database::getUnpackedRecord, and Database::newRecord.

UInt16 GenericDB::selected_record [protected]
 

the current record.

Definition at line 167 of file GenericDB.h.

Referenced by Database::getUnpackedRecord.


The documentation for this class was generated from the following files:
Generated on Thu Jan 16 23:11:15 2003 for FreeCoins by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002