/usr/include/dcmtk/dcmnet/dcmsmap.h is in libdcmtk-dev 3.6.2-3build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | /*
*
* Copyright (C) 1994-2011, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmnet
*
* Author: Marco Eichelberg
*
* Purpose:
* template <class T> class DcmKeyValuePair
* template <class T> class DcmSimpleMap
* these template classes implement a simple map of key-value pairs.
* The template type must be copy constructable.
*
*/
#ifndef DCMSMAP_H
#define DCMSMAP_H
#include "dcmtk/config/osconfig.h"
#include "dcmtk/ofstd/oflist.h" /* for class OFList<> */
#include "dcmtk/ofstd/ofstring.h" /* for class OFString */
/** this template class implements a simple key - value pair map
* that is used in template class DcmSimpleMap. Template type must be
* copy constructable.
*/
template <class T> class DcmKeyValuePair
{
public:
/** constructor
* @param k key
* @param v value
*/
DcmKeyValuePair(const OFString& k, const T& v)
: key_(k)
, value_(v)
{
}
/// copy constructor
DcmKeyValuePair(const DcmKeyValuePair& arg)
: key_(arg.key_)
, value_(arg.value_)
{
}
/// destructor
~DcmKeyValuePair()
{
}
/** return key of key-value pair
* @return key as const reference
*/
const OFString& key() const
{
return key_;
}
/** return value of key-value pair
* @return value as const reference
*/
const T& value() const
{
return value_;
}
/** return value of key-value pair
* @return value as non-const reference
*/
T& value()
{
return value_;
}
/** checks if this entry matches the given key
* @return true if key matches, false otherwise
*/
OFBool matches(const OFString &key) const
{
return (key_ == key);
}
/** comparison operator.
* @param arg object to compare with
* @return true if equal
*/
OFBool operator==(const DcmKeyValuePair& arg) const
{
return (key_ == arg.key_) && (value_ == arg.value_);
}
private:
/// private undefined copy assignment operator
DcmKeyValuePair& operator=(const DcmKeyValuePair& arg);
/// the key
OFString key_;
/// the value
T value_;
};
/** this class implements a simple map of key-value pairs.
* No double keys are permitted, the second attempt to insert
* an element with a key already present will fail.
* Template type must be copy constructable.
*/
template <class T> class DcmSimpleMap
{
public:
/// default constructor
DcmSimpleMap()
: list_()
{
}
/// destructor
~DcmSimpleMap()
{
OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) first(list_.begin());
OFLIST_TYPENAME OFListIterator(DcmKeyValuePair<T> *) last(list_.end());
while (first != last)
{
delete (*first);
first = list_.erase(first);
}
}
/** inserts a new key-value pair into the map
* by means of copy construction.
* @param key key
* @param value value
* @return true if successful, false if failed because key already present
*/
OFBool add(const OFString& key, const T& value)
{
OFBool result = OFFalse;
if (! lookup(key))
{
list_.push_back(new DcmKeyValuePair<T>(key, value));
result = OFTrue;
}
return result;
}
/** looks up the given key in the map.
* @param key key
* @return pointer to value if found, NULL otherwise.
*/
const T *lookup(const OFString& key) const
{
OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) first(list_.begin());
OFLIST_TYPENAME OFListConstIterator(DcmKeyValuePair<T> *) last(list_.end());
while (first != last)
{
if ((*first)->matches(key)) return &((*first)->value());
++first;
}
return NULL;
}
/** return iterator to first element in list
*/
OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) begin()
{
return list_.begin();
}
/** return iterator to end of list
*/
OFLIST_TYPENAME OFListIterator( DcmKeyValuePair<T> * ) end()
{
return list_.end();
}
private:
/// private undefined copy constructor
DcmSimpleMap(const DcmSimpleMap& arg);
/// private undefined copy assignment operator
DcmSimpleMap& operator=(const DcmSimpleMap& arg);
/// the list of key-value pairs
OFList<DcmKeyValuePair<T> *> list_;
};
#endif
|