home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 Mobile
/
Chip_Mobile_2001.iso
/
palm
/
business
/
printcar
/
printcar.exe
/
src
/
CardList.cc
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-04
|
1KB
|
68 lines
//
// $Id: CardList.cc,v 1.2 2000/06/04 00:50:46 sergey Exp $
//
#include <Pilot.h>
#include "CardList.h"
#include "Util/Assert.h"
// Constants
static const char* CARD_DB_NAME = "PrintCardDB";
// construction
CardList::CardList():
_recordCount(0),
_lastIndex(-1)
{}
// operations
int CardList::recordCount() const
{
return ensureDatabaseOpened()? _recordCount : 0;
}
const CardRecord& CardList::record(int index) const
{
if (!ensureRecordLoaded(index))
assertf(false, "Fail to read Card record %d", index);
return _currentRecord;
}
// implementation
bool CardList::ensureDatabaseOpened() const
{
if (!_database.isOpened())
{
if (!_database.open(0, CARD_DB_NAME, dmModeReadOnly))
return false;
// store the amount of Card records in the database
_recordCount = CardRecord::countRecords(_database);
}
return true;
}
bool CardList::ensureRecordLoaded(int index) const
{
if (index == _lastIndex)
return true;
if (ensureDatabaseOpened())
{
if (_currentRecord.load(index, _database))
{
_lastIndex = index;
return true;
}
}
_lastIndex = -1;
return false;
}