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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
*
* Copyright (c) 1998-9
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* FILE re_lst.h
* VERSION 2.12
* This is an internal header file, do not include directly.
* re_list support class, for regular
* expression library.
*/
#ifndef RE_LST_H
#define RE_LST_H
#ifndef JM_CFG_H
#include <jm/jm_cfg.h>
#endif
#include <new.h>
JM_NAMESPACE(__JM)
template <class T, class Allocator>
class re_list
{
public:
struct node
{
node* next;
T t;
node(const T& o) : t(o) {}
};
public:
class iterator
{
node* pos;
public:
iterator() { pos = 0; }
~iterator() {}
iterator(const iterator& i) { pos = i.pos; }
iterator(node* n) { pos = n; }
iterator& operator=(const iterator& i)
{
pos = i.pos;
return *this;
}
bool operator==(iterator& i)
{
return pos == i.pos;
}
bool operator!=(iterator& i)
{
return pos != i.pos;
}
T& operator*() { return pos->t; }
iterator& operator++()
{
pos = pos->next;
return *this;
}
iterator operator++(int)
{
iterator t(*this);
pos = pos->next;
return t;
}
const node* tell()const
{
return pos;
}
};
class const_iterator
{
const node* pos;
public:
const_iterator() { pos = 0; }
~const_iterator() {}
const_iterator(const const_iterator& i) { pos = i.pos; }
const_iterator(const iterator& i) { pos = i.tell(); }
const_iterator(const node* n) { pos = n; }
const_iterator& operator=(const iterator& i)
{
pos = i.tell();
return *this;
}
const_iterator& operator=(const const_iterator& i)
{
pos = i.pos;
return *this;
}
bool operator==(const_iterator& i)
{
return pos == i.pos;
}
bool operator!=(const_iterator& i)
{
return pos != i.pos;
}
const T& operator*() { return pos->t; }
const_iterator& operator++()
{
pos = pos->next;
return *this;
}
const_iterator operator++(int)
{
const_iterator t(*this);
pos = pos->next;
return t;
}
};
private:
typedef JM_MAYBE_TYPENAME REBIND_TYPE(node, Allocator) node_alloc;
struct data : public node_alloc
{
node* first;
data(const Allocator& a) : node_alloc(a), first(0) {}
};
data alloc_inst;
public:
re_list(const Allocator& a = Allocator()) : alloc_inst(a) {}
~re_list() { clear(); }
iterator RE_CALL begin() { return iterator(alloc_inst.first); }
iterator RE_CALL end() { return iterator(0); }
const_iterator RE_CALL begin()const { return const_iterator(alloc_inst.first); }
const_iterator RE_CALL end()const { return const_iterator(0); }
void RE_CALL add(const T& t)
{
node* temp;
temp = alloc_inst.allocate(1);
#ifndef JM_NO_EXCEPTIONS
try{
#endif
alloc_inst.construct(temp, t);
#ifndef JM_NO_EXCEPTIONS
}catch(...){ alloc_inst.deallocate(temp, 1); throw; }
#endif
temp->next = alloc_inst.first;
alloc_inst.first = temp;
}
void RE_CALL clear();
};
template <class T, class Allocator>
void RE_CALL re_list<T, Allocator>::clear()
{
node* temp;
while(alloc_inst.first)
{
temp = alloc_inst.first;
alloc_inst.first = alloc_inst.first->next;
alloc_inst.destroy(temp);
alloc_inst.deallocate(temp, 1);
}
}
JM_END_NAMESPACE
#endif
|