/* * CENA C++ Utilities * * by Stephane Chatty * * Copyright 1990, 1991, 1992, 1993, 1994 * Laboratoire de Recherche en Informatique (LRI) * Centre d'Etudes de la Navigation Aerienne (CENA) * * tables for managing an ID scheme, originally by Michel Beaudouin-Lafon * * $Id$ * $CurLog$ */ #ifndef IdTable_H_ #define IdTable_H_ #include "cplus_bugs.h" #include "word.h" #include "bool.h" typedef void IvlIdItem; typedef lword IvlID; typedef sword IvlIdType; typedef sword IvlIdIndex; class IvlIdTable { friend class IvlIdIter; friend class IvlIdCell; protected: IvlIdCell* Entries; // the table itself IvlIdCell* LastCell; // its end IvlIdIndex FirstFree; // index of first free entry IvlIdIndex LastFree; // index of end of free list short NumFree; // number of free Entries bool Grow (int); public: IvlIdTable (int); // initial size should be power of 2 IvlID Store (IvlIdItem*, IvlIdType = 0); IvlIdItem* Get (IvlID, IvlIdType* = 0); IvlIdItem* Remove (IvlID, bool* = 0, IvlIdType* = 0); void Change (IvlID, IvlIdItem*, IvlIdType = 0); }; class IvlIdIter { public: enum iditer_status { Normal, StartOfTable, EndOfTable }; protected: const IvlIdTable* TheTable; iditer_status StatusFlag; IvlIdCell* Entries; IvlIdCell* CurCell; public: inline IvlIdIter (const IvlIdTable& t) : TheTable (&t), StatusFlag (StartOfTable) { CurCell = Entries = t.Entries; } inline void Reset () { CurCell = Entries = TheTable->Entries; StatusFlag = StartOfTable; } inline IvlIdIter& operator = (const IvlIdTable& t) { TheTable = &t; StatusFlag = StartOfTable; CurCell = Entries = t.Entries; return *this; } inline IvlIdIter& operator = (const IvlIdIter& it) { TheTable = it.TheTable; StatusFlag = it.StatusFlag; CurCell = it.CurCell; Entries = it.Entries; return *this; } IvlIdIter& operator ++ (); IvlIdItem* Current () const; inline IvlIdItem* operator * () const { return Current (); } inline operator int () const { return StatusFlag == Normal; } IvlIdType CurType () const; IvlID CurId () const; }; template class IvlIdTableOf : public IvlIdTable { public: inline IvlIdTableOf (int sz) : IvlIdTable (sz) {} inline IvlID Store (ITEM* it, IvlIdType typ = 0) { return IvlIdTable::Store (it, typ); } inline ITEM* Get (IvlID id, IvlIdType* typ = 0) { return (ITEM*) IvlIdTable::Get (id, typ); } inline ITEM* Remove (IvlID id, bool* f = 0, IvlIdType* t = 0) { return (ITEM*) IvlIdTable::Remove (id, f, t); } inline void Change (IvlID id, ITEM* i, IvlIdType t = 0) { IvlIdTable::Change (id, i, t); } }; template class IvlIdIterOf : public IvlIdIter { public: inline IvlIdIterOf (IvlIdTableOf & t) : IvlIdIter (t) { } inline IvlIdIterOf& operator = (const IvlIdTableOf & t) { return (IvlIdIterOf&) IvlIdIter::operator = (t); } inline IvlIdIterOf& operator = (const IvlIdIterOf& li) { return (IvlIdIterOf&) IvlIdIter::operator = (li); } inline IvlIdIterOf& operator ++ () { return (IvlIdIterOf&) IvlIdIter::operator ++ (); } inline ITEM* Current () const { return (ITEM*) IvlIdIter::Current (); } inline ITEM* operator * () const { return Current (); } }; #endif /* IdTable_H_ */