00001 /* 00002 * 00003 * Copyright (C) 1994-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: dcmnet 00019 * 00020 * Author: Marco Eichelberg 00021 * 00022 * Purpose: 00023 * template <class T> class DcmKeyValuePair 00024 * template <class T> class DcmSimpleMap 00025 * these template classes implement a simple map of key-value pairs. 00026 * The template type must be copy constructable. 00027 * 00028 * Last Update: $Author: meichel $ 00029 * Update Date: $Date: 2005/12/08 16:02:17 $ 00030 * Source File: $Source: /share/dicom/cvs-depot/dcmtk/dcmnet/include/dcmtk/dcmnet/dcmsmap.h,v $ 00031 * CVS/RCS Revision: $Revision: 1.6 $ 00032 * Status: $State: Exp $ 00033 * 00034 * CVS/RCS Log at end of file 00035 * 00036 */ 00037 00038 #ifndef DCMSMAP_H 00039 #define DCMSMAP_H 00040 00041 #include "dcmtk/config/osconfig.h" 00042 #include "dcmtk/ofstd/oflist.h" /* for class OFList<> */ 00043 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */ 00044 00045 00050 template <class T> class DcmKeyValuePair 00051 { 00052 public: 00057 DcmKeyValuePair(const OFString& k, const T& v) 00058 : key_(k) 00059 , value_(v) 00060 { 00061 } 00062 00064 DcmKeyValuePair(const DcmKeyValuePair& arg) 00065 : key_(arg.key_) 00066 , value_(arg.value_) 00067 { 00068 } 00069 00071 ~DcmKeyValuePair() 00072 { 00073 } 00074 00078 const T& value() const 00079 { 00080 return value_; 00081 } 00082 00086 T& value() 00087 { 00088 return value_; 00089 } 00090 00094 OFBool matches(const OFString &key) const 00095 { 00096 return (key_ == key); 00097 } 00098 00103 OFBool operator==(const DcmKeyValuePair& arg) const 00104 { 00105 return (key_ == arg.key_) && (value_ == arg.value_); 00106 } 00107 00108 private: 00110 DcmKeyValuePair& operator=(const DcmKeyValuePair& arg); 00111 00113 OFString key_; 00114 00116 T value_; 00117 }; 00118 00119 00125 template <class T> class DcmSimpleMap 00126 { 00127 public: 00129 DcmSimpleMap() 00130 : list_() 00131 { 00132 } 00133 00135 ~DcmSimpleMap() 00136 { 00137 OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) first(list_.begin()); 00138 OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) last(list_.end()); 00139 while (first != last) 00140 { 00141 delete (*first); 00142 first = list_.erase(first); 00143 } 00144 } 00145 00152 OFBool add(const OFString& key, const T& value) 00153 { 00154 OFBool result = OFFalse; 00155 if (! lookup(key)) 00156 { 00157 list_.push_back(new DcmKeyValuePair<T>(key, value)); 00158 result = OFTrue; 00159 } 00160 return result; 00161 } 00162 00167 const T *lookup(const OFString& key) const 00168 { 00169 OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) first(list_.begin()); 00170 OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) last(list_.end()); 00171 while (first != last) 00172 { 00173 if ((*first)->matches(key)) return &((*first)->value()); 00174 ++first; 00175 } 00176 return NULL; 00177 } 00178 00181 OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) begin() 00182 { 00183 return list_.begin(); 00184 } 00185 00188 OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) end() 00189 { 00190 return list_.end(); 00191 } 00192 00193 private: 00195 DcmSimpleMap(const DcmSimpleMap& arg); 00196 00198 DcmSimpleMap& operator=(const DcmSimpleMap& arg); 00199 00201 OFList<DcmKeyValuePair<T> *> list_; 00202 00203 }; 00204 00205 #endif 00206 00207 /* 00208 * CVS/RCS Log 00209 * $Log: dcmsmap.h,v $ 00210 * Revision 1.6 2005/12/08 16:02:17 meichel 00211 * Changed include path schema for all DCMTK header files 00212 * 00213 * Revision 1.5 2004/05/05 12:57:56 meichel 00214 * Simplified template class DcmSimpleMap<T>, needed for Sun CC 2.0.1 00215 * 00216 * Revision 1.4 2003/07/11 13:42:17 joergr 00217 * Added workaround to get rid of "implicit typename" warnings on gcc 3.x 00218 * (introduced macro OFLIST_TYPENAME). 00219 * 00220 * Revision 1.3 2003/07/03 15:56:19 meichel 00221 * Introduced workaround for "implicit typename" warning on gcc 3.x when 00222 * compiling with HAVE_STL. 00223 * 00224 * Revision 1.2 2003/06/18 08:16:17 meichel 00225 * Added comparison operators to keep MSVC5 compiler happy 00226 * 00227 * Revision 1.1 2003/06/10 14:27:33 meichel 00228 * Initial release of class DcmAssociationConfiguration and support 00229 * classes. This class maintains a list of association negotiation 00230 * profiles that can be addressed by symbolic keys. The profiles may 00231 * be read from a configuration file. 00232 * 00233 * 00234 */