home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- //////////////////////////////////////////////////////////////
- // Database.h --
- //////////////////////////////////////////////////////////////
- #ifndef DATABASE_H
- #define DATABASE_H
-
-
-
- #include "parody.h"
- #include "OkStr.h"
- #include "OkStrArray.h"
- #include "OkTPtrArray.h"
-
-
- enum ClassIdent {
- SETUP_FIELDS=1,
- SETUP_ATTRIBUTES,
- CARD_DIRECTORY,
- FIELDS_SETUP,
- CARD_INFO
- };
-
-
- // Generic Integer Key.
-
- class IntKey : public Key {
- int _key;
-
- int operator>( Key &key ) { return _key>((IntKey &) key).key(); }
- int operator==( Key &key ) { return _key==((IntKey &) key).key(); }
-
- Key& operator=( Key &key ) {
- if ( this != &key ) {
- Key::operator=(key);
- IntKey& intKey = (IntKey&) key;
- _key = intKey._key;
- }
- return *this;
- }
-
- void Write( fstream& ndx ) { ndx.write( (char *) &_key, sizeof _key ); }
- void Read( fstream& ndx ) { ndx.read( (char *) &_key, sizeof _key ); }
-
- Key *Make() { return new IntKey(); }
- pBool isNullValue() { return (pBool) ( _key==0 ); }
-
- public:
- IntKey( int key=0 ) { _key = key; }
- int key() const { return _key; }
- };
-
- enum SortOrder { ASCENDING, DESCENDING };
-
- typedef OkTPtrArray<ObjAddr> ObjAddrArray;
-
- class CardDirectory : public Persistent {
-
- IntKey _key;
- ObjAddrArray _objAddrArray;
- SortOrder _sortOrder;
-
- public:
- CardDirectory();
- ~CardDirectory();
-
- ObjAddr objAddr( unsigned pos ) { return _objAddrArray[ pos-1 ]; }
-
- unsigned totalCards() { return _objAddrArray.length(); }
- void add( ObjAddr objAddr, unsigned pos=0 );
- void remove( unsigned pos );
- void removeAll();
-
- void sort( SortOrder );
- SortOrder sortOrder() const { return _sortOrder; }
-
-
- protected:
- // Persistent funcs.
- void Read();
- void Write();
-
- };
-
-
- class CardInfo;
- class ExportImportDialog;
-
- class Database : public Parody {
-
- friend ExportImportDialog;
-
- CardDirectory* _cardDirectory;
-
- private:
- OkStr _dbName;
-
- Boolean _dirty;
-
- public:
- Database( const char* name );
- ~Database();
- void save();
-
- const char* dbName() const { return _dbName; }
- int totalCards() const { return _cardDirectory->totalCards(); }
-
- // Caller is responsible to delete returned CardInfo from
- // cardInfo and addCard.
- // pos = {1 ... totalCards)
- CardInfo* cardInfo( unsigned pos );
- CardInfo* addCard( const char* name, unsigned pos=0 );
- CardInfo* addCard( CardInfo* cInfo, unsigned pos=0 );
-
- void deleteCard( unsigned pos, CardInfo* cInfo=NULL );
- void deleteAllCards();
-
- void load( OkStr& listHeader, OkStrArray& listItems );
- static void Load( OkStr& item, const CardInfo* cInfo );
-
- SortOrder sortOrder() const { return _cardDirectory->sortOrder(); }
- void sort( SortOrder sortOrder ) { _cardDirectory->sort( sortOrder ); }
-
- // Search card that has string s.
- // Returns card number, or 0 if none found.
- enum Direction { FORWARD, BACKWARD };
- int searchCard( OkStr s,
- int from=0,
- Direction direction=FORWARD,
- Boolean caseSensitive=FALSE,
- Boolean srchNotesToo=FALSE );
-
- };
-
- extern Database *theDatabase;
-
-
- #endif
-