5#ifndef DUNE_PERSISTENTCONTAINERMAP_HH
6#define DUNE_PERSISTENTCONTAINERMAP_HH
13#include <dune/common/hybridutilities.hh>
14#include <dune/common/typetraits.hh>
24 template<
class G,
class IdSet,
class Map >
30 template<
class reference,
class iterator >
36 typedef typename Map::mapped_type
Value;
37 typedef typename Map::size_type
Size;
51 template<
class Entity >
55 typename Map::const_iterator pos =
data_.find(
idSet().
id( entity ) );
56 assert( pos !=
data_.end() );
60 template<
class Entity >
64 typename Map::iterator pos =
data_.find(
idSet().
id( entity ) );
65 assert( pos !=
data_.end() );
69 template<
class Entity >
73 assert( pos !=
data_.end() );
77 template<
class Entity >
81 assert( pos !=
data_.end() );
89 Hybrid::forEach( std::make_index_sequence< Grid::dimension+1 >{},
90 [ & ](
auto i ){
if(
int(i) == this->
codimension() ) this->
template resize< i >( value ); } );
116 template<
int codim >
119 template<
int codim >
121 std::integral_constant< bool, true > );
123 template<
int codim >
125 std::integral_constant< bool, false > );
128 Map &oldData, Map &newData );
143 template<
class G,
class IdSet,
class Map >
144 template<
class value,
class iterator >
155 value &operator* () {
return it_->second; }
156 value *operator-> () {
return &(it_->second); }
173 template<
class G,
class IdSet,
class Map >
180 template<
class G,
class IdSet,
class Map >
188 template<
class G,
class IdSet,
class Map >
195 template<
class G,
class IdSet,
class Map >
203 template<
class G,
class IdSet,
class Map >
204 template<
int codim >
207 std::integral_constant< bool, Capabilities::hasEntityIterator< Grid, codim >::v > hasEntityIterator;
208 assert( codim == codimension() );
215 const int maxLevel = grid().maxLevel();
216 for (
int level = 0; level <= maxLevel; ++level )
217 migrateLevel< codim >( level, value, data, hasEntityIterator );
221 template<
class G,
class IdSet,
class Map >
222 template<
int codim >
225 std::integral_constant< bool, true > )
228 typedef typename LevelView::template Codim< codim >::Iterator LevelIterator;
230 const LevelView levelView = grid().levelGridView( level );
231 const LevelIterator end = levelView.template end< codim >();
232 for( LevelIterator it = levelView.template begin< codim >(); it != end; ++it )
233 migrateEntry( idSet().
id( *it ), value, data, data_ );
237 template<
class G,
class IdSet,
class Map >
238 template<
int codim >
241 std::integral_constant< bool, false > )
244 typedef typename LevelView::template Codim< 0 >::Iterator LevelIterator;
246 const LevelView levelView = grid().levelGridView( level );
247 const LevelIterator end = levelView.template end< 0 >();
248 for( LevelIterator it = levelView.template begin< 0 >(); it != end; ++it )
250 const typename LevelIterator::Entity &entity = *it;
251 const int subEntities = entity.subEntities( codim );
252 for(
int i = 0; i < subEntities; ++i )
253 migrateEntry( idSet().subId( entity, i, codim ), value, data, data_ );
258 template<
class G,
class IdSet,
class Map >
261 Map &oldData, Map &newData )
264 const std::pair< typename Map::iterator, bool > inserted
265 = newData.insert( std::make_pair(
id, value ) );
268 if( inserted.second )
270 const typename Map::iterator pos = oldData.find(
id );
271 if( pos != oldData.end() )
273 inserted.first->second = pos->second;
274 oldData.erase( pos );
void swap(Dune::PersistentContainer< G, T > &a, Dune::PersistentContainer< G, T > &b)
Definition: utility/persistentcontainer.hh:83
Include standard header files.
Definition: agrid.hh:60
Wrapper class for entities.
Definition: common/entity.hh:66
static constexpr int codimension
Know your own codimension.
Definition: common/entity.hh:106
Id Set Interface.
Definition: indexidset.hh:452
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:458
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: common/grid.hh:402
map-based implementation of the PersistentContainer
Definition: persistentcontainermap.hh:26
void migrateLevel(int level, const Value &value, Map &data, std::integral_constant< bool, false >)
Definition: persistentcontainermap.hh:240
void swap(This &other)
Definition: persistentcontainermap.hh:97
void fill(const Value &value)
Definition: persistentcontainermap.hh:95
G Grid
Definition: persistentcontainermap.hh:34
void resize(const Value &value)
IteratorWrapper< const Value, typename Map::const_iterator > ConstIterator
Definition: persistentcontainermap.hh:39
int codim_
Definition: persistentcontainermap.hh:133
const Grid * grid_
Definition: persistentcontainermap.hh:132
const Value & operator[](const Entity &entity) const
Definition: persistentcontainermap.hh:52
int codimension() const
Definition: persistentcontainermap.hh:111
void resize(const Value &value=Value())
Definition: persistentcontainermap.hh:87
const IdSet & idSet() const
Definition: persistentcontainermap.hh:130
ConstIterator begin() const
Definition: persistentcontainermap.hh:175
static void migrateEntry(const typename IdSet::IdType &id, const Value &value, Map &oldData, Map &newData)
Definition: persistentcontainermap.hh:260
Map::mapped_type Value
Definition: persistentcontainermap.hh:36
Iterator end()
Definition: persistentcontainermap.hh:197
const Grid & grid() const
Definition: persistentcontainermap.hh:114
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainermap.hh:70
PersistentContainerMap(const Grid &grid, int codim, const IdSet &idSet, const Value &value)
Definition: persistentcontainermap.hh:42
Iterator begin()
Definition: persistentcontainermap.hh:182
Map::size_type Size
Definition: persistentcontainermap.hh:37
ConstIterator end() const
Definition: persistentcontainermap.hh:190
Map data_
Definition: persistentcontainermap.hh:135
Size size() const
Definition: persistentcontainermap.hh:85
IteratorWrapper< Value, typename Map::iterator > Iterator
Definition: persistentcontainermap.hh:40
const IdSet * idSet_
Definition: persistentcontainermap.hh:134
void migrateLevel(int level, const Value &value, Map &data, std::integral_constant< bool, true >)
Definition: persistentcontainermap.hh:224
void shrinkToFit()
Definition: persistentcontainermap.hh:93
Definition: persistentcontainermap.hh:147
IteratorWrapper(const iterator &it)
Definition: persistentcontainermap.hh:151
A set of traits classes to store static information about grid implementation.