dune-grid  2.4.1
persistentcontainervector.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
4 #define DUNE_PERSISTENTCONTAINERVECTOR_HH
5 
6 #include <algorithm>
7 #include <cassert>
8 
9 namespace Dune
10 {
11 
12  // PersistentContainerVector
13  // -------------------------
14 
47  template< class G, class IndexSet, class Vector >
49  {
51 
52  public:
53  typedef G Grid;
54 
55  typedef typename Vector::value_type Value;
56  typedef typename Vector::size_type Size;
57  typedef typename Vector::const_iterator ConstIterator;
58  typedef typename Vector::iterator Iterator;
59 
60  typedef typename Vector::allocator_type Allocator;
61 
62  PersistentContainerVector ( const IndexSet &indexSet, int codim, const Value &value,
63  const Allocator &allocator = Allocator() )
64  : codim_( codim ),
65  indexSet_( &indexSet ),
66  data_( indexSet.size( codim ), value, allocator )
67  {}
68 
69  template< class Entity >
70  const Value &operator[] ( const Entity &entity ) const
71  {
72  assert( Entity::codimension == codimension() );
73  const Size index = indexSet().index( entity );
74  assert( index < data_.size() );
75  return data_[ index ];
76  }
77 
78  template< class Entity >
79  Value &operator[] ( const Entity &entity )
80  {
81  assert( Entity::codimension == codimension() );
82  const Size index = indexSet().index( entity );
83  assert( index < data_.size() );
84  return data_[ index ];
85  }
86 
87  template< class Entity >
88  const Value &operator() ( const Entity &entity, int subEntity ) const
89  {
90  const Size index = indexSet().subIndex( entity, subEntity, codimension() );
91  assert( index < data_.size() );
92  return data_[ index ];
93  }
94 
95  template< class Entity >
96  Value &operator() ( const Entity &entity, int subEntity )
97  {
98  const Size index = indexSet().subIndex( entity, subEntity, codimension() );
99  assert( index < data_.size() );
100  return data_[ index ];
101  }
102 
103  Size size () const { return data_.size(); }
104 
105  void resize ( const Value &value = Value() )
106  {
107  const Size indexSetSize = indexSet().size( codimension() );
108  data_.resize( indexSetSize, value );
109  }
110 
111  void shrinkToFit () {}
112 
113  void fill ( const Value &value ) { std::fill( begin(), end(), value ); }
114 
115  void swap ( This &other )
116  {
117  std::swap( codim_, other.codim_ );
118  std::swap( indexSet_, other.indexSet_ );
119  std::swap( data_, other.data_ );
120  }
121 
122  ConstIterator begin () const { return data_.begin(); }
123  Iterator begin () { return data_.begin(); }
124 
125  ConstIterator end () const { return data_.end(); }
126  Iterator end () { return data_.end(); }
127 
128  int codimension () const { return codim_; }
129 
130  protected:
131  const IndexSet &indexSet () const { return *indexSet_; }
132 
133  int codim_;
135  Vector data_;
136  };
137 
138 } // namespace Dune
139 
140 #endif // #ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
ConstIterator begin() const
Definition: persistentcontainervector.hh:122
G Grid
Definition: persistentcontainervector.hh:53
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainervector.hh:88
PersistentContainerVector(const IndexSet &indexSet, int codim, const Value &value, const Allocator &allocator=Allocator())
Definition: persistentcontainervector.hh:62
const IndexSet * indexSet_
Definition: persistentcontainervector.hh:134
Wrapper class for entities.
Definition: common/entity.hh:61
Vector::size_type Size
Definition: persistentcontainervector.hh:56
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:115
const Value & operator[](const Entity &entity) const
Definition: persistentcontainervector.hh:70
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:153
Vector::iterator Iterator
Definition: persistentcontainervector.hh:58
int codimension() const
Definition: persistentcontainervector.hh:128
const IndexSet & indexSet() const
Definition: persistentcontainervector.hh:131
Vector::value_type Value
Definition: persistentcontainervector.hh:55
Vector data_
Definition: persistentcontainervector.hh:135
void fill(const Value &value)
Definition: persistentcontainervector.hh:113
Index Set Interface base class.
Definition: common/grid.hh:361
ConstIterator end() const
Definition: persistentcontainervector.hh:125
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:48
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:232
void resize(const Value &value=Value())
Definition: persistentcontainervector.hh:105
Vector::allocator_type Allocator
Definition: persistentcontainervector.hh:60
Vector::const_iterator ConstIterator
Definition: persistentcontainervector.hh:57
Include standard header files.
Definition: agrid.hh:59
int codim_
Definition: persistentcontainervector.hh:133
Know your own codimension.
Definition: common/entity.hh:104
void swap(This &other)
Definition: persistentcontainervector.hh:115
Size size() const
Definition: persistentcontainervector.hh:103
Iterator end()
Definition: persistentcontainervector.hh:126
Iterator begin()
Definition: persistentcontainervector.hh:123
void shrinkToFit()
Definition: persistentcontainervector.hh:111