00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef DCMSMAP_H
00039 #define DCMSMAP_H
00040
00041 #include "dcmtk/config/osconfig.h"
00042 #include "dcmtk/ofstd/oflist.h"
00043 #include "dcmtk/ofstd/ofstring.h"
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
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234