00001 /* 00002 * 00003 * Copyright (C) 2000-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmsr 00015 * 00016 * Author: Joerg Riesmeier 00017 * 00018 * Purpose: 00019 * classes: DSRListOfItems 00020 * 00021 * Last Update: $Author: joergr $ 00022 * Update Date: $Date: 2010-10-14 13:16:33 $ 00023 * CVS/RCS Revision: $Revision: 1.14 $ 00024 * Status: $State: Exp $ 00025 * 00026 * CVS/RCS Log at end of file 00027 * 00028 */ 00029 00030 00031 #ifndef DSRTLIST_H 00032 #define DSRTLIST_H 00033 00034 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00035 00036 #include "dcmtk/ofstd/oflist.h" 00037 00038 #include "dcmtk/dcmdata/dcerror.h" 00039 00040 00041 /*---------------------* 00042 * class declaration * 00043 *---------------------*/ 00044 00049 template<class T> class DSRListOfItems 00050 { 00051 00052 public: 00053 00056 DSRListOfItems() 00057 : ItemList() 00058 { 00059 } 00060 00064 DSRListOfItems(const DSRListOfItems<T> &lst) 00065 : ItemList(lst.ItemList) 00066 { 00067 } 00068 00071 virtual ~DSRListOfItems() 00072 { 00073 } 00074 00079 inline DSRListOfItems<T> &operator=(const DSRListOfItems<T> &lst) 00080 { 00081 /* class OFList has no overloaded assignment operator */ 00082 ItemList.clear(); 00083 const OFLIST_TYPENAME OFListConstIterator(T) endPos = lst.ItemList.end(); 00084 OFLIST_TYPENAME OFListConstIterator(T) iterator = lst.ItemList.begin(); 00085 while (iterator != endPos) 00086 { 00087 ItemList.push_back(*iterator); 00088 iterator++; 00089 } 00090 return *this; 00091 } 00092 00095 inline void clear() 00096 { 00097 ItemList.clear(); 00098 } 00099 00103 inline OFBool isEmpty() const 00104 { 00105 return ItemList.empty(); 00106 } 00107 00111 inline size_t getNumberOfItems() const 00112 { 00113 return ItemList.size(); 00114 } 00115 00120 OFBool isElement(const T &item) const 00121 { 00122 OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin(); 00123 return gotoItem(item, iterator); 00124 } 00125 00130 const T &getItem(const size_t idx) const 00131 { 00132 OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin(); 00133 if (gotoItemPos(idx, iterator)) 00134 return *iterator; 00135 else 00136 return EmptyItem; 00137 } 00138 00145 OFCondition getItem(const size_t idx, 00146 T &item) const 00147 { 00148 OFCondition result = EC_IllegalParameter; 00149 OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin(); 00150 if (gotoItemPos(idx, iterator)) 00151 { 00152 item = *iterator; 00153 result = EC_Normal; 00154 } 00155 return result; 00156 } 00157 00161 inline void addItem(const T &item) 00162 { 00163 ItemList.push_back(item); 00164 } 00165 00169 inline void addOnlyNewItem(const T &item) 00170 { 00171 if (!isElement(item)) 00172 ItemList.push_back(item); 00173 } 00174 00180 OFCondition insertItem(const size_t idx, 00181 const T &item) 00182 { 00183 OFCondition result = EC_IllegalParameter; 00184 if (idx == ItemList.size() + 1) 00185 { 00186 /* append to the end of the list */ 00187 ItemList.push_back(item); 00188 result = EC_Normal; 00189 } else { 00190 OFLIST_TYPENAME OFListIterator(T) iterator = ItemList.begin(); 00191 if (gotoItemPos(idx, iterator)) 00192 { 00193 ItemList.insert(iterator, 1, item); 00194 result = EC_Normal; 00195 } 00196 } 00197 return result; 00198 } 00199 00204 OFCondition removeItem(const size_t idx) 00205 { 00206 OFCondition result = EC_IllegalParameter; 00207 OFLIST_TYPENAME OFListIterator(T) iterator = ItemList.begin(); 00208 if (gotoItemPos(idx, iterator)) 00209 { 00210 ItemList.erase(iterator); 00211 result = EC_Normal; 00212 } 00213 return result; 00214 } 00215 00219 static const T EmptyItem; 00220 00221 00222 protected: 00223 00229 OFBool gotoItemPos(size_t idx, 00230 OFLIST_TYPENAME OFListConstIterator(T) &iterator) const 00231 { 00232 OFBool result = OFFalse; 00233 if (idx > 0) 00234 { 00235 const OFLIST_TYPENAME OFListConstIterator(T) endPos = ItemList.end(); 00236 while ((--idx > 0) && (iterator != endPos)) 00237 iterator++; 00238 /* index found? */ 00239 result = (idx == 0); 00240 } 00241 return result; 00242 } 00243 00249 OFBool gotoItem(const T &item, 00250 OFLIST_TYPENAME OFListConstIterator(T) &iterator) const 00251 { 00252 const OFLIST_TYPENAME OFListConstIterator(T) endPos = ItemList.end(); 00253 /* operator== is used to reduce requirements for class T */ 00254 while ((iterator != endPos) && (!(*iterator == item))) 00255 iterator++; 00256 return (iterator != endPos); 00257 } 00258 00259 protected: 00260 00262 OFList<T> ItemList; 00263 }; 00264 00265 00266 #endif 00267 00268 00269 /* 00270 * CVS/RCS Log: 00271 * $Log: dsrtlist.h,v $ 00272 * Revision 1.14 2010-10-14 13:16:33 joergr 00273 * Updated copyright header. Added reference to COPYRIGHT file. 00274 * 00275 * Revision 1.13 2005-12-08 16:05:27 meichel 00276 * Changed include path schema for all DCMTK header files 00277 * 00278 * Revision 1.12 2003/08/07 12:55:13 joergr 00279 * Updated documentation to get rid of doxygen warnings. 00280 * 00281 * Revision 1.11 2003/07/11 13:44:00 joergr 00282 * Added workaround to get rid of "implicit typename" warnings on gcc 3.x 00283 * (introduced macro OFLIST_TYPENAME). 00284 * 00285 * Revision 1.10 2003/06/04 12:40:01 meichel 00286 * Replaced protected inheritance from OFList with protected aggregation 00287 * 00288 * Revision 1.9 2003/06/03 10:16:44 meichel 00289 * Renamed local variables to avoid name clashes with STL 00290 * 00291 * Revision 1.8 2001/10/10 15:27:41 joergr 00292 * Additonal adjustments for new OFCondition class. 00293 * 00294 * Revision 1.7 2001/09/26 13:04:13 meichel 00295 * Adapted dcmsr to class OFCondition 00296 * 00297 * Revision 1.6 2001/05/07 16:13:24 joergr 00298 * Updated CVS header. 00299 * 00300 * Revision 1.5 2001/01/25 11:48:11 joergr 00301 * Added method to insert item into a list. 00302 * 00303 * Revision 1.4 2000/12/12 14:17:13 joergr 00304 * Renamed method to avoid ambiguity reported by gcc 2.7. 00305 * 00306 * Revision 1.3 2000/10/26 14:19:38 joergr 00307 * Fixed bug: index in search routine was starting from 0 not 1. 00308 * 00309 * Revision 1.2 2000/10/18 17:08:44 joergr 00310 * Added doc++ comments. 00311 * 00312 * Revision 1.1 2000/10/13 07:49:34 joergr 00313 * Added new module 'dcmsr' providing access to DICOM structured reporting 00314 * documents (supplement 23). Doc++ documentation not yet completed. 00315 * 00316 * 00317 */