00001 /* 00002 * 00003 * Copyright (C) 1997-2005, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: ofstd 00019 * 00020 * Author: Andreas Barth 00021 * 00022 * Purpose: 00023 * Defines a template stack class with interfaces similar to the C++ Standard 00024 * 00025 * Last Update: $Author: meichel $ 00026 * Update Date: $Date: 2005/12/08 16:06:03 $ 00027 * Source File: $Source: /share/dicom/cvs-depot/dcmtk/ofstd/include/dcmtk/ofstd/ofstack.h,v $ 00028 * CVS/RCS Revision: $Revision: 1.17 $ 00029 * Status: $State: Exp $ 00030 * 00031 * CVS/RCS Log at end of file 00032 * 00033 */ 00034 00035 00036 #ifndef OFSTACK_H 00037 #define OFSTACK_H 00038 00039 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00040 #include "dcmtk/ofstd/oftypes.h" 00041 #include "dcmtk/ofstd/ofcast.h" 00042 00043 #if defined(HAVE_STL) || defined(HAVE_STL_STACK) 00044 // It is possible to use the standard template library list class since the 00045 // interface is nearly identical. 00046 // Important: If you want to use the standard template library, no variable 00047 // in a namespace with using a list shall have the name stack 00048 #include <stack> 00049 #define OFStack std::stack 00050 #else 00051 00052 #define INCLUDE_CASSERT 00053 #define INCLUDE_CSTDDEF 00054 #include "dcmtk/ofstd/ofstdinc.h" 00055 00056 #ifndef HAVE_CLASS_TEMPLATE 00057 #error Your C++ compiler cannot handle class templates: 00058 #endif 00059 00060 00064 struct OFStackLinkBase 00065 { 00067 OFStackLinkBase * next; 00068 00070 OFStackLinkBase() 00071 : next(NULL) 00072 { 00073 } 00074 00076 virtual ~OFStackLinkBase() 00077 { 00078 } 00079 private: 00080 00082 OFStackLinkBase(const OFStackLinkBase &); 00083 00085 OFStackLinkBase &operator=(const OFStackLinkBase &); 00086 }; 00087 00091 class OFStackBase 00092 { 00093 public: 00095 OFStackBase() 00096 : head(NULL), 00097 stackSize(0) 00098 { 00099 } 00100 00102 virtual ~OFStackBase() 00103 { 00104 while(!base_empty()) 00105 base_pop(); 00106 } 00107 00111 OFBool base_empty() const { return head == NULL; } 00112 00116 size_t base_size() const { return stackSize; } 00117 00121 OFStackLinkBase * base_top() 00122 { 00123 assert(head!=NULL); 00124 return head; 00125 } 00126 00130 void base_push(OFStackLinkBase * element) 00131 { 00132 element->next = head; 00133 head = element; 00134 stackSize++; 00135 } 00136 00140 void base_pop() 00141 { 00142 assert(head!=NULL); 00143 OFStackLinkBase * delObj = head; 00144 head = head->next; 00145 delete delObj; 00146 stackSize--; 00147 } 00148 00149 protected: 00150 00152 OFStackLinkBase * head; 00153 00155 size_t stackSize; 00156 00157 private: 00158 00160 OFStackBase(const OFStackBase &); 00161 00163 OFStackBase &operator=(const OFStackBase &); 00164 00165 }; 00166 00170 template <class T> 00171 struct OFStackLink : public OFStackLinkBase 00172 { 00174 T info; 00175 00179 OFStackLink(const T & i) : OFStackLinkBase(), info(i) { } 00180 00182 virtual ~OFStackLink() 00183 { 00184 } 00185 00186 private: 00187 00189 OFStackLink(const OFStackLink<T> &); 00190 00192 OFStackLink<T> &operator=(const OFStackLink<T> &); 00193 }; 00194 00195 00196 00200 template <class T> 00201 class OFStack : private OFStackBase 00202 { 00203 00204 public: 00205 00207 OFStack() {}; 00208 00210 OFStack(const OFStack<T> & x) : OFStackBase() 00211 { 00212 copy(x); 00213 } 00214 00216 OFStack<T> &operator=(const OFStack<T> &x) 00217 { 00218 copy(x); 00219 return *this; 00220 } 00221 00225 OFBool empty() const { return OFStackBase::base_empty(); } 00226 00230 size_t size() const { return OFStackBase::base_size(); } 00231 00236 T & top() 00237 { 00238 return (OFstatic_cast(OFStackLink<T> *, OFStackBase::base_top()))->info; 00239 } 00240 00245 void push(const T & x) 00246 { 00247 OFStackBase::base_push(new OFStackLink<T>(x)); 00248 } 00249 00253 void pop() { OFStackBase::base_pop(); } 00254 00255 private: 00256 00261 int copy(const OFStack<T> & x) 00262 { 00263 stackSize = x.size(); 00264 if (stackSize) 00265 { 00266 head = new OFStackLink<T>((OFstatic_cast(OFStackLink<T>*, x.head))->info); 00267 OFStackLinkBase * newPtr = head; 00268 OFStackLinkBase * oldPtr = x.head->next; 00269 while (oldPtr) 00270 { 00271 newPtr->next = 00272 new OFStackLink<T>((OFstatic_cast(OFStackLink<T>*, oldPtr))->info); 00273 oldPtr = oldPtr->next; 00274 newPtr = newPtr->next; 00275 } 00276 } 00277 return 0; 00278 } 00279 00280 }; 00281 00282 #endif 00283 #endif 00284 00285 /* 00286 ** CVS/RCS Log: 00287 ** $Log: ofstack.h,v $ 00288 ** Revision 1.17 2005/12/08 16:06:03 meichel 00289 ** Changed include path schema for all DCMTK header files 00290 ** 00291 ** Revision 1.16 2003/08/14 14:41:39 meichel 00292 ** OFStack now explicitly defined as std::stack if compiling with HAVE_STL 00293 ** 00294 ** Revision 1.15 2003/07/09 13:57:43 meichel 00295 ** Adapted type casts to new-style typecast operators defined in ofcast.h 00296 ** 00297 ** Revision 1.14 2002/11/27 11:23:06 meichel 00298 ** Adapted module ofstd to use of new header file ofstdinc.h 00299 ** 00300 ** Revision 1.13 2002/07/10 11:50:40 meichel 00301 ** Added vitual destructor to class OFStackLink 00302 ** 00303 ** Revision 1.12 2001/12/03 15:09:09 meichel 00304 ** Completed doc++ documentation 00305 ** 00306 ** Revision 1.11 2001/07/03 14:35:01 meichel 00307 ** Fixed memory leak in ofstack.h 00308 ** 00309 ** Revision 1.10 2001/06/01 15:51:35 meichel 00310 ** Updated copyright header 00311 ** 00312 ** Revision 1.9 2000/10/12 08:11:35 joergr 00313 ** Added assignment operator to class OFStack. 00314 ** Declared (unimplemented) copy constructor and assignment operator in class 00315 ** OFStackLink to avoid compiler warnings (e.g. on Sun CC 2.0.1). 00316 ** 00317 ** Revision 1.8 2000/10/10 12:01:21 meichel 00318 ** Created/updated doc++ comments 00319 ** 00320 ** Revision 1.7 2000/03/08 16:36:02 meichel 00321 ** Updated copyright header. 00322 ** 00323 ** Revision 1.6 1998/11/27 12:42:52 joergr 00324 ** Added copyright message to source files and changed CVS header. 00325 ** 00326 ** Revision 1.5 1998/07/02 10:11:31 joergr 00327 ** Minor changes to avoid compiler warnings (gcc 2.8.1 with additional 00328 ** options), e.g. add copy constructors. 00329 ** 00330 ** Revision 1.4 1998/02/06 15:07:40 meichel 00331 ** Removed many minor problems (name clashes, unreached code) 00332 ** reported by Sun CC4 with "+w" or Sun CC2. 00333 ** 00334 ** Revision 1.3 1997/09/11 15:43:16 hewett 00335 ** Minor changes to eliminate warnings when compiled under the 00336 ** Signus GnuWin32 envionment. Changed order of initialisers 00337 ** for OFListLink and OFStackLink. Make ~OFLisBase and ~OFStackBase 00338 ** virtual destructors. 00339 ** 00340 ** Revision 1.2 1997/07/21 09:02:24 andreas 00341 ** - New copy constructor for class OFStack 00342 ** 00343 ** Revision 1.1 1997/07/02 11:51:15 andreas 00344 ** - Preliminary release of the OFFIS Standard Library. 00345 ** In the future this library shall contain a subset of the 00346 ** ANSI C++ Library (Version 3) that works on a lot of different 00347 ** compilers. Additionally this library shall include classes and 00348 ** functions that are often used. All classes and functions begin 00349 ** with OF... This library is independent of the DICOM development and 00350 ** shall contain no DICOM specific stuff. 00351 ** 00352 ** 00353 */