home *** CD-ROM | disk | FTP | other *** search
- #ifndef H_OOF1
- #define H_OOF1
-
- // COPYRIGHT 1994 A.D. Software, All rights reserved
-
- // public layer of OOFILE database
-
- // NOTE inline definitions included at end of this header file
-
- // see misc.txt for code conventions
- #include "oof0.hpp"
- #ifdef _Macintosh
- #include <Types.h>
- #endif
-
-
- enum OOF_IndexOptions { kNotIndexed=0, kIndexed=1, kIndexNoDups=2, kIndexCaseSensitive=4,
- kIndexCompressLeading=8, kIndexCompressPadding=16,
- kIndexCompress = kIndexCompressLeading + kIndexCompressPadding,
- kIndexCompressNoDups = kIndexCompress + kIndexNoDups,
- kIndexCompressLeadingNoDups = kIndexCompressLeading + kIndexNoDups,
- kIndexCompressPaddingNoDups = kIndexCompressPadding + kIndexNoDups
- };
- ostream& operator<<(ostream&, OOF_IndexOptions);
-
-
- typedef unsigned short fieldNumT; // never more than 64k fields in a record!
-
- // utility functions
- void validateDatabaseState();
- bool skipTillDigit(istream&);
-
-
- class OOF_String {
- public:
- // constructors
- OOF_String(const OOF_String&);
- OOF_String(const OOF_String&, const char *);
- OOF_String(const OOF_String&, const char, const char *);
- OOF_String(const OOF_String&, const char *, const OOF_String&);
- OOF_String(const char *chars=0); // default
- ~OOF_String();
-
- // other protocol
- OOF_String& operator=(const OOF_String&);
- OOF_String& operator=(const char*);
- operator char *() const;
- char *adopt();
- bool isEmpty() const;
-
- protected:
- // data storage
- char *mBody; // owned
- unsigned int mLen;
-
- public:
- static char sEmptyStr;
- };
- ostream& operator<<(ostream&, const OOF_String&);
-
-
- #ifdef _Macintosh
- class OOF_MacString : public OOF_String {
- public:
- OOF_MacString(const Str63);
- };
- #endif
-
-
-
- class dbQueryClause;
- class dbRelHalf;
- class dbRelChain;
- class dbRelRefBase;
- class OOF_relChainList;
- class dbRelationship;
- class dbField;
- class OOF_tableBackend;
- class OOF_Context;
- class dbConnect;
-
- class dbTable : public dbClass {
- public:
- dbTable(const char *); // MUST name tables
- dbTable(const dbTable&);
- virtual ~dbTable();
- private:
- void operator=(const dbTable&) {assert(0);};
- public:
- void setName(const char*);
- virtual dbTable* cloneWithoutSelection();
- // operator dbTable*();
-
- void attachPartRelation(dbRelHalf*);
- // used to setup relations
- void joinField(dbField&);
- void pathNamedAs(const char*);
- dbRelChain* buildRelChain(dbRelChain*);
- void assignRelChainToAllFields(dbRelChain*);
-
- // other protocol
- bool loadRelatedContextJoiningFromTo(const dbField*, const dbField*);
- enum saveOptions{requireExplicit, autoOnContextChange, requireExplicitAndBuffer};
- void setSaveOption(const saveOptions);
- dbField *field(fieldNumT);
- dbField *field(const char *);
- OOF_String tableName() const;
- void setOIDfield(const dbField&) const;
- bool pointsToBackend(const OOF_tableBackend*) const;
- virtual bool canSaveRecord(); // expect user override in many cases
-
- void attachfield(dbField*);
- void buildSchema();
- void createTableInConnection(const dbConnect*);
- void openTableInConnection(const dbConnect*);
- unsigned int numIndexes() const;
- unsigned int numFiles() const;
- long sequenceNumber() const;
-
- // current record context management
- bool contextChangedFrom(const OOF_Context*) const;
- void updateContext(OOF_Context*) const;
- OOF_Context* createContext() const;
- void returnToContext(OOF_Context*);
-
- // recordwise access
- void start();
- void next();
- void first();
- void prev();
- void last();
-
- bool more() const;
- bool atFirst() const;
- bool atLast() const;
-
- unsigned long count() const;
- unsigned long countAll() const;
-
- void sortBy(const dbField&);
- void sortBy(const dbField*);
- void unloadRecord();
- bool isRecordLoaded() const;
- bool isDirty() const;
- unsigned long recordNumber() const;
-
- // public search functions
- bool gotoRelativeRecord(unsigned long);
- bool gotoRecord(unsigned long);
- bool searchDefaultIndex(const char*);
- void selectAll();
- void selectNone();
- bool search(const dbQueryClause& query);
- bool searchSelection(const dbQueryClause& query);
-
- // selection functions
- void difference_with(const dbTable&);
- void operator -=(const dbTable&);
- void operator %=(const dbTable&);
-
- void intersection_with(const dbTable&);
- void operator &=(const dbTable&);
-
- void union_with(const dbTable&);
- void operator +=(const dbTable&);
- void operator |=(const dbTable&);
-
- void invert();
- void operator~();
- void operator!();
-
- // NOT YET IMPLEMENTED void reduceSelectionToCurrentRecord();
-
- // data access
- void newRecord();
- void saveRecord();
- void deleteRecord();
- void deleteSelection();
- void deleteAll();
-
- void extract(ostream&);
- unsigned long insert(istream&);
-
- // reflective operators
- virtual void describe(ostream&);
-
- virtual void generateTestData(int numRecords, const char* testBuf, unsigned long testBufLen);
-
- private:
- void AddHalfRelation(dbRelRefBase& linkfieldPtr);
- // void SetReferenceHalf(dbRelHalf*);
- void CompleteField(dbField*);
- void ContextChange();
-
- // data storage
- protected:
- OOF_tableBackend *mBackend; // owned (the bit that does all the work!!)
- OOF_Dictionary mFields;
- OOF_String mTableName;
- fieldNumT mFieldCount;
- fieldNumT mSortByFieldNum;
- saveOptions mSaveOption;
-
- private:
- OOF_Dictionary mPartRelations;
- OOF_relChainList* mRelChains; // owned
-
- static dbTable *sCurrentlyConstructing;
- static dbRelHalf * sSavedRelationHalf;
- protected:
- static bool sCloningWithoutSelection;
-
- friend class dbField;
- friend class dbConnect;
- friend class dbRelHalf;
- };
- ostream& operator<<(ostream& os, dbTable& tbl);
- ostream& operator<<(ostream& os, dbTable* tbl);
- istream& operator>>(istream& is, dbTable* tbl);
- istream& operator>>(istream& is, dbTable& tbl);
-
-
- class stPreserveOOFILEcontext {
- public:
- stPreserveOOFILEcontext(dbTable*);
- stPreserveOOFILEcontext(dbTable&);
- ~stPreserveOOFILEcontext();
-
- private:
- OOF_Context* mContext;
- dbTable* mTable;
- };
-
-
- class dbConnect : public dbClass {
- public:
- dbConnect();
- virtual ~dbConnect();
-
- virtual void newConnection(const OOF_String& connectionName)=0;
- virtual void openConnection(const OOF_String& connectionName)=0;
-
-
- void attachTable(dbTable *);
- void attachRelation(dbRelationship *);
- dbTable *table(unsigned int);
- dbTable *table(const char*);
-
- // locking
- virtual void exitLocking()=0;
- virtual void enterWriteLocking()=0;
- virtual void enterReadLocking()=0;
-
- // utilities
- static bool fileExists(const char * fName);
- static bool underConstruction();
- virtual void describe(ostream&);
- void dumpData(ostream&);
- void generateTestData(const char* testFileName, unsigned long maxRecs=0);
- static void raise(ostream&);
- static void raise(const char*);
-
- private:
- virtual OOF_tableBackend *MakeTableBackend(const OOF_Dictionary& tablesfields, const OOF_String& tableName)=0;
-
- // data storage
- protected:
- static dbConnect *sCurrentlyConstructing;
- OOF_Dictionary mTables, mRelations;
- OOF_String mConnectionName;
-
-
- friend dbTable::dbTable(const char*);
- friend class dbRelationship;
- };
-
-
- class dbBLOB;
-
- class OOF_tableBackend {
- // uses lots of public methods but is only ever accessed by a dbTable or dbField subclass
- // so no problems
- protected:
- OOF_tableBackend(const OOF_Dictionary& tablesfields, const OOF_String& tableName):
- mOIDfield(0),
- mFields(tablesfields),
- mTableName(tableName)
- {};
- OOF_tableBackend(const OOF_tableBackend&, const OOF_Dictionary& tablesFields);
-
- public:
- virtual void buildSchema()=0;
- virtual void createTableInConnection(const dbConnect*)=0;
- virtual void openTableInConnection(const dbConnect*)=0;
- void setOIDfield(const dbField &oidfield);
- virtual OOF_tableBackend* clone(bool selectionNotCopied, const OOF_Dictionary&) const=0;
-
- // recordwise access
- virtual void start()=0;
- virtual void next()=0;
- virtual void prev()=0;
- virtual bool more() const=0;
- virtual bool atFirst() const=0;
- virtual bool atLast() const=0;
- virtual unsigned long count() const=0;
- virtual unsigned long countAll() const=0;
- virtual void sortBy(fieldNumT)=0;
-
- // data access
- virtual void newRecord()=0;
- virtual void deleteRecord()=0;
- virtual void saveRecord()=0;
- virtual void unloadRecord()=0;
- virtual bool isRecordLoaded() const=0;
- virtual void *getFieldWriteDest(fieldNumT)=0;
- virtual void *getFieldReadFrom(fieldNumT)=0;
- virtual void setBlobLength(fieldNumT, unsigned long len)=0;
- virtual void loadBlob(dbBLOB*)=0;
- bool isDirty() const;
- void markDirty();
-
- // reflective operators
- virtual unsigned int numIndexes() const=0;
- virtual unsigned int numFiles() const=0;
- virtual unsigned long fieldDataLen(const dbField*) const=0;
- virtual unsigned long blobPointerReferenceSize() const=0;
- virtual long sequenceNumber() const=0;
-
- // public search functions
- virtual bool gotoRecord(unsigned long)=0;
- virtual bool gotoRelativeRecord(unsigned long relativeNum)=0;
- virtual bool searchEqual(const dbField*, const char*, bool matchEntireKey=true)=0;
- virtual bool searchEqual(const dbField*, const void*)=0;
- virtual void selectAll()=0;
- virtual void selectNone()=0;
- virtual bool search(const dbQueryClause*)=0;
- virtual bool searchSelection(const dbQueryClause*)=0;
- virtual void difference_with(const OOF_tableBackend*)=0;
- virtual void intersection_with(const OOF_tableBackend*)=0;
- virtual void invert()=0;
- virtual void union_with(const OOF_tableBackend*)=0;
- virtual bool loadRelatedContextJoiningFromTo(const dbField*, const dbField*)=0;
-
- // current record context management
- virtual bool contextChangedFrom(const OOF_Context*) const=0;
- virtual void updateContext(OOF_Context*) const=0;
- virtual OOF_Context* createContext() const=0;
- virtual unsigned long recordNumber() const=0;
- virtual void returnToContext(OOF_Context*)=0;
-
- protected:
- virtual void CacheDirtyBuffer()=0;
-
- // data storage
- dbField *mOIDfield;
- OOF_Dictionary mFields; // copy of dbTable handle object, one representation
- OOF_String mTableName; // copy of dbtable object
- bool mDirty;
-
- friend class dbTable;
- };
-
-
- class OOF_mixRelChainEndPoint {
- public:
- OOF_mixRelChainEndPoint() : mRelationChain(0) {};
- virtual ~OOF_mixRelChainEndPoint();
-
- static void appendRelationLink(dbRelHalf*);
- static bool hasTransitoryLinks();
-
- protected:
- bool ConsumePossibleRelationChain();
- // data storage
- dbRelChain* mRelationChain; // owned
-
- static dbRelChain* sTransitoryRelChainLinks;
- };
-
-
- // define macros for table construction
- #define REF_TABLE(tb) \
- class tb; \
- class tb ## Ref : public dbRelRef \
- { public: tb* operator->() { LogTransition(); return (tb*) RefersToTable();}; };
-
-
- #define SET_TABLE(tb) \
- class tb; \
- class tb ## Set : public dbRelSet \
- { public: tb* operator->() { LogTransition(); return (tb*) RefersToTable();}; };
-
-
- #define CLASS_TABLE(tb) \
- class tb : public dbTable { \
- public: \
- tb& operator[](const dbQueryClause& rhs) { search(rhs); return *this; }; \
- tb& operator[](unsigned long index) { gotoRelativeRecord(index); return *this;}; \
- tb& operator[](const char *name) { searchDefaultIndex(name); return *this;}; \
- tb& operator[](long index) { assert(index>=0); gotoRelativeRecord(index); return *this;}; \
- virtual dbTable* cloneWithoutSelection() { sCloningWithoutSelection = true; return new tb(*this); }; \
- tb& operator-(const tb& rhs) { dbTable::difference_with(rhs); return *this; }; \
- tb& difference_with(const tb& rhs) { dbTable::difference_with(rhs); return *this; }; \
- tb& operator&(const tb& rhs) { dbTable::intersection_with(rhs); return *this; }; \
- tb& intersection_with(const tb& rhs) { dbTable::intersection_with(rhs); return *this; }; \
- tb& operator|(const tb& rhs) { dbTable::union_with(rhs); return *this; }; \
- tb& operator+(const tb& rhs) { dbTable::union_with(rhs); return *this; }; \
- tb& union_with(const tb& rhs) { dbTable::union_with(rhs); return *this; }; \
- friend ostream& operator<<(ostream& os, tb& tbl) {tbl.extract(os); return os;}; \
- friend ostream& operator<<(ostream& os, tb* tbl) {tbl->extract(os); return os;}; \
- friend istream& operator>>(istream& is, tb& tbl) {tbl.insert(is); return is;}; \
- friend istream& operator>>(istream& is, tb* tbl) {tbl->insert(is); return is;};
-
- //tb* operator&() { assert(0); return this;}; \
- //tb* invert(const dbTablePtr& rhs) { AddHalfRelation((dbTable**) &rhs); return this; }; \
-
-
- // include inline definitions
- #include "oof1.inl"
- #endif
-
-
-