00001 /* 00002 * 00003 * Copyright (C) 1994-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: dcmnet 00015 * 00016 * Author: Marco Eichelberg 00017 * 00018 * Purpose: 00019 * template <class T> class DcmKeyValuePair 00020 * template <class T> class DcmSimpleMap 00021 * these template classes implement a simple map of key-value pairs. 00022 * The template type must be copy constructable. 00023 * 00024 * Last Update: $Author: joergr $ 00025 * Update Date: $Date: 2010-10-14 13:17:22 $ 00026 * CVS/RCS Revision: $Revision: 1.7 $ 00027 * Status: $State: Exp $ 00028 * 00029 * CVS/RCS Log at end of file 00030 * 00031 */ 00032 00033 #ifndef DCMSMAP_H 00034 #define DCMSMAP_H 00035 00036 #include "dcmtk/config/osconfig.h" 00037 #include "dcmtk/ofstd/oflist.h" /* for class OFList<> */ 00038 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */ 00039 00040 00045 template <class T> class DcmKeyValuePair 00046 { 00047 public: 00052 DcmKeyValuePair(const OFString& k, const T& v) 00053 : key_(k) 00054 , value_(v) 00055 { 00056 } 00057 00059 DcmKeyValuePair(const DcmKeyValuePair& arg) 00060 : key_(arg.key_) 00061 , value_(arg.value_) 00062 { 00063 } 00064 00066 ~DcmKeyValuePair() 00067 { 00068 } 00069 00073 const T& value() const 00074 { 00075 return value_; 00076 } 00077 00081 T& value() 00082 { 00083 return value_; 00084 } 00085 00089 OFBool matches(const OFString &key) const 00090 { 00091 return (key_ == key); 00092 } 00093 00098 OFBool operator==(const DcmKeyValuePair& arg) const 00099 { 00100 return (key_ == arg.key_) && (value_ == arg.value_); 00101 } 00102 00103 private: 00105 DcmKeyValuePair& operator=(const DcmKeyValuePair& arg); 00106 00108 OFString key_; 00109 00111 T value_; 00112 }; 00113 00114 00120 template <class T> class DcmSimpleMap 00121 { 00122 public: 00124 DcmSimpleMap() 00125 : list_() 00126 { 00127 } 00128 00130 ~DcmSimpleMap() 00131 { 00132 OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) first(list_.begin()); 00133 OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) last(list_.end()); 00134 while (first != last) 00135 { 00136 delete (*first); 00137 first = list_.erase(first); 00138 } 00139 } 00140 00147 OFBool add(const OFString& key, const T& value) 00148 { 00149 OFBool result = OFFalse; 00150 if (! lookup(key)) 00151 { 00152 list_.push_back(new DcmKeyValuePair<T>(key, value)); 00153 result = OFTrue; 00154 } 00155 return result; 00156 } 00157 00162 const T *lookup(const OFString& key) const 00163 { 00164 OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) first(list_.begin()); 00165 OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) last(list_.end()); 00166 while (first != last) 00167 { 00168 if ((*first)->matches(key)) return &((*first)->value()); 00169 ++first; 00170 } 00171 return NULL; 00172 } 00173 00176 OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) begin() 00177 { 00178 return list_.begin(); 00179 } 00180 00183 OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) end() 00184 { 00185 return list_.end(); 00186 } 00187 00188 private: 00190 DcmSimpleMap(const DcmSimpleMap& arg); 00191 00193 DcmSimpleMap& operator=(const DcmSimpleMap& arg); 00194 00196 OFList<DcmKeyValuePair<T> *> list_; 00197 00198 }; 00199 00200 #endif 00201 00202 /* 00203 * CVS/RCS Log 00204 * $Log: dcmsmap.h,v $ 00205 * Revision 1.7 2010-10-14 13:17:22 joergr 00206 * Updated copyright header. Added reference to COPYRIGHT file. 00207 * 00208 * Revision 1.6 2005/12/08 16:02:17 meichel 00209 * Changed include path schema for all DCMTK header files 00210 * 00211 * Revision 1.5 2004/05/05 12:57:56 meichel 00212 * Simplified template class DcmSimpleMap<T>, needed for Sun CC 2.0.1 00213 * 00214 * Revision 1.4 2003/07/11 13:42:17 joergr 00215 * Added workaround to get rid of "implicit typename" warnings on gcc 3.x 00216 * (introduced macro OFLIST_TYPENAME). 00217 * 00218 * Revision 1.3 2003/07/03 15:56:19 meichel 00219 * Introduced workaround for "implicit typename" warning on gcc 3.x when 00220 * compiling with HAVE_STL. 00221 * 00222 * Revision 1.2 2003/06/18 08:16:17 meichel 00223 * Added comparison operators to keep MSVC5 compiler happy 00224 * 00225 * Revision 1.1 2003/06/10 14:27:33 meichel 00226 * Initial release of class DcmAssociationConfiguration and support 00227 * classes. This class maintains a list of association negotiation 00228 * profiles that can be addressed by symbolic keys. The profiles may 00229 * be read from a configuration file. 00230 * 00231 * 00232 */