00001 /* 00002 * 00003 * Copyright (C) 2000-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: dcmsr 00019 * 00020 * Author: Joerg Riesmeier 00021 * 00022 * Purpose: 00023 * classes: DSRListOfItems 00024 * 00025 * Last Update: $Author: meichel $ 00026 * Update Date: $Date: 2005/12/08 16:05:27 $ 00027 * CVS/RCS Revision: $Revision: 1.13 $ 00028 * Status: $State: Exp $ 00029 * 00030 * CVS/RCS Log at end of file 00031 * 00032 */ 00033 00034 00035 #ifndef DSRTLIST_H 00036 #define DSRTLIST_H 00037 00038 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00039 00040 #include "dcmtk/ofstd/oflist.h" 00041 00042 #include "dcmtk/dcmdata/dcerror.h" 00043 00044 00045 /*---------------------* 00046 * class declaration * 00047 *---------------------*/ 00048 00053 template<class T> class DSRListOfItems 00054 { 00055 00056 public: 00057 00060 DSRListOfItems() 00061 : ItemList() 00062 { 00063 } 00064 00068 DSRListOfItems(const DSRListOfItems<T> &lst) 00069 : ItemList(lst.ItemList) 00070 { 00071 } 00072 00075 virtual ~DSRListOfItems() 00076 { 00077 } 00078 00083 inline DSRListOfItems<T> &operator=(const DSRListOfItems<T> &lst) 00084 { 00085 /* class OFList has no overloaded assignment operator */ 00086 ItemList.clear(); 00087 const OFLIST_TYPENAME OFListConstIterator(T) endPos = lst.ItemList.end(); 00088 OFLIST_TYPENAME OFListConstIterator(T) iterator = lst.ItemList.begin(); 00089 while (iterator != endPos) 00090 { 00091 ItemList.push_back(*iterator); 00092 iterator++; 00093 } 00094 return *this; 00095 } 00096 00099 inline void clear() 00100 { 00101 ItemList.clear(); 00102 } 00103 00107 inline OFBool isEmpty() const 00108 { 00109 return ItemList.empty(); 00110 } 00111 00115 inline size_t getNumberOfItems() const 00116 { 00117 return ItemList.size(); 00118 } 00119 00124 OFBool isElement(const T &item) const 00125 { 00126 OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin(); 00127 return gotoItem(item, iterator); 00128 } 00129 00134 const T &getItem(const size_t idx) const 00135 { 00136 OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin(); 00137 if (gotoItemPos(idx, iterator)) 00138 return *iterator; 00139 else 00140 return EmptyItem; 00141 } 00142 00149 OFCondition getItem(const size_t idx, 00150 T &item) const 00151 { 00152 OFCondition result = EC_IllegalParameter; 00153 OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin(); 00154 if (gotoItemPos(idx, iterator)) 00155 { 00156 item = *iterator; 00157 result = EC_Normal; 00158 } 00159 return result; 00160 } 00161 00165 inline void addItem(const T &item) 00166 { 00167 ItemList.push_back(item); 00168 } 00169 00173 inline void addOnlyNewItem(const T &item) 00174 { 00175 if (!isElement(item)) 00176 ItemList.push_back(item); 00177 } 00178 00184 OFCondition insertItem(const size_t idx, 00185 const T &item) 00186 { 00187 OFCondition result = EC_IllegalParameter; 00188 if (idx == ItemList.size() + 1) 00189 { 00190 /* append to the end of the list */ 00191 ItemList.push_back(item); 00192 result = EC_Normal; 00193 } else { 00194 OFLIST_TYPENAME OFListIterator(T) iterator = ItemList.begin(); 00195 if (gotoItemPos(idx, iterator)) 00196 { 00197 ItemList.insert(iterator, 1, item); 00198 result = EC_Normal; 00199 } 00200 } 00201 return result; 00202 } 00203 00208 OFCondition removeItem(const size_t idx) 00209 { 00210 OFCondition result = EC_IllegalParameter; 00211 OFLIST_TYPENAME OFListIterator(T) iterator = ItemList.begin(); 00212 if (gotoItemPos(idx, iterator)) 00213 { 00214 ItemList.erase(iterator); 00215 result = EC_Normal; 00216 } 00217 return result; 00218 } 00219 00223 static const T EmptyItem; 00224 00225 00226 protected: 00227 00233 OFBool gotoItemPos(size_t idx, 00234 OFLIST_TYPENAME OFListConstIterator(T) &iterator) const 00235 { 00236 OFBool result = OFFalse; 00237 if (idx > 0) 00238 { 00239 const OFLIST_TYPENAME OFListConstIterator(T) endPos = ItemList.end(); 00240 while ((--idx > 0) && (iterator != endPos)) 00241 iterator++; 00242 /* index found? */ 00243 result = (idx == 0); 00244 } 00245 return result; 00246 } 00247 00253 OFBool gotoItem(const T &item, 00254 OFLIST_TYPENAME OFListConstIterator(T) &iterator) const 00255 { 00256 const OFLIST_TYPENAME OFListConstIterator(T) endPos = ItemList.end(); 00257 /* operator== is used to reduce requirements for class T */ 00258 while ((iterator != endPos) && (!(*iterator == item))) 00259 iterator++; 00260 return (iterator != endPos); 00261 } 00262 00263 protected: 00264 00266 OFList<T> ItemList; 00267 }; 00268 00269 00270 #endif 00271 00272 00273 /* 00274 * CVS/RCS Log: 00275 * $Log: dsrtlist.h,v $ 00276 * Revision 1.13 2005/12/08 16:05:27 meichel 00277 * Changed include path schema for all DCMTK header files 00278 * 00279 * Revision 1.12 2003/08/07 12:55:13 joergr 00280 * Updated documentation to get rid of doxygen warnings. 00281 * 00282 * Revision 1.11 2003/07/11 13:44:00 joergr 00283 * Added workaround to get rid of "implicit typename" warnings on gcc 3.x 00284 * (introduced macro OFLIST_TYPENAME). 00285 * 00286 * Revision 1.10 2003/06/04 12:40:01 meichel 00287 * Replaced protected inheritance from OFList with protected aggregation 00288 * 00289 * Revision 1.9 2003/06/03 10:16:44 meichel 00290 * Renamed local variables to avoid name clashes with STL 00291 * 00292 * Revision 1.8 2001/10/10 15:27:41 joergr 00293 * Additonal adjustments for new OFCondition class. 00294 * 00295 * Revision 1.7 2001/09/26 13:04:13 meichel 00296 * Adapted dcmsr to class OFCondition 00297 * 00298 * Revision 1.6 2001/05/07 16:13:24 joergr 00299 * Updated CVS header. 00300 * 00301 * Revision 1.5 2001/01/25 11:48:11 joergr 00302 * Added method to insert item into a list. 00303 * 00304 * Revision 1.4 2000/12/12 14:17:13 joergr 00305 * Renamed method to avoid ambiguity reported by gcc 2.7. 00306 * 00307 * Revision 1.3 2000/10/26 14:19:38 joergr 00308 * Fixed bug: index in search routine was starting from 0 not 1. 00309 * 00310 * Revision 1.2 2000/10/18 17:08:44 joergr 00311 * Added doc++ comments. 00312 * 00313 * Revision 1.1 2000/10/13 07:49:34 joergr 00314 * Added new module 'dcmsr' providing access to DICOM structured reporting 00315 * documents (supplement 23). Doc++ documentation not yet completed. 00316 * 00317 * 00318 */