Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/register.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * register.h | |
7 */ | |
8 | |
9 #ifndef REGISTER_H | |
10 #define REGISTER_H | |
11 | |
12 #include "agbaltree.h" | |
13 #include "agstack.h" | |
14 #include "assert.h" | |
15 | |
16 | |
17 template <class Descriptor> | |
18 class ObjectRegister { | |
19 private: | |
20 //Don't want this to happen | |
21 void *operator new(size_t sz) { | |
22 assert(0); | |
23 #ifdef __GNUC__ | |
24 return ::new char[sz]; | |
25 #else | |
26 return 0; | |
27 #endif | |
28 } | |
29 | |
30 protected: | |
31 int index; | |
32 Descriptor *descriptor; | |
33 static AgStack<Descriptor> descriptorList; | |
34 ObjectRegister(const Descriptor &d); | |
35 ObjectRegister(const ObjectRegister<Descriptor> &d); | |
36 | |
37 public: | |
38 // Constructors | |
39 //ObjectRegister() : index(0), descriptor(0) {} | |
40 ObjectRegister(); | |
41 ObjectRegister(int x); | |
42 ObjectRegister<Descriptor> &operator = (const ObjectRegister<Descriptor> &d); | |
43 ObjectRegister<Descriptor> &operator = (int x); | |
44 // Destructor | |
45 ~ObjectRegister() {} | |
46 | |
47 // Register management functions | |
48 static void reset(); | |
49 int next(); | |
50 inline int isNull() { return index == 0; } | |
51 inline int isNotNull() { return index != 0; } | |
52 static unsigned count(); | |
53 | |
54 // Object operators | |
55 Descriptor *operator -> () const { return descriptor; } | |
56 operator Descriptor & () const { return *descriptor; } | |
57 operator int() const { return index; } | |
58 | |
59 int operator == (const ObjectRegister<Descriptor> &d) const { | |
60 return index == d.index; | |
61 } | |
62 int operator != (const ObjectRegister<Descriptor> &d) const { | |
63 return index != d.index; | |
64 } | |
65 int operator < (const ObjectRegister<Descriptor> &d) const { | |
66 return index < d.index; | |
67 } | |
68 int operator > (const ObjectRegister<Descriptor> &d) const { | |
69 return index > d.index; | |
70 } | |
71 int operator <= (const ObjectRegister<Descriptor> &d) const { | |
72 return index <= d.index; | |
73 } | |
74 int operator >= (const ObjectRegister<Descriptor> &d) const { | |
75 return index >= d.index; | |
76 } | |
77 }; | |
78 | |
79 template <class Descriptor> | |
80 class KeyedObjectRegister : public ObjectRegister<Descriptor> { | |
81 protected: | |
82 static const Descriptor *testObject; | |
83 | |
84 KeyedObjectRegister(); | |
85 | |
86 public: | |
87 class Tree; | |
88 friend class Tree; | |
89 class Tree : public AgBalancedTree<int> { | |
90 int compare(const int &x, const int &y) const; | |
91 }; | |
92 | |
93 static Tree tree; | |
94 | |
95 KeyedObjectRegister(const Descriptor &d); | |
96 KeyedObjectRegister(unsigned x); | |
97 static void reset(); | |
98 }; | |
99 | |
100 template <class Register> | |
101 class Each : public Register { | |
102 public: | |
103 //Each(int x = Register::first) { | |
104 // index = x; | |
105 // descriptor = (unsigned) index < descriptorList.size() ? | |
106 // &descriptorList[index] : 0; | |
107 //} | |
108 | |
109 //void restart(int x = Register::first) { | |
110 // index = x; | |
111 // descriptor = (unsigned) index < descriptorList.size() ? | |
112 // &descriptorList[index] : 0; | |
113 //} | |
114 | |
115 int loopNotFinished() { | |
116 return (unsigned) Each<Register>::index | |
117 < | |
118 Each<Register>::descriptorList.size(); | |
119 } | |
120 | |
121 //void getNext() { | |
122 // index++; | |
123 // descriptor = (unsigned) index < descriptorList.size() ? | |
124 // &descriptorList[index] : 0; | |
125 //} | |
126 | |
127 Each(int x = Register::first); | |
128 void restart(int x = Register::first); | |
129 void getNext(); | |
130 }; | |
131 | |
132 | |
133 #endif /* REGISTER_H */ |