OFFIS DCMTK
Version 3.6.0
Main Page
Related Pages
Classes
Files
File List
File Members
ofstd
include
dcmtk
ofstd
ofstack.h
1
/*
2
*
3
* Copyright (C) 1997-2010, OFFIS e.V.
4
* All rights reserved. See COPYRIGHT file for details.
5
*
6
* This software and supporting documentation were developed by
7
*
8
* OFFIS e.V.
9
* R&D Division Health
10
* Escherweg 2
11
* D-26121 Oldenburg, Germany
12
*
13
*
14
* Module: ofstd
15
*
16
* Author: Andreas Barth
17
*
18
* Purpose:
19
* Defines a template stack class with interfaces similar to the C++ Standard
20
*
21
* Last Update: $Author: joergr $
22
* Update Date: $Date: 2010-10-14 13:15:50 $
23
* CVS/RCS Revision: $Revision: 1.18 $
24
* Status: $State: Exp $
25
*
26
* CVS/RCS Log at end of file
27
*
28
*/
29
30
31
#ifndef OFSTACK_H
32
#define OFSTACK_H
33
34
#include "dcmtk/config/osconfig.h"
/* make sure OS specific configuration is included first */
35
#include "dcmtk/ofstd/oftypes.h"
36
#include "dcmtk/ofstd/ofcast.h"
37
38
#if defined(HAVE_STL) || defined(HAVE_STL_STACK)
39
// It is possible to use the standard template library list class since the
40
// interface is nearly identical.
41
// Important: If you want to use the standard template library, no variable
42
// in a namespace with using a list shall have the name stack
43
#include <stack>
44
#define OFStack std::stack
45
#else
46
47
#define INCLUDE_CASSERT
48
#define INCLUDE_CSTDDEF
49
#include "dcmtk/ofstd/ofstdinc.h"
50
51
#ifndef HAVE_CLASS_TEMPLATE
52
#error Your C++ compiler cannot handle class templates:
53
#endif
54
55
59
struct
OFStackLinkBase
60
{
62
OFStackLinkBase
*
next
;
63
65
OFStackLinkBase
()
66
:
next
(NULL)
67
{
68
}
69
71
virtual
~OFStackLinkBase
()
72
{
73
}
74
private
:
75
77
OFStackLinkBase
(
const
OFStackLinkBase
&);
78
80
OFStackLinkBase
&
operator=
(
const
OFStackLinkBase
&);
81
};
82
86
class
OFStackBase
87
{
88
public
:
90
OFStackBase
()
91
:
head
(NULL),
92
stackSize
(0)
93
{
94
}
95
97
virtual
~OFStackBase
()
98
{
99
while
(!
base_empty
())
100
base_pop
();
101
}
102
106
OFBool
base_empty
()
const
{
return
head
== NULL; }
107
111
size_t
base_size
()
const
{
return
stackSize
; }
112
116
OFStackLinkBase
*
base_top
()
117
{
118
assert(
head
!=NULL);
119
return
head
;
120
}
121
125
void
base_push
(
OFStackLinkBase
* element)
126
{
127
element->
next
=
head
;
128
head
= element;
129
stackSize
++;
130
}
131
135
void
base_pop
()
136
{
137
assert(
head
!=NULL);
138
OFStackLinkBase
* delObj =
head
;
139
head
=
head
->
next
;
140
delete
delObj;
141
stackSize
--;
142
}
143
144
protected
:
145
147
OFStackLinkBase
*
head
;
148
150
size_t
stackSize
;
151
152
private
:
153
155
OFStackBase
(
const
OFStackBase
&);
156
158
OFStackBase
&
operator=
(
const
OFStackBase
&);
159
160
};
161
165
template
<
class
T>
166
struct
OFStackLink
:
public
OFStackLinkBase
167
{
169
T
info
;
170
174
OFStackLink
(
const
T & i) :
OFStackLinkBase
(),
info
(i) { }
175
177
virtual
~OFStackLink
()
178
{
179
}
180
181
private
:
182
184
OFStackLink
(
const
OFStackLink<T>
&);
185
187
OFStackLink<T>
&
operator=
(
const
OFStackLink<T>
&);
188
};
189
190
191
195
template
<
class
T>
196
class
OFStack
:
private
OFStackBase
197
{
198
199
public
:
200
202
OFStack
() {};
203
205
OFStack
(
const
OFStack<T>
& x) :
OFStackBase
()
206
{
207
copy
(x);
208
}
209
211
OFStack<T>
&
operator=
(
const
OFStack<T>
&x)
212
{
213
copy
(x);
214
return
*
this
;
215
}
216
220
OFBool
empty
()
const
{
return
OFStackBase::base_empty
(); }
221
225
size_t
size
()
const
{
return
OFStackBase::base_size
(); }
226
231
T &
top
()
232
{
233
return
(OFstatic_cast(
OFStackLink<T>
*,
OFStackBase::base_top
()))->info;
234
}
235
240
void
push
(
const
T & x)
241
{
242
OFStackBase::base_push
(
new
OFStackLink<T>
(x));
243
}
244
248
void
pop
() {
OFStackBase::base_pop
(); }
249
250
private
:
251
256
int
copy
(
const
OFStack<T>
& x)
257
{
258
stackSize
= x.
size
();
259
if
(
stackSize
)
260
{
261
head
=
new
OFStackLink<T>
((OFstatic_cast(
OFStackLink<T>
*, x.
head
))->info);
262
OFStackLinkBase
* newPtr =
head
;
263
OFStackLinkBase
* oldPtr = x.
head
->
next
;
264
while
(oldPtr)
265
{
266
newPtr->
next
=
267
new
OFStackLink<T>
((OFstatic_cast(
OFStackLink<T>
*, oldPtr))->info);
268
oldPtr = oldPtr->
next
;
269
newPtr = newPtr->
next
;
270
}
271
}
272
return
0;
273
}
274
275
};
276
277
#endif
278
#endif
279
280
/*
281
** CVS/RCS Log:
282
** $Log: ofstack.h,v $
283
** Revision 1.18 2010-10-14 13:15:50 joergr
284
** Updated copyright header. Added reference to COPYRIGHT file.
285
**
286
** Revision 1.17 2005/12/08 16:06:03 meichel
287
** Changed include path schema for all DCMTK header files
288
**
289
** Revision 1.16 2003/08/14 14:41:39 meichel
290
** OFStack now explicitly defined as std::stack if compiling with HAVE_STL
291
**
292
** Revision 1.15 2003/07/09 13:57:43 meichel
293
** Adapted type casts to new-style typecast operators defined in ofcast.h
294
**
295
** Revision 1.14 2002/11/27 11:23:06 meichel
296
** Adapted module ofstd to use of new header file ofstdinc.h
297
**
298
** Revision 1.13 2002/07/10 11:50:40 meichel
299
** Added vitual destructor to class OFStackLink
300
**
301
** Revision 1.12 2001/12/03 15:09:09 meichel
302
** Completed doc++ documentation
303
**
304
** Revision 1.11 2001/07/03 14:35:01 meichel
305
** Fixed memory leak in ofstack.h
306
**
307
** Revision 1.10 2001/06/01 15:51:35 meichel
308
** Updated copyright header
309
**
310
** Revision 1.9 2000/10/12 08:11:35 joergr
311
** Added assignment operator to class OFStack.
312
** Declared (unimplemented) copy constructor and assignment operator in class
313
** OFStackLink to avoid compiler warnings (e.g. on Sun CC 2.0.1).
314
**
315
** Revision 1.8 2000/10/10 12:01:21 meichel
316
** Created/updated doc++ comments
317
**
318
** Revision 1.7 2000/03/08 16:36:02 meichel
319
** Updated copyright header.
320
**
321
** Revision 1.6 1998/11/27 12:42:52 joergr
322
** Added copyright message to source files and changed CVS header.
323
**
324
** Revision 1.5 1998/07/02 10:11:31 joergr
325
** Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
326
** options), e.g. add copy constructors.
327
**
328
** Revision 1.4 1998/02/06 15:07:40 meichel
329
** Removed many minor problems (name clashes, unreached code)
330
** reported by Sun CC4 with "+w" or Sun CC2.
331
**
332
** Revision 1.3 1997/09/11 15:43:16 hewett
333
** Minor changes to eliminate warnings when compiled under the
334
** Signus GnuWin32 envionment. Changed order of initialisers
335
** for OFListLink and OFStackLink. Make ~OFLisBase and ~OFStackBase
336
** virtual destructors.
337
**
338
** Revision 1.2 1997/07/21 09:02:24 andreas
339
** - New copy constructor for class OFStack
340
**
341
** Revision 1.1 1997/07/02 11:51:15 andreas
342
** - Preliminary release of the OFFIS Standard Library.
343
** In the future this library shall contain a subset of the
344
** ANSI C++ Library (Version 3) that works on a lot of different
345
** compilers. Additionally this library shall include classes and
346
** functions that are often used. All classes and functions begin
347
** with OF... This library is independent of the DICOM development and
348
** shall contain no DICOM specific stuff.
349
**
350
**
351
*/
Generated on Thu Dec 20 2012 for
OFFIS DCMTK
Version 3.6.0 by
Doxygen
1.8.2