/usr/include/dune/pdelab/backend/istl/vectoriterator.hh is in libdune-pdelab-dev 2.5.0~20170124g7cf9f47a-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 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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=8 sw=2 sts=2:
#ifndef DUNE_PDELAB_BACKEND_ISTL_VECTORITERATOR_HH
#define DUNE_PDELAB_BACKEND_ISTL_VECTORITERATOR_HH
// this is here for backwards compatibility and deprecation warnings, remove after 2.5.0
#include "ensureistlinclude.hh"
#include <iterator>
#include <cassert>
#include <tuple>
#include <dune/pdelab/backend/istl/tags.hh>
namespace Dune {
namespace PDELab {
namespace ISTL {
namespace impl {
template<typename T, bool is_const, typename Tag, typename... Iterators>
struct _extract_iterators;
template<typename T, typename... Iterators>
struct _extract_iterators<T,true,tags::block_vector,Iterators...>
: public _extract_iterators<typename T::block_type,
true,
typename tags::container<typename T::block_type>::type::base_tag,
Iterators..., typename T::const_iterator
>
{};
template<typename T, typename... Iterators>
struct _extract_iterators<T,false,tags::block_vector,Iterators...>
: public _extract_iterators<typename T::block_type,
false,
typename tags::container<typename T::block_type>::type::base_tag,
Iterators..., typename T::iterator
>
{};
template<typename T, typename... Iterators>
struct _extract_iterators<T,true,tags::field_vector,Iterators...>
{
typedef std::tuple<Iterators...,typename T::const_iterator> type;
};
template<typename T, typename... Iterators>
struct _extract_iterators<T,false,tags::field_vector,Iterators...>
{
typedef std::tuple<Iterators...,typename T::iterator> type;
};
template<typename T, typename... Iterators>
struct _extract_iterators<T,true,tags::dynamic_vector,Iterators...>
{
typedef std::tuple<Iterators...,typename T::const_iterator> type;
};
template<typename T, typename... Iterators>
struct _extract_iterators<T,false,tags::dynamic_vector,Iterators...>
{
typedef std::tuple<Iterators...,typename T::iterator> type;
};
template<typename V>
struct extract_iterators
: public _extract_iterators<V,false,typename tags::container<V>::type::base_tag>
{};
template<typename V>
struct extract_iterators<const V>
: public _extract_iterators<V,true,typename tags::container<V>::type::base_tag>
{};
template<typename V>
struct vector_iterator_base
: public std::iterator<std::forward_iterator_tag,
typename V::field_type,
typename std::ptrdiff_t,
typename V::field_type*,
typename V::field_type&
>
{
typedef V vector;
typedef V& vector_reference;
typedef typename tags::container<V>::type::base_tag vector_tag;
static const bool is_const = false;
};
template<typename V>
struct vector_iterator_base<const V>
: public std::iterator<std::forward_iterator_tag,
typename V::field_type,
typename std::ptrdiff_t,
const typename V::field_type*,
const typename V::field_type&
>
{
typedef V vector;
typedef const V& vector_reference;
typedef typename tags::container<V>::type::base_tag vector_tag;
static const bool is_const = true;
};
}
template<typename V>
class vector_iterator
: public impl::vector_iterator_base<V>
{
typedef impl::vector_iterator_base<V> BaseT;
typedef typename BaseT::vector vector;
typedef typename BaseT::vector_reference vector_reference;
typedef typename BaseT::vector_tag vector_tag;
typedef typename impl::extract_iterators<V>::type Iterators;
static const bool is_const = BaseT::is_const;
template<typename>
friend class vector_iterator;
public:
vector_iterator(vector_reference vector, bool at_end)
: _at_end(at_end)
, _current(nullptr)
{
if (!_at_end)
if (!start(vector_tag(),level<0>(),vector))
_at_end = true;
}
// Copy constructor from iterator to const_iterator
// We disable this one if the two types are identical to avoid hiding
// the default copy constructor
template<typename W>
vector_iterator(const vector_iterator<W>& r, typename std::enable_if<is_const && !std::is_same<V,W>::value && std::is_same<vector,W>::value,void*>::type = nullptr)
: _at_end(r._at_end)
, _current(r._current)
, _iterators(r._iterators)
, _end(r._end)
{}
// Assignment operator from iterator to const_iterator
// We disable this one if the two types are identical to avoid hiding
// the default assignment operator
template<typename W>
typename std::enable_if<
is_const && !std::is_same<vector,W>::value && std::is_same<vector,W>::value,
vector_iterator&
>::type
operator=(const vector_iterator<W>& r)
{
_at_end = r._at_end;
_current =r._current;
_iterators = r._iterators;
_end = r._end;
return *this;
}
typename BaseT::pointer operator->() const
{
assert(!_at_end);
return _current;
}
typename BaseT::reference operator*() const
{
assert(!_at_end);
return *_current;
}
vector_iterator& operator++()
{
increment();
return *this;
}
vector_iterator operator++(int)
{
vector_iterator tmp(*this);
increment();
return tmp;
}
template<typename W>
typename std::enable_if<
std::is_same<vector,typename vector_iterator<W>::vector>::value,
bool
>::type
operator==(const vector_iterator<W>& r) const
{
if (!_at_end)
{
if (r._at_end)
return false;
return _current == r._current;
}
else
return r._at_end;
}
template<typename W>
typename std::enable_if<
std::is_same<vector,typename vector_iterator<W>::vector>::value,
bool
>::type
operator!=(const vector_iterator<W>& r) const
{
return !operator==(r);
}
private:
template<std::size_t l>
struct level
: public std::integral_constant<std::size_t,l>
{};
void increment()
{
assert(!_at_end);
if (!advance(vector_tag(),level<0>()))
_at_end = true;
}
template<std::size_t l, typename Block>
bool start_leaf(level<l>, Block& block)
{
typedef typename std::tuple_element<l,Iterators>::type iterator;
iterator& it = std::get<l>(_iterators);
iterator& end = std::get<l>(_end);
it = block.begin();
end = block.end();
if (it == end)
return false;
_current = &(*it);
return true;
}
template<std::size_t l, typename Block>
bool start(tags::field_vector_n, level<l>, Block& block)
{
return start_leaf(level<l>(),block);
}
template<std::size_t l, typename Block>
bool start(tags::dynamic_vector, level<l>, Block& block)
{
return start_leaf(level<l>(),block);
}
template<std::size_t l, typename Block>
bool start(tags::field_vector_1, level<l>, Block& block)
{
_current = &(block[0]);
return true;
}
template<std::size_t l, typename Block>
bool start(tags::block_vector, level<l>, Block& block)
{
typedef typename std::tuple_element<l,Iterators>::type iterator;
iterator& it = std::get<l>(_iterators);
iterator& end = std::get<l>(_end);
it = block.begin();
end = block.end();
while (it != end)
{
if (start(container_tag(*it),level<l+1>(),*it))
return true;
++it;
}
return false;
}
template<std::size_t l>
bool advance_leaf(level<l>)
{
typedef typename std::tuple_element<l,Iterators>::type iterator;
iterator& it = std::get<l>(_iterators);
const iterator& end = std::get<l>(_end);
++it;
if (it == end)
return false;
_current = &(*it);
return true;
}
template<std::size_t l>
bool advance(tags::field_vector_n, level<l>)
{
return advance_leaf(level<l>());
}
template<std::size_t l>
bool advance(tags::dynamic_vector, level<l>)
{
return advance_leaf(level<l>());
}
template<std::size_t l>
bool advance(tags::field_vector_1, level<l>)
{
return false;
}
template<std::size_t l>
bool advance(tags::block_vector, level<l>)
{
typedef typename std::tuple_element<l,Iterators>::type iterator;
iterator& it = std::get<l>(_iterators);
iterator& end = std::get<l>(_end);
if (advance(container_tag(*it),level<l+1>()))
return true;
++it;
while (it != end)
{
if (start(container_tag(*it),level<l+1>(),*it))
return true;
++it;
}
return false;
}
bool _at_end;
typename BaseT::pointer _current;
Iterators _iterators;
Iterators _end;
};
} // namespace ISTL
} // namespace PDELab
} // namespace Dune
#endif // DUNE_PDELAB_BACKEND_ISTL_VECTORITERATOR_HH
|