/usr/include/dune/grid-glue/common/multivector.hh is in libdune-grid-glue-dev 2.4.0-1build1.
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 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_GRIDGLUE_COMMON_MULTIVECTOR_HH
#define DUNE_GRIDGLUE_COMMON_MULTIVECTOR_HH
#include <dune/common/tuples.hh>
#include <dune/common/tupleutility.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/iteratorfacades.hh>
#include <dune/common/typetraits.hh>
#include <vector>
#include <iostream>
#include <cassert>
namespace Dune {
#ifndef DOXYGEN
// TMPs for the MultiVector tuples stuff
namespace {
struct MultiVectorAssertSize
{
size_t sz_;
MultiVectorAssertSize(size_t sz) : sz_(sz) {}
template <class E>
void visit(E& elem) { assert(elem.size() == sz_); }
};
struct MultiVectorEraser
{
size_t front, back;
MultiVectorEraser(size_t f, size_t b) : front(f), back(b) {}
template <class E>
void visit(E& elem)
{
elem.erase( elem.begin()+front, elem.begin()+back );
}
};
struct MultiVectorPrinter
{
std::ostream & s;
size_t pos;
std::string del;
MultiVectorPrinter(std::ostream & _s, size_t p) : s(_s), pos(p), del("") {}
template <class E>
void visit(E& elem)
{
s << del << elem[pos];
del = ", ";
}
};
struct MultiVectorAssign
{
size_t pos1, pos2;
MultiVectorAssign(size_t p1, size_t p2) : pos1(p1), pos2(p2) {}
template <class E1, class E2>
void visit(E1& elem1, E2& elem2)
{
elem1[pos1] = elem2[pos2];
}
};
} // end empty namespace
#endif
/**
proxy object to give access
@tparam T the tuple< vector<...> > type
*/
template< typename T >
struct MultiDataProxy;
template< typename T >
struct MultiDataProxy
{
typedef MultiDataProxy<typename remove_const<T>::type> MutableProxy;
typedef MultiDataProxy<const typename remove_const<T>::type> ConstProxy;
T & _vectors;
int pos;
std::string name;
MultiDataProxy(T & v, size_t pos, std::string _n) :
_vectors(v), pos(pos), name(_n) {}
MultiDataProxy(ConstProxy & other) :
_vectors(other._vectors), pos(other.pos), name(other.name) {}
MultiDataProxy(MutableProxy & other) :
_vectors(other._vectors), pos(other.pos), name(other.name) {}
// compare
bool operator == (const MultiDataProxy & other) const { return get<0>() == other.get<0>(); }
bool operator != (const MultiDataProxy & other) const { return get<0>() != other.get<0>(); }
bool operator < (const MultiDataProxy & other) const { return get<0>() < other.get<0>(); }
bool operator > (const MultiDataProxy & other) const { return get<0>() > other.get<0>(); }
// assign
MultiDataProxy& operator = (const ConstProxy & other) {
assign(other);
return *this;
}
MultiDataProxy& operator = (const MutableProxy & other) {
assign(other);
return *this;
}
// access
template <size_t N>
typename TypeTraits<typename tuple_element<N,T>::type>::ReferredType::reference
get() {
return Dune::get<N>(_vectors)[pos];
}
template <size_t N>
typename TypeTraits<typename tuple_element<N,T>::type>::ReferredType::const_reference
get() const {
return Dune::get<N>(_vectors)[pos];
}
private:
template<typename P>
void assign(const P & other) {
#ifdef DEBUG_MULTIVEC
std::cerr << "Assign " << name << "," << pos
<< "\n from " << other.name << "," << other.pos << std::endl;
#endif
MultiVectorAssign assign(pos, other.pos);
ForEachValuePair<T,const T> forEach(_vectors, other._vectors);
forEach.apply(assign);
}
};
template< typename T >
std::ostream& operator<< (std::ostream & s, const MultiDataProxy<T> & i)
{
s << "(";
MultiVectorPrinter printer(s, i.pos);
ForEachValue<T> forEach(i._vectors);
forEach.apply(printer);
s << ")";
return s;
}
template< typename T >
class MultiVectorIterator :
public Dune::BidirectionalIteratorFacade< MultiVectorIterator<T>,
MultiDataProxy<T> >
{
// friend class MultiVectorIterator<typename remove_const<C>::type, typename remove_const<T>::type >;
// friend class TestIterator<const typename remove_const<C>::type, const typename remove_const<T>::type >;
public:
mutable MultiDataProxy<T> data;
// constructors
MultiVectorIterator(T & v, size_t n, std::string i) :
data(v,n,i) {}
MultiVectorIterator(const MultiVectorIterator & other) :
data(other.data)
{
#ifdef DEBUG_MULTIVEC
std::cerr << "Copy Iterator " << data.name << "," << data.pos << std::endl;
#endif
}
size_t pos() const { return data.pos; }
MultiVectorIterator operator = (const MultiVectorIterator & other)
{
#ifdef DEBUG_MULTIVEC
// std::cerr << "Assign Iterator " << data.name << "," << data.pos
// << "\n from " << other.data.name << "," << other.data.pos << std::endl;
#endif
assert(other.data._vectors == data._vectors);
data.pos = other.data.pos;
return *this;
}
// operators
bool equals (const MultiVectorIterator & other) const
{
#ifdef DEBUG_MULTIVEC
// std::cerr << "Compare " << data.name << "," << data.pos
// << " with " << other.data.name << "," << other.data.pos << "\n";
#endif
assert(other.data._vectors == data._vectors);
return other.data.pos == data.pos;
}
// in-/decrement
void increment()
{
#ifdef DEBUG_MULTIVEC
// std::cerr << "Increment " << data.name << "," << data.pos << std::endl;
#endif
data.pos++;
}
void decrement()
{
#ifdef DEBUG_MULTIVEC
std::cerr << "Decrement " << data.name << "," << data.pos << std::endl;
#endif
data.pos--;
}
// dereference
MultiDataProxy<T>& dereference() const
{
#ifdef DEBUG_MULTIVEC
std::cerr << "dereference " << data.name << "," << data.pos << std::endl;
#endif
return data;
}
};
template<typename A, typename B, typename C, typename D>
class MultiVector
{
typedef MultiVector<A,B,C,D> vector_type;
typedef tuple<A&, B&, C&, D&> T;
T _vectors;
std::string _name;
public:
//! container interface typedefs
//! \{
/** \brief Type of the values stored by the container */
typedef MultiDataProxy<T> value_type;
/** \brief Type of the const values stored by the container */
typedef MultiDataProxy<T> const_value_type;
/** \brief Reference to a small block of bits */
typedef value_type reference;
/** \brief Const reference to a small block of bits */
typedef const_value_type const_reference;
/** \brief Pointer to a small block of bits */
typedef reference* pointer;
/** \brief Const pointer to a small block of bits */
typedef const_reference* const_pointer;
/** \brief size type */
typedef size_t size_type;
//! \}
//! iterators
//! \{
typedef MultiVectorIterator<T> iterator;
typedef MultiVectorIterator<const T> const_iterator;
//! \}
MultiVector(A & a, B & b, C & c, D & d, std::string n = "?") :
_vectors(tie(a,b,c,d))
{
assertSize();
_name = n;
}
iterator begin()
{
return iterator(_vectors, 0, _name);
}
iterator end()
{
assertSize();
return iterator(_vectors, get<0>().size(), _name);
}
void erase(iterator front, iterator back)
{
assertSize();
MultiVectorEraser erase(front.pos(), back.pos());
ForEachValue<T> forEach(_vectors);
forEach.apply(erase);
}
size_t size() const {
assertSize();
return get<0>().size();
}
template <size_t N>
typename tuple_element<N,T>::type &
get() {
return Dune::get<N>(_vectors);
}
template <size_t N>
typename tuple_element<N,T>::type
get() const {
return Dune::get<N>(_vectors);
}
private:
void assertSize() const {
MultiVectorAssertSize check(get<0>().size());
ForEachValue<const T> forEach(_vectors);
forEach.apply(check);
}
};
} // end namespace Dune
#endif // DUNE_GRIDGLUE_COMMON_MULTIVECTOR_HH
|