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/typetraits.hh>
9 #include <dune/common/iteratorfacades.hh>
10 #include <dune/common/typetraits.hh>
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 >
72 template<
typename T >
82 _vectors(v), pos(pos), name(_n) {}
84 _vectors(other._vectors), pos(other.pos), name(other.name) {}
86 _vectors(other._vectors), pos(other.pos), name(other.name) {}
104 typename TypeTraits<typename tuple_element<N,T>::type>::ReferredType::reference
109 typename TypeTraits<typename tuple_element<N,T>::type>::ReferredType::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 >
127 std::ostream& operator<< (std::ostream & s, const MultiDataProxy<T> & i)
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
174 #ifdef DEBUG_MULTIVEC
179 return other.
data.pos == data.
pos;
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);
266 void erase(iterator front, iterator back)
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);
299 #endif // DUNE_GRIDGLUE_COMMON_MULTIVECTOR_HH
Definition: multivector.hh:207
MultiDataProxy(T &v, size_t pos, std::string _n)
Definition: multivector.hh:81
MultiDataProxy< T > & dereference() const
Definition: multivector.hh:197
bool operator>(const MultiDataProxy &other) const
Definition: multivector.hh:91
MultiVectorIterator< T > iterator
Definition: multivector.hh:244
std::string name
Definition: multivector.hh:80
MultiDataProxy(MutableProxy &other)
Definition: multivector.hh:85
T & _vectors
Definition: multivector.hh:77
iterator end()
Definition: multivector.hh:260
bool operator<(const MultiDataProxy &other) const
Definition: multivector.hh:90
Definition: gridglue.hh:34
size_t size() const
Definition: multivector.hh:274
bool operator==(const MultiDataProxy &other) const
Definition: multivector.hh:88
bool equals(const MultiVectorIterator &other) const
Definition: multivector.hh:172
MultiDataProxy< const typename remove_const< T >::type > ConstProxy
Definition: multivector.hh:76
reference * pointer
Pointer to a small block of bits.
Definition: multivector.hh:232
Definition: multivector.hh:70
const_reference * const_pointer
Const pointer to a small block of bits.
Definition: multivector.hh:235
void increment()
Definition: multivector.hh:182
size_t pos() const
Definition: multivector.hh:158
size_t size_type
size type
Definition: multivector.hh:238
int pos
Definition: multivector.hh:79
MultiVector(A &a, B &b, C &c, D &d, std::string n="?")
Definition: multivector.hh:248
value_type reference
Reference to a small block of bits.
Definition: multivector.hh:226
MultiDataProxy< typename remove_const< T >::type > MutableProxy
Definition: multivector.hh:75
void decrement()
Definition: multivector.hh:189
Definition: multivector.hh:138
MultiVectorIterator(const MultiVectorIterator &other)
Definition: multivector.hh:150
MultiDataProxy< T > value_type
Type of the values stored by the container.
Definition: multivector.hh:220
MultiVectorIterator(T &v, size_t n, std::string i)
Definition: multivector.hh:148
MultiVectorIterator< const T > const_iterator
Definition: multivector.hh:245
MultiVectorIterator operator=(const MultiVectorIterator &other)
Definition: multivector.hh:160
void erase(iterator front, iterator back)
Definition: multivector.hh:266
iterator begin()
Definition: multivector.hh:255
MultiDataProxy(ConstProxy &other)
Definition: multivector.hh:83
MultiDataProxy< T > const_value_type
Type of the const values stored by the container.
Definition: multivector.hh:223
MultiDataProxy< T > data
Definition: multivector.hh:145
const_value_type const_reference
Const reference to a small block of bits.
Definition: multivector.hh:229
bool operator!=(const MultiDataProxy &other) const
Definition: multivector.hh:89
TypeTraits< typename tuple_element< N, T >::type >::ReferredType::reference get()
Definition: multivector.hh:105
MultiDataProxy & operator=(const ConstProxy &other)
Definition: multivector.hh:93