/usr/include/ace/Array_Map.cpp is in libace-dev 6.2.8+dfsg-1.
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 | // $Id: Array_Map.cpp 92386 2010-10-28 07:44:37Z johnnyw $
#ifndef ACE_ARRAY_MAP_CPP
#define ACE_ARRAY_MAP_CPP
#include "ace/Array_Map.h"
#ifndef __ACE_INLINE__
# include "ace/Array_Map.inl"
#endif /* !__ACE_INLINE__ */
#include "ace/checked_iterator.h"
#include <algorithm>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
template<typename Key, typename Value, class EqualTo>
template<typename InputIterator>
ACE_Array_Map<Key, Value, EqualTo>::ACE_Array_Map (InputIterator f,
InputIterator l)
: size_ (l - f)
, capacity_ (size_)
, nodes_ (size_ == 0 ? 0 : new value_type[size_])
{
(void) std::copy (f,
l,
ACE_make_checked_array_iterator (this->begin (),
this->size_));
// iterator n = this->begin ();
// for (InputIterator i = f; i != l; ++i, ++n)
// *n = *i;
}
template<typename Key, typename Value, class EqualTo>
ACE_Array_Map<Key, Value, EqualTo>::ACE_Array_Map (
ACE_Array_Map<Key, Value, EqualTo> const & map)
: size_ (map.size_)
, capacity_ (map.size_)
, nodes_ (size_ == 0 ? 0 : new value_type[size_])
{
std::copy (map.begin (),
map.end (),
ACE_make_checked_array_iterator (this->begin (),
this->size_));
// iterator f = map.begin ();
// iterator l = map.end ();
// iterator n = this->begin ();
// for (iterator i = f; i != l; ++i, ++n)
// *n = *i;
}
template<typename Key, typename Value, class EqualTo>
ACE_Array_Map<Key, Value, EqualTo>::~ACE_Array_Map (void)
{
delete[] this->nodes_;
}
template<typename Key, typename Value, class EqualTo>
void
ACE_Array_Map<Key, Value, EqualTo>::swap (
ACE_Array_Map<Key, Value, EqualTo> & map)
{
std::swap (this->size_, map.size_);
std::swap (this->capacity_, map.capacity_);
std::swap (this->nodes_, map.nodes_);
}
template<typename Key, typename Value, class EqualTo>
std::pair<typename ACE_Array_Map<Key, Value, EqualTo>::iterator, bool>
ACE_Array_Map<Key, Value, EqualTo>::insert (
typename ACE_Array_Map<Key, Value, EqualTo>::value_type const & x)
{
// Linear insertion due to linear duplicate key search.
bool inserted = false;
iterator i = this->find (x.first);
if (i == this->end ())
{
// Add the element to the array.
size_type const old_size = this->size ();
this->grow (1); // Increase size by at least one.
i = this->begin () + old_size;
*i = x;
++this->size_;
inserted = true;
}
return std::make_pair (i, inserted);
}
template<typename Key, typename Value, class EqualTo>
template<typename InputIterator>
void
ACE_Array_Map<Key, Value, EqualTo>::insert (InputIterator f, InputIterator l)
{
this->grow (l - f); // Preallocate storage.
for (InputIterator i = f; i != l; ++i)
{
(void) this->insert (*i);
}
}
template<typename Key, typename Value, class EqualTo>
void
ACE_Array_Map<Key, Value, EqualTo>::erase (
typename ACE_Array_Map<Key, Value, EqualTo>::iterator pos)
{
iterator const first = this->begin ();
iterator const last = this->end ();
if (pos >= first && pos < last)
{
if (pos != last - 1)
{
// Relocate the tail element to the location of the erased
// element to prevent introduction of "holes" in the
// underlying array.
*pos = *(last - 1);
}
// Explicitly destroy the tail element by assigning a default
// constructed instance to it. Note that this also works for
// the case of a map of size 1.
*(last - 1) = value_type ();
--this->size_;
}
}
template<typename Key, typename Value, class EqualTo>
typename ACE_Array_Map<Key, Value, EqualTo>::size_type
ACE_Array_Map<Key, Value, EqualTo>::erase (
typename ACE_Array_Map<Key, Value, EqualTo>::key_type const & k)
{
iterator pos = this->find (k);
size_type const old_size = this->size_;
this->erase (pos);
return old_size - this->size_;
}
template<typename Key, typename Value, class EqualTo>
void
ACE_Array_Map<Key, Value, EqualTo>::erase (
typename ACE_Array_Map<Key, Value, EqualTo>::iterator first,
typename ACE_Array_Map<Key, Value, EqualTo>::iterator last)
{
if (this->begin () <= first && first < last && last < this->end ())
for (iterator i = first; i != last; ++i)
this->erase (i);
}
template<typename Key, typename Value, class EqualTo>
void
ACE_Array_Map<Key, Value, EqualTo>::clear (void)
{
this->size_ = 0; // No need to deallocate array nor destroy elements.
}
template<typename Key, typename Value, class EqualTo>
typename ACE_Array_Map<Key, Value, EqualTo>::iterator
ACE_Array_Map<Key, Value, EqualTo>::find (
typename ACE_Array_Map<Key, Value, EqualTo>::key_type const & k)
{
iterator const the_end = this->end ();
EqualTo eq;
for (iterator i = this->begin (); i != the_end; ++i)
if (eq (k, i->first))
return i;
return this->end ();
}
template<typename Key, typename Value, class EqualTo>
typename ACE_Array_Map<Key, Value, EqualTo>::const_iterator
ACE_Array_Map<Key, Value, EqualTo>::find (
typename ACE_Array_Map<Key, Value, EqualTo>::key_type const & k) const
{
const_iterator const the_end = this->end ();
EqualTo eq;
for (const_iterator i = this->begin (); i != the_end; ++i)
if (eq (k, i->first))
return i;
return this->end ();
}
template<typename Key, typename Value, class EqualTo>
void
ACE_Array_Map<Key, Value, EqualTo>::grow (
typename ACE_Array_Map<Key, Value, EqualTo>::size_type s)
{
if (this->size () + s > this->capacity_)
{
// This implementation focuses more on static footprint than
// speed.
// Strongly exception safe.
ACE_Array_Map<Key, Value, EqualTo> temp (this->size () + s);
std::copy (this->begin (),
this->end (),
ACE_make_checked_array_iterator (temp.begin (),
temp.capacity_));
size_type const n = this->size (); // Do not swap out the size
// since we bypassed the
// temporary map's element
// counting code.
this->swap (temp);
this->size_ = n;
}
}
// ---------------------------------------------------------------
template <typename Key, typename Value, class EqualTo>
bool
operator== (ACE_Array_Map<Key, Value, EqualTo> const & lhs,
ACE_Array_Map<Key, Value, EqualTo> const & rhs)
{
// Do not include Array_Map capacity in comparison. It isn't useful
// in this case.
return (lhs.size () == rhs.size ()
&& std::equal (lhs.begin (),
lhs.end (),
ACE_make_checked_array_iterator (rhs.begin (),
rhs.size ())));
}
template <typename Key, typename Value, class EqualTo>
bool
operator< (ACE_Array_Map<Key, Value, EqualTo> const & lhs,
ACE_Array_Map<Key, Value, EqualTo> const & rhs)
{
return std::lexicographical_compare (lhs.begin (), lhs.end (),
rhs.begin (), rhs.end ());
}
ACE_END_VERSIONED_NAMESPACE_DECL
#endif /* ACE_ARRAY_MAP_CPP */
|