1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* CENA C++ Utilities
*
* by Stephane Chatty
*
* Copyright 1990, 1991, 1992, 1993
* 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 "word.h"
#include "bool.h"
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* 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); // initial size should be power of 2
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:
const CcuIdTable* TheTable;
iditer_status StatusFlag;
CcuIdCell* Entries;
CcuIdCell* CurCell;
public:
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;
};
template <class ITEM> class CcuIdTableOf : public CcuIdTable {
public:
inline CcuIdTableOf (int sz) : CcuIdTable (sz) {}
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 ITEM> class CcuIdIterOf : public CcuIdIter {
public:
inline CcuIdIterOf (CcuIdTableOf <ITEM> & t) : CcuIdIter (t) { }
inline CcuIdIterOf<ITEM>& operator = (const CcuIdTableOf <ITEM>& t) { return (CcuIdIterOf<ITEM>&) CcuIdIter::operator = (t); }
inline CcuIdIterOf<ITEM>& operator = (const CcuIdIterOf<ITEM>& li) { return (CcuIdIterOf<ITEM>&) CcuIdIter::operator = (li); }
inline CcuIdIterOf<ITEM>& operator ++ () { return (CcuIdIterOf<ITEM>&) CcuIdIter::operator ++ (); }
inline ITEM* Current () const { return (ITEM*) CcuIdIter::Current (); }
inline ITEM* operator * () const { return Current (); }
};
#endif /* IdTable_H_ */
|