dune-grid  2.3.1-rc1
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 
16  template< class G, class IndexSet, class Vector >
18  {
20 
21  public:
22  typedef G Grid;
23 
24  typedef typename Vector::value_type Value;
25  typedef typename Vector::size_type Size;
26  typedef typename Vector::const_iterator ConstIterator;
27  typedef typename Vector::iterator Iterator;
28 
29  typedef typename Vector::allocator_type Allocator;
30 
31  PersistentContainerVector ( const IndexSet &indexSet, int codim, const Value &value,
32  const Allocator &allocator = Allocator() )
33  : codim_( codim ),
34  indexSet_( &indexSet ),
35  data_( indexSet.size( codim ), value, allocator )
36  {}
37 
38  template< class Entity >
39  const Value &operator[] ( const Entity &entity ) const
40  {
41  assert( Entity::codimension == codimension() );
42  const Size index = indexSet().index( entity );
43  assert( index < data_.size() );
44  return data_[ index ];
45  }
46 
47  template< class Entity >
48  Value &operator[] ( const Entity &entity )
49  {
50  assert( Entity::codimension == codimension() );
51  const Size index = indexSet().index( entity );
52  assert( index < data_.size() );
53  return data_[ index ];
54  }
55 
56  template< class Entity >
57  const Value &operator() ( const Entity &entity, int subEntity ) const
58  {
59  const Size index = indexSet().subIndex( entity, subEntity, codimension() );
60  assert( index < data_.size() );
61  return data_[ index ];
62  }
63 
64  template< class Entity >
65  Value &operator() ( const Entity &entity, int subEntity )
66  {
67  const Size index = indexSet().subIndex( entity, subEntity, codimension() );
68  assert( index < data_.size() );
69  return data_[ index ];
70  }
71 
72  Size size () const { return data_.size(); }
73 
74  void resize ( const Value &value = Value() )
75  {
76  const Size indexSetSize = indexSet().size( codimension() );
77  data_.resize( indexSetSize, value );
78  }
79 
80  void shrinkToFit () {}
81 
82  void fill ( const Value &value ) { std::fill( begin(), end(), value ); }
83 
84  void swap ( This &other )
85  {
86  std::swap( codim_, other.codim_ );
87  std::swap( indexSet_, other.indexSet_ );
88  std::swap( data_, other.data_ );
89  }
90 
91  ConstIterator begin () const { return data_.begin(); }
92  Iterator begin () { return data_.begin(); }
93 
94  ConstIterator end () const { return data_.end(); }
95  Iterator end () { return data_.end(); }
96 
97  int codimension () const { return codim_; }
98 
99 
100  // deprecated stuff, will be removed after Dune 2.3
101 
102  typedef Grid GridType DUNE_DEPRECATED_MSG("Use Grid instead.");
103  typedef Value Data DUNE_DEPRECATED_MSG("Use Value instead.");
104 
105  void reserve () DUNE_DEPRECATED_MSG("Use resize() instead.")
106  { return resize(); }
107 
108  void clear () DUNE_DEPRECATED_MSG("Use resize() instead.")
109  {
110  resize( Value() );
111  shrinkToFit();
112  fill( Value() );
113  }
114 
115  void update () DUNE_DEPRECATED_MSG("Use resize() instead.")
116  {
117  resize( Value() );
118  shrinkToFit();
119  }
120 
121  protected:
122  const IndexSet &indexSet () const { return *indexSet_; }
123 
124  int codim_;
126  Vector data_;
127  };
128 
129 } // namespace Dune
130 
131 #endif // #ifndef DUNE_PERSISTENTCONTAINERVECTOR_HH
Know your own codimension.
Definition: common/entity.hh:99
void reserve()
Definition: persistentcontainervector.hh:105
void update()
Definition: persistentcontainervector.hh:115
void resize(const Value &value=Value())
Definition: persistentcontainervector.hh:74
Wrapper class for entities.
Definition: common/entity.hh:56
const IndexSet * indexSet_
Definition: persistentcontainervector.hh:125
Index Set Interface base class.
Definition: common/grid.hh:359
ConstIterator end() const
Definition: persistentcontainervector.hh:94
Vector::const_iterator ConstIterator
Definition: persistentcontainervector.hh:26
void swap(This &other)
Definition: persistentcontainervector.hh:84
G Grid
Definition: persistentcontainervector.hh:22
void clear()
Definition: persistentcontainervector.hh:108
[ provides Dune::Grid ]
Definition: agrid.hh:137
void shrinkToFit()
Definition: persistentcontainervector.hh:80
IndexType index(const typename remove_const< GridImp >::type::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:107
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainervector.hh:57
Vector data_
Definition: persistentcontainervector.hh:126
Vector::allocator_type Allocator
Definition: persistentcontainervector.hh:29
Size size() const
Definition: persistentcontainervector.hh:72
const Value & operator[](const Entity &entity) const
Definition: persistentcontainervector.hh:39
Vector::iterator Iterator
Definition: persistentcontainervector.hh:27
Iterator begin()
Definition: persistentcontainervector.hh:92
void fill(const Value &value)
Definition: persistentcontainervector.hh:82
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:146
Iterator end()
Definition: persistentcontainervector.hh:95
Vector::size_type Size
Definition: persistentcontainervector.hh:25
ConstIterator begin() const
Definition: persistentcontainervector.hh:91
int codimension() const
Definition: persistentcontainervector.hh:97
vector-based implementation of the PersistentContainer
Definition: persistentcontainervector.hh:17
const IndexSet & indexSet() const
Definition: persistentcontainervector.hh:122
Vector::value_type Value
Definition: persistentcontainervector.hh:24
int codim_
Definition: persistentcontainervector.hh:124
PersistentContainerVector(const IndexSet &indexSet, int codim, const Value &value, const Allocator &allocator=Allocator())
Definition: persistentcontainervector.hh:31
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204