3 #ifndef DUNE_GRIDGLUE_COMMON_MULTIVECTOR_HH
4 #define DUNE_GRIDGLUE_COMMON_MULTIVECTOR_HH
6 #include <dune/common/tuples.hh>
7 #include <dune/common/tupleutility.hh>
8 #include <dune/common/iteratorfacades.hh>
9 #include <dune/common/typetraits.hh>
14 #include <type_traits>
21 struct MultiVectorAssertSize
24 MultiVectorAssertSize(
size_t sz) : sz_(sz) {}
26 void visit(E& elem) { assert(elem.size() == sz_); }
28 struct MultiVectorEraser
31 MultiVectorEraser(
size_t f,
size_t b) : front(f), back(b) {}
35 elem.erase( elem.begin()+front, elem.begin()+back );
38 struct MultiVectorPrinter
43 MultiVectorPrinter(std::ostream & _s,
size_t p) : s(_s), pos(p), del(
"") {}
47 s << del << elem[pos];
51 struct MultiVectorAssign
54 MultiVectorAssign(
size_t p1,
size_t p2) : pos1(p1), pos2(p2) {}
55 template <
class E1,
class E2>
56 void visit(E1& elem1, E2& elem2)
58 elem1[pos1] = elem2[pos2];
69 template<
typename T >
70 struct MultiDataProxy;
72 template<
typename T >
104 typename std::remove_reference<typename tuple_element<N,T>::type>::type::reference
109 typename std::remove_reference<typename tuple_element<N,T>::type>::type::const_reference
115 void assign(
const P & other) {
116 #ifdef DEBUG_MULTIVEC
117 std::cerr <<
"Assign " <<
name <<
"," <<
pos
118 <<
"\n from " << other.name <<
"," << other.pos << std::endl;
120 MultiVectorAssign assign(
pos, other.pos);
121 ForEachValuePair<T,const T> forEach(
_vectors, other._vectors);
122 forEach.apply(assign);
126 template<
typename T >
130 MultiVectorPrinter printer(s, i.
pos);
131 ForEachValue<T> forEach(i.
_vectors);
132 forEach.apply(printer);
137 template<
typename T >
139 public Dune::BidirectionalIteratorFacade< MultiVectorIterator<T>,
153 #ifdef DEBUG_MULTIVEC
154 std::cerr <<
"Copy Iterator " <<
data.name <<
"," <<
data.pos << std::endl;
162 #ifdef DEBUG_MULTIVEC
166 assert(other.
data._vectors ==
data._vectors);
174 #ifdef DEBUG_MULTIVEC
178 assert(other.
data._vectors ==
data._vectors);
184 #ifdef DEBUG_MULTIVEC
191 #ifdef DEBUG_MULTIVEC
192 std::cerr <<
"Decrement " <<
data.name <<
"," <<
data.pos << std::endl;
199 #ifdef DEBUG_MULTIVEC
200 std::cerr <<
"dereference " <<
data.name <<
"," <<
data.pos << std::endl;
206 template<
typename A,
typename B,
typename C,
typename D>
211 typedef tuple<A&, B&, C&, D&> T;
249 _vectors(tie(a,b,c,d))
257 return iterator(_vectors, 0, _name);
271 ForEachValue<T> forEach(_vectors);
272 forEach.apply(
erase);
276 return get<0>().size();
280 typename tuple_element<N,T>::type &
282 return Dune::get<N>(_vectors);
285 typename tuple_element<N,T>::type
287 return Dune::get<N>(_vectors);
290 void assertSize()
const {
291 MultiVectorAssertSize check(get<0>().
size());
292 ForEachValue<const T> forEach(_vectors);
293 forEach.apply(check);
Definition: gridglue.hh:30
std::ostream & operator<<(std::ostream &s, const MultiDataProxy< T > &i)
Definition: multivector.hh:127
Definition: multivector.hh:74
int pos
Definition: multivector.hh:79
MultiDataProxy(T &v, size_t pos, std::string _n)
Definition: multivector.hh:81
MultiDataProxy & operator=(const ConstProxy &other)
Definition: multivector.hh:93
std::string name
Definition: multivector.hh:80
std::remove_reference< typename tuple_element< N, T >::type >::type::const_reference get() const
Definition: multivector.hh:110
MultiDataProxy(ConstProxy &other)
Definition: multivector.hh:83
bool operator!=(const MultiDataProxy &other) const
Definition: multivector.hh:89
MultiDataProxy< const typename std::remove_const< T >::type > ConstProxy
Definition: multivector.hh:76
bool operator==(const MultiDataProxy &other) const
Definition: multivector.hh:88
MultiDataProxy(MutableProxy &other)
Definition: multivector.hh:85
T & _vectors
Definition: multivector.hh:77
std::remove_reference< typename tuple_element< N, T >::type >::type::reference get()
Definition: multivector.hh:105
bool operator<(const MultiDataProxy &other) const
Definition: multivector.hh:90
MultiDataProxy< typename std::remove_const< T >::type > MutableProxy
Definition: multivector.hh:75
bool operator>(const MultiDataProxy &other) const
Definition: multivector.hh:91
Definition: multivector.hh:141
MultiVectorIterator(T &v, size_t n, std::string i)
Definition: multivector.hh:148
MultiDataProxy< T > data
Definition: multivector.hh:145
MultiVectorIterator operator=(const MultiVectorIterator &other)
Definition: multivector.hh:160
MultiVectorIterator(const MultiVectorIterator &other)
Definition: multivector.hh:150
MultiDataProxy< T > & dereference() const
Definition: multivector.hh:197
void increment()
Definition: multivector.hh:182
size_t pos() const
Definition: multivector.hh:158
void decrement()
Definition: multivector.hh:189
bool equals(const MultiVectorIterator &other) const
Definition: multivector.hh:172
Definition: multivector.hh:208
MultiDataProxy< T > const_value_type
Type of the const values stored by the container.
Definition: multivector.hh:223
size_t size_type
size type
Definition: multivector.hh:238
value_type reference
Reference to a small block of bits.
Definition: multivector.hh:226
iterator begin()
Definition: multivector.hh:255
reference * pointer
Pointer to a small block of bits.
Definition: multivector.hh:232
tuple_element< N, T >::type get() const
Definition: multivector.hh:286
iterator end()
Definition: multivector.hh:260
MultiVectorIterator< T > iterator
Definition: multivector.hh:244
const_value_type const_reference
Const reference to a small block of bits.
Definition: multivector.hh:229
tuple_element< N, T >::type & get()
Definition: multivector.hh:281
size_t size() const
Definition: multivector.hh:274
MultiVectorIterator< const T > const_iterator
Definition: multivector.hh:245
MultiVector(A &a, B &b, C &c, D &d, std::string n="?")
Definition: multivector.hh:248
const_reference * const_pointer
Const pointer to a small block of bits.
Definition: multivector.hh:235
MultiDataProxy< T > value_type
Type of the values stored by the container.
Definition: multivector.hh:220
void erase(iterator front, iterator back)
Definition: multivector.hh:266