From fa5d3f424a09155e714394eb9b501c81373e0973 Mon Sep 17 00:00:00 2001 From: chatty Date: Wed, 22 Dec 1993 12:25:31 +0000 Subject: serious reorganization --- utils/IdTable.h | 90 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/utils/IdTable.h b/utils/IdTable.h index 0b64219..ad95411 100644 --- a/utils/IdTable.h +++ b/utils/IdTable.h @@ -3,7 +3,7 @@ * * by Stephane Chatty * - * Copyright 1990, 1991, 1992 + * Copyright 1990, 1991, 1992, 1993 * Laboratoire de Recherche en Informatique (LRI) * Centre d'Etudes de la Navigation Aerienne (CENA) * @@ -19,61 +19,79 @@ #include "word.h" #include "bool.h" -/* - * TID_MASK = 2^TID_SHIFT = max table size - * TID_MASK = TID_SHIFT bits set to 1. - */ -#define TID_MAX (2 << 16) -#define TID_SHIFT 16 -#define TID_MASK 0xffff - -struct CcuIdCell { - sword chk; // the check number - sword typ; // for the appli, for free list when not allocated - const void* obj; // the object -}; +typedef void CcuIdItem; +typedef lword CcuID; +typedef sword CcuIdType; +typedef sword CcuIdIndex; class CcuIdTable { friend class CcuIdIter; +friend class CcuIdCell; protected: - CcuIdCell* entries; // the table itself - CcuIdCell* last; // its end - sword free; // index of first free entry - sword last_free; // index of end of free list - sword num_free; // number of free entries + CcuIdCell* Entries; // the table itself + CcuIdCell* LastCell; // its end + CcuIdIndex FirstFree; // index of first free entry + CcuIdIndex LastFree; // index of end of free list + short NumFree; // number of free Entries bool Grow (int); public: - CcuIdTable (int = 4); // initial size should be power of 2 *** 4 for testing + CcuIdTable (int); // initial size should be power of 2 - lword Store (const void*, sword = 0); - bool Remove (lword); - const void* Get (lword, sword* = 0); - void Change (lword, const void*, sword = 0); + CcuID Store (CcuIdItem*, CcuIdType = 0); + CcuIdItem* Get (CcuID, CcuIdType* = 0); + CcuIdItem* Remove (CcuID, bool* = 0, CcuIdType* = 0); + void Change (CcuID, CcuIdItem*, CcuIdType = 0); }; class CcuIdIter { +public: + enum iditer_status { Normal, StartOfTable, EndOfTable }; + protected: - CcuIdTable* idt; - CcuIdCell* entries; - CcuIdCell* cur; + const CcuIdTable* TheTable; + iditer_status StatusFlag; + CcuIdCell* Entries; + CcuIdCell* CurCell; - void Step (); - public: - CcuIdIter (CcuIdTable& t) { idt = &t; cur = entries = t.entries; Step (); } +inline CcuIdIter (const CcuIdTable& t) : TheTable (&t), StatusFlag (StartOfTable) { CurCell = Entries = t.Entries; } +inline void Reset () { CurCell = Entries = TheTable->Entries; StatusFlag = StartOfTable; } +inline CcuIdIter& operator = (const CcuIdTable& t) { TheTable = &t; StatusFlag = StartOfTable; CurCell = Entries = t.Entries; return *this; } +inline CcuIdIter& operator = (const CcuIdIter& it) { TheTable = it.TheTable; StatusFlag = it.StatusFlag; CurCell = it.CurCell; Entries = it.Entries; return *this; } + + CcuIdIter& operator ++ (); + CcuIdItem* Current () const; +inline CcuIdItem* operator * () const { return Current (); } +inline operator int () const { return StatusFlag == Normal; } + CcuIdType CurType () const; + CcuID CurId () const; - const void* operator () () { Step (); return cur ? cur->obj : 0; } - const void* operator ++ () { Step (); return cur ? cur++->obj : 0; } - const void* Current () { return cur ? cur->obj : 0; } - sword CurType () { return cur ? cur->typ : 0; } - lword CurId () { return cur ? (cur -> chk << TID_SHIFT) | (cur - entries) : 0; } +}; +template class CcuIdTableOf : public CcuIdTable { +public: +inline CcuIdTableOf (int sz) : CcuIdTable (sz) {} - void Reset () { cur = entries = idt->entries; } +inline CcuID Store (ITEM* it, CcuIdType typ = 0) { return CcuIdTable::Store (it, typ); } +inline ITEM* Get (CcuID id, CcuIdType* typ = 0) { return (ITEM*) CcuIdTable::Get (id, typ); } +inline ITEM* Remove (CcuID id, bool* f = 0, CcuIdType* t = 0) { return (ITEM*) CcuIdTable::Remove (id, f, t); } +inline void Change (CcuID id, ITEM* i, CcuIdType t = 0) { CcuIdTable::Change (id, i, t); } }; +template class CcuIdIterOf : public CcuIdIter { +public: +inline CcuIdIterOf (CcuIdTableOf & t) : CcuIdIter (t) { } +inline CcuIdIterOf& operator = (const CcuIdTableOf & t) { return (CcuIdIterOf&) CcuIdIter::operator = (t); } +inline CcuIdIterOf& operator = (const CcuIdIterOf& li) { return (CcuIdIterOf&) CcuIdIter::operator = (li); } +inline CcuIdIterOf& operator ++ () { return (CcuIdIterOf&) CcuIdIter::operator ++ (); } +inline ITEM* Current () const { return (ITEM*) CcuIdIter::Current (); } +inline ITEM* operator * () const { return Current (); } +}; + + + #endif /* IdTable_H_ */ -- cgit v1.1