OFFIS DCMTK  Version 3.6.0
dsrtlist.h
1 /*
2  *
3  * Copyright (C) 2000-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: dcmsr
15  *
16  * Author: Joerg Riesmeier
17  *
18  * Purpose:
19  * classes: DSRListOfItems
20  *
21  * Last Update: $Author: joergr $
22  * Update Date: $Date: 2010-10-14 13:16:33 $
23  * CVS/RCS Revision: $Revision: 1.14 $
24  * Status: $State: Exp $
25  *
26  * CVS/RCS Log at end of file
27  *
28  */
29 
30 
31 #ifndef DSRTLIST_H
32 #define DSRTLIST_H
33 
34 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
35 
36 #include "dcmtk/ofstd/oflist.h"
37 
38 #include "dcmtk/dcmdata/dcerror.h"
39 
40 
41 /*---------------------*
42  * class declaration *
43  *---------------------*/
44 
49 template<class T> class DSRListOfItems
50 {
51 
52  public:
53 
57  : ItemList()
58  {
59  }
60 
65  : ItemList(lst.ItemList)
66  {
67  }
68 
71  virtual ~DSRListOfItems()
72  {
73  }
74 
80  {
81  /* class OFList has no overloaded assignment operator */
82  ItemList.clear();
83  const OFLIST_TYPENAME OFListConstIterator(T) endPos = lst.ItemList.end();
84  OFLIST_TYPENAME OFListConstIterator(T) iterator = lst.ItemList.begin();
85  while (iterator != endPos)
86  {
87  ItemList.push_back(*iterator);
88  iterator++;
89  }
90  return *this;
91  }
92 
95  inline void clear()
96  {
97  ItemList.clear();
98  }
99 
103  inline OFBool isEmpty() const
104  {
105  return ItemList.empty();
106  }
107 
111  inline size_t getNumberOfItems() const
112  {
113  return ItemList.size();
114  }
115 
120  OFBool isElement(const T &item) const
121  {
122  OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin();
123  return gotoItem(item, iterator);
124  }
125 
130  const T &getItem(const size_t idx) const
131  {
132  OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin();
133  if (gotoItemPos(idx, iterator))
134  return *iterator;
135  else
136  return EmptyItem;
137  }
138 
145  OFCondition getItem(const size_t idx,
146  T &item) const
147  {
148  OFCondition result = EC_IllegalParameter;
149  OFLIST_TYPENAME OFListConstIterator(T) iterator = ItemList.begin();
150  if (gotoItemPos(idx, iterator))
151  {
152  item = *iterator;
153  result = EC_Normal;
154  }
155  return result;
156  }
157 
161  inline void addItem(const T &item)
162  {
163  ItemList.push_back(item);
164  }
165 
169  inline void addOnlyNewItem(const T &item)
170  {
171  if (!isElement(item))
172  ItemList.push_back(item);
173  }
174 
180  OFCondition insertItem(const size_t idx,
181  const T &item)
182  {
183  OFCondition result = EC_IllegalParameter;
184  if (idx == ItemList.size() + 1)
185  {
186  /* append to the end of the list */
187  ItemList.push_back(item);
188  result = EC_Normal;
189  } else {
190  OFLIST_TYPENAME OFListIterator(T) iterator = ItemList.begin();
191  if (gotoItemPos(idx, iterator))
192  {
193  ItemList.insert(iterator, 1, item);
194  result = EC_Normal;
195  }
196  }
197  return result;
198  }
199 
204  OFCondition removeItem(const size_t idx)
205  {
206  OFCondition result = EC_IllegalParameter;
207  OFLIST_TYPENAME OFListIterator(T) iterator = ItemList.begin();
208  if (gotoItemPos(idx, iterator))
209  {
210  ItemList.erase(iterator);
211  result = EC_Normal;
212  }
213  return result;
214  }
215 
219  static const T EmptyItem;
220 
221 
222  protected:
223 
229  OFBool gotoItemPos(size_t idx,
230  OFLIST_TYPENAME OFListConstIterator(T) &iterator) const
231  {
232  OFBool result = OFFalse;
233  if (idx > 0)
234  {
235  const OFLIST_TYPENAME OFListConstIterator(T) endPos = ItemList.end();
236  while ((--idx > 0) && (iterator != endPos))
237  iterator++;
238  /* index found? */
239  result = (idx == 0);
240  }
241  return result;
242  }
243 
249  OFBool gotoItem(const T &item,
250  OFLIST_TYPENAME OFListConstIterator(T) &iterator) const
251  {
252  const OFLIST_TYPENAME OFListConstIterator(T) endPos = ItemList.end();
253  /* operator== is used to reduce requirements for class T */
254  while ((iterator != endPos) && (!(*iterator == item)))
255  iterator++;
256  return (iterator != endPos);
257  }
258 
259  protected:
260 
263 };
264 
265 
266 #endif
267 
268 
269 /*
270  * CVS/RCS Log:
271  * $Log: dsrtlist.h,v $
272  * Revision 1.14 2010-10-14 13:16:33 joergr
273  * Updated copyright header. Added reference to COPYRIGHT file.
274  *
275  * Revision 1.13 2005-12-08 16:05:27 meichel
276  * Changed include path schema for all DCMTK header files
277  *
278  * Revision 1.12 2003/08/07 12:55:13 joergr
279  * Updated documentation to get rid of doxygen warnings.
280  *
281  * Revision 1.11 2003/07/11 13:44:00 joergr
282  * Added workaround to get rid of "implicit typename" warnings on gcc 3.x
283  * (introduced macro OFLIST_TYPENAME).
284  *
285  * Revision 1.10 2003/06/04 12:40:01 meichel
286  * Replaced protected inheritance from OFList with protected aggregation
287  *
288  * Revision 1.9 2003/06/03 10:16:44 meichel
289  * Renamed local variables to avoid name clashes with STL
290  *
291  * Revision 1.8 2001/10/10 15:27:41 joergr
292  * Additonal adjustments for new OFCondition class.
293  *
294  * Revision 1.7 2001/09/26 13:04:13 meichel
295  * Adapted dcmsr to class OFCondition
296  *
297  * Revision 1.6 2001/05/07 16:13:24 joergr
298  * Updated CVS header.
299  *
300  * Revision 1.5 2001/01/25 11:48:11 joergr
301  * Added method to insert item into a list.
302  *
303  * Revision 1.4 2000/12/12 14:17:13 joergr
304  * Renamed method to avoid ambiguity reported by gcc 2.7.
305  *
306  * Revision 1.3 2000/10/26 14:19:38 joergr
307  * Fixed bug: index in search routine was starting from 0 not 1.
308  *
309  * Revision 1.2 2000/10/18 17:08:44 joergr
310  * Added doc++ comments.
311  *
312  * Revision 1.1 2000/10/13 07:49:34 joergr
313  * Added new module 'dcmsr' providing access to DICOM structured reporting
314  * documents (supplement 23). Doc++ documentation not yet completed.
315  *
316  *
317  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2