/usr/include/dcmtk/ofstd/ofmap.h is in libdcmtk2-dev 3.6.0-15.
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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | /*
*
* Copyright (C) 2009-2010, 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: ofstd
*
* Author: Uli Schlachter
*
* Purpose: Defines a template map class with interfaces similar to the C++
* Standard
*
* Last Update: $Author: uli $
* Update Date: $Date: 2010-11-08 09:49:03 $
* CVS/RCS Revision: $Revision: 1.6 $
* Status: $State: Exp $
*
* CVS/RCS Log at end of file
*
*/
#ifndef OFMAP_H
#define OFMAP_H
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#if defined(HAVE_STL) || defined(HAVE_STL_MAP)
// it is possible to use the standard template library map class since the
// interface is nearly identical.
#include <map>
#define OFMap std::map
#define OFPair std::pair
#define OFMake_pair std::make_pair
#else
#include "dcmtk/ofstd/oftypes.h"
#include "dcmtk/ofstd/ofcast.h"
#include "dcmtk/ofstd/oflist.h"
#ifndef HAVE_CLASS_TEMPLATE
#error Your C++ compiler cannot handle class templates:
#endif
/** a pair - this implements parts of std::pair's interface.
*/
template<typename K, typename V> class OFPair
{
public:
/** this is the first value of the pair */
K first;
/** this is the second value of the pair */
V second;
/** default constructor */
OFPair() : first(), second() { }
/** construct a OFPair for the two given values
* @param f the value for first.
* @param s the value for second.
*/
OFPair(const K& f, const V& s) : first(f), second(s) { }
/** copy assignment operator
*/
OFPair& operator=(const OFPair& other)
{
first = other.first;
second = other.second;
return *this;
}
};
/** helper function to create a pair. This is similar to std::make_pair()
* @param first the first part of the pair
* @param second the second art of the pair
* @return the pair (first, second)
*/
template<typename K, typename V>
OFPair<K, V> OFMake_pair(const K& first, const V& second)
{
return OFPair<K, V>(first, second);
}
/** associative container class. This class is a subset of std::map.
*/
template<typename K, typename V> class OFMap
{
public:
/** the type of values saved in this map */
typedef OFPair<K, V> value_type;
protected:
/// @todo using a list as base is slooooow
OFList<value_type> values_;
public:
/** iterator class for OFMap. You can modify elements through this
* iterator's ->first and ->second properties.
*/
typedef OFListIterator(value_type) iterator;
/** constant iterator class for OFMap. You can read the elements, but you may
* not modify them.
*/
typedef OFListConstIterator(value_type) const_iterator;
/** default constructor */
OFMap() : values_() { }
/** copy constructor */
OFMap& operator=(const OFMap& other)
{
clear();
for (const_iterator it = other.begin();
it != other.end(); it++)
insert(*it);
return *this;
}
/** index operator. You can use this to add new elements to the map.
* Beware: Don't use this for checking if a given key is already used in
* the map, use find() != end() for this job!
* @param key the key you want to access
* @return reference to the value saved under the given key.
*/
V& operator[](const K& key)
{
iterator it = find(key);
if (it == end())
{
it = insert(value_type(key, V())).first;
}
return it->second;
}
/** returns iterator pointing to the first element of this map
* @return iterator pointing to the first element of this map
*/
iterator begin() { return values_.begin(); }
/** returns iterator pointer after the last element of this map
* @return iterator pointer after the last element of this map
*/
iterator end() { return values_.end(); }
/** returns constant iterator pointing to the first element of this map
* @return constant iterator pointing to the first element of this map
*/
const_iterator begin() const { return values_.begin(); }
/** returns constant iterator pointer after the last element of this map
* @return constant iterator pointer after the last element of this map
*/
const_iterator end() const { return values_.end(); }
/** looks up the given key in this map
* @param key the key to look for
* @return iterator for that key to end()
*/
iterator find(const K& key)
{
iterator it = begin();
while (it != end())
{
if (it->first == key)
break;
it++;
}
return it;
}
/** looks up the given key in this map
* @param key the key to look for
* @return constant iterator for that key to end()
*/
const_iterator find(const K& key) const
{
const_iterator it = begin();
while (it != end())
{
if (it->first == key)
break;
it++;
}
return it;
}
/** returns the number of elements saved in this map
* @return the number of elements saved in this map
*/
size_t size() const { return values_.size(); }
/** removes all elements from this map */
void clear() { values_.clear(); }
/** removes all elements in the given range from this map
* @param first the first element to remove
* @param last the first element NOT to remove
*/
void erase(const iterator& first, const iterator& last)
{
values_.erase(first, last);
}
/** removes the element to which the given iterator points to
* @param elem the element to remove
*/
void erase(const iterator& elem)
{
values_.erase(elem);
}
/** removes the element with the given key from this map
* @return the number of elements removed (0 or 1)
*/
int erase(const K& key)
{
iterator it = find(key);
if (it == end())
return 0;
values_.erase(it);
return 1;
}
/** inserts a new element into the map, but does not overwrite existing
* elements
* @param val the value to insert
* @return a pair of an iterator and a boolean. The iterator always points
* to the element which got val's key. The boolean is true if val was
* inserted, false otherwise.
*/
OFPair<iterator, bool> insert(const value_type& val)
{
OFListIterator(value_type) it = find(val.first);
if (it != end())
return OFMake_pair(it, false);
it = values_.insert(values_.end(), val);
return OFMake_pair(it, true);
}
};
#endif
#endif
/*
** CVS/RCS Log:
** $Log: ofmap.h,v $
** Revision 1.6 2010-11-08 09:49:03 uli
** Fixed even more gcc warnings caused by additional compiler flags.
**
** Revision 1.5 2010-10-14 13:15:50 joergr
** Updated copyright header. Added reference to COPYRIGHT file.
**
** Revision 1.4 2010-10-08 12:27:07 uli
** Fixed all doxygen warnings for OFPair and OFauto_ptr.
**
** Revision 1.3 2010-08-06 08:41:36 uli
** Fixed some more compiler warnings.
**
** Revision 1.2 2009-09-29 13:59:34 uli
** Fix an invalid iterator use in OFMap. A iterator was used after it was passed
** to erase().
** Add a test case which verifies some of OFMap's implementation.
**
** Revision 1.1 2009-08-19 10:52:08 joergr
** Added new class OFMap required for upcoming module "oflog".
**
**
*/
|