OFFIS DCMTK  Version 3.6.0
dcmsmap.h
1 /*
2  *
3  * Copyright (C) 1994-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: dcmnet
15  *
16  * Author: Marco Eichelberg
17  *
18  * Purpose:
19  * template <class T> class DcmKeyValuePair
20  * template <class T> class DcmSimpleMap
21  * these template classes implement a simple map of key-value pairs.
22  * The template type must be copy constructable.
23  *
24  * Last Update: $Author: joergr $
25  * Update Date: $Date: 2010-10-14 13:17:22 $
26  * CVS/RCS Revision: $Revision: 1.7 $
27  * Status: $State: Exp $
28  *
29  * CVS/RCS Log at end of file
30  *
31  */
32 
33 #ifndef DCMSMAP_H
34 #define DCMSMAP_H
35 
36 #include "dcmtk/config/osconfig.h"
37 #include "dcmtk/ofstd/oflist.h" /* for class OFList<> */
38 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */
39 
40 
45 template <class T> class DcmKeyValuePair
46 {
47 public:
52  DcmKeyValuePair(const OFString& k, const T& v)
53  : key_(k)
54  , value_(v)
55  {
56  }
57 
60  : key_(arg.key_)
61  , value_(arg.value_)
62  {
63  }
64 
67  {
68  }
69 
73  const T& value() const
74  {
75  return value_;
76  }
77 
81  T& value()
82  {
83  return value_;
84  }
85 
89  OFBool matches(const OFString &key) const
90  {
91  return (key_ == key);
92  }
93 
98  OFBool operator==(const DcmKeyValuePair& arg) const
99  {
100  return (key_ == arg.key_) && (value_ == arg.value_);
101  }
102 
103 private:
106 
109 
112 };
113 
114 
120 template <class T> class DcmSimpleMap
121 {
122 public:
125  : list_()
126  {
127  }
128 
131  {
132  OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) first(list_.begin());
133  OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) last(list_.end());
134  while (first != last)
135  {
136  delete (*first);
137  first = list_.erase(first);
138  }
139  }
140 
147  OFBool add(const OFString& key, const T& value)
148  {
149  OFBool result = OFFalse;
150  if (! lookup(key))
151  {
152  list_.push_back(new DcmKeyValuePair<T>(key, value));
153  result = OFTrue;
154  }
155  return result;
156  }
157 
162  const T *lookup(const OFString& key) const
163  {
164  OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) first(list_.begin());
165  OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) last(list_.end());
166  while (first != last)
167  {
168  if ((*first)->matches(key)) return &((*first)->value());
169  ++first;
170  }
171  return NULL;
172  }
173 
176  OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) begin()
177  {
178  return list_.begin();
179  }
180 
183  OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) end()
184  {
185  return list_.end();
186  }
187 
188 private:
190  DcmSimpleMap(const DcmSimpleMap& arg);
191 
193  DcmSimpleMap& operator=(const DcmSimpleMap& arg);
194 
197 
198 };
199 
200 #endif
201 
202 /*
203  * CVS/RCS Log
204  * $Log: dcmsmap.h,v $
205  * Revision 1.7 2010-10-14 13:17:22 joergr
206  * Updated copyright header. Added reference to COPYRIGHT file.
207  *
208  * Revision 1.6 2005/12/08 16:02:17 meichel
209  * Changed include path schema for all DCMTK header files
210  *
211  * Revision 1.5 2004/05/05 12:57:56 meichel
212  * Simplified template class DcmSimpleMap<T>, needed for Sun CC 2.0.1
213  *
214  * Revision 1.4 2003/07/11 13:42:17 joergr
215  * Added workaround to get rid of "implicit typename" warnings on gcc 3.x
216  * (introduced macro OFLIST_TYPENAME).
217  *
218  * Revision 1.3 2003/07/03 15:56:19 meichel
219  * Introduced workaround for "implicit typename" warning on gcc 3.x when
220  * compiling with HAVE_STL.
221  *
222  * Revision 1.2 2003/06/18 08:16:17 meichel
223  * Added comparison operators to keep MSVC5 compiler happy
224  *
225  * Revision 1.1 2003/06/10 14:27:33 meichel
226  * Initial release of class DcmAssociationConfiguration and support
227  * classes. This class maintains a list of association negotiation
228  * profiles that can be addressed by symbolic keys. The profiles may
229  * be read from a configuration file.
230  *
231  *
232  */


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