3 #ifndef DUNE_PERSISTENTCONTAINERMAP_HH
4 #define DUNE_PERSISTENTCONTAINERMAP_HH
9 #include <dune/common/typetraits.hh>
10 #include <dune/common/forloop.hh>
20 template<
class G,
class IdSet,
class Map >
26 template<
class reference,
class iterator >
35 typedef typename Map::mapped_type
Value;
36 typedef typename Map::size_type
Size;
38 typedef IteratorWrapper< const Value, typename Map::const_iterator >
ConstIterator;
39 typedef IteratorWrapper< Value, typename Map::iterator >
Iterator;
50 template<
class Entity >
54 typename Map::const_iterator pos =
data_.find(
idSet().
id( entity ) );
55 assert( pos !=
data_.end() );
59 template<
class Entity >
63 typename Map::iterator pos =
data_.find(
idSet().
id( entity ) );
64 assert( pos !=
data_.end() );
68 template<
class Entity >
72 assert( pos !=
data_.end() );
76 template<
class Entity >
80 assert( pos !=
data_.end() );
88 return ForLoop< Resize, 0, Grid::dimension >::apply( *
this, value );
115 typedef Value Data DUNE_DEPRECATED_MSG(
"Use Value instead.");
136 template<
int codim >
139 template<
int codim >
141 integral_constant< bool, true > );
143 template<
int codim >
145 integral_constant< bool, false > );
148 Map &oldData, Map &newData );
164 template<
class G,
class IdSet,
class Map >
165 template<
class value,
class iterator >
169 typedef IteratorWrapper< const value, typename Map::const_iterator > ConstWrapper;
176 value &operator* () {
return it_->second; }
177 value *operator-> () {
return &(it_->second); }
193 template<
class G,
class IdSet,
class Map >
194 template<
int codim >
201 container.template resize< codim >( value );
210 template<
class G,
class IdSet,
class Map >
217 template<
class G,
class IdSet,
class Map >
225 template<
class G,
class IdSet,
class Map >
232 template<
class G,
class IdSet,
class Map >
240 template<
class G,
class IdSet,
class Map >
241 template<
int codim >
244 integral_constant< bool, Capabilities::hasEntity< Grid, codim >::v > hasEntity;
245 assert( codim == codimension() );
249 std::swap( data, data_ );
252 const int maxLevel = grid().maxLevel();
253 for (
int level = 0; level <= maxLevel; ++level )
254 migrateLevel< codim >( level, value, data, hasEntity );
258 template<
class G,
class IdSet,
class Map >
259 template<
int codim >
262 integral_constant< bool, true > )
265 typedef typename LevelView::template Codim< codim >::Iterator
LevelIterator;
267 const LevelView levelView = grid().levelGridView( level );
268 const LevelIterator end = levelView.template end< codim >();
269 for( LevelIterator it = levelView.template begin< codim >(); it != end; ++it )
270 migrateEntry( idSet().id( *it ), value, data, data_ );
274 template<
class G,
class IdSet,
class Map >
275 template<
int codim >
278 integral_constant< bool, false > )
281 typedef typename LevelView::template Codim< 0 >::Iterator
LevelIterator;
283 const LevelView levelView = grid().levelGridView( level );
284 const LevelIterator end = levelView.template end< 0 >();
285 for( LevelIterator it = levelView.template begin< 0 >(); it != end; ++it )
288 for(
int i = 0; i < entity.template count< codim >(); ++i )
289 migrateEntry( idSet().subId( entity, i, codim ), value, data, data_ );
294 template<
class G,
class IdSet,
class Map >
297 Map &oldData, Map &newData )
300 const std::pair< typename Map::iterator, bool > inserted
301 = newData.insert( std::make_pair(
id, value ) );
304 if( inserted.second )
306 const typename Map::iterator pos = oldData.find(
id );
307 if( pos != oldData.end() )
309 inserted.first->second = pos->second;
310 oldData.erase( pos );
317 #endif // #ifndef DUNE_PERSISTENTCONTAINERMAP_HH
Know your own codimension.
Definition: common/entity.hh:99
const Value & operator[](const Entity &entity) const
Definition: persistentcontainermap.hh:51
static void apply(PersistentContainerMap< G, IdSet, Map > &container, const Value &value)
Definition: persistentcontainermap.hh:197
map-based implementation of the PersistentContainer
Definition: persistentcontainermap.hh:21
const IdSet * idSet_
Definition: persistentcontainermap.hh:155
Wrapper class for entities.
Definition: common/entity.hh:56
IteratorWrapper< const Value, typename Map::const_iterator > ConstIterator
Definition: persistentcontainermap.hh:38
void reserve()
Definition: persistentcontainermap.hh:117
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:406
void swap(This &other)
Definition: persistentcontainermap.hh:95
Map data_
Definition: persistentcontainermap.hh:156
Grid GridType
Definition: persistentcontainermap.hh:114
const Grid & grid() const
Definition: persistentcontainermap.hh:134
PersistentContainerMap(const Grid &grid, int codim, const IdSet &idSet, const Value &value)
Definition: persistentcontainermap.hh:41
int codimension() const
Definition: persistentcontainermap.hh:109
void migrateLevel(int level, const Value &value, Map &data, integral_constant< bool, true >)
Definition: persistentcontainermap.hh:261
void resize(const Value &value=Value())
Definition: persistentcontainermap.hh:86
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainermap.hh:69
const Grid * grid_
Definition: persistentcontainermap.hh:153
ConstIterator end() const
Definition: persistentcontainermap.hh:227
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: common/grid.hh:426
IteratorWrapper< Value, typename Map::iterator > Iterator
Definition: persistentcontainermap.hh:39
A set of traits classes to store static information about grid implementation.
Size size() const
Definition: persistentcontainermap.hh:84
Value Data
Definition: persistentcontainermap.hh:115
ConstIterator begin() const
Definition: persistentcontainermap.hh:212
void shrinkToFit()
Definition: persistentcontainermap.hh:91
const IdSet & idSet() const
Definition: persistentcontainermap.hh:151
G Grid
Definition: persistentcontainermap.hh:30
static void migrateEntry(const typename IdSet::IdType &id, const Value &value, Map &oldData, Map &newData)
Definition: persistentcontainermap.hh:296
IteratorWrapper(const iterator &it)
Definition: persistentcontainermap.hh:172
int codim_
Definition: persistentcontainermap.hh:154
void update()
Definition: persistentcontainermap.hh:127
void fill(const Value &value)
Definition: persistentcontainermap.hh:93
IteratorImp::Entity Entity
The Entity that this EntityPointer can point to.
Definition: common/entitypointer.hh:123
Map::size_type Size
Definition: persistentcontainermap.hh:36
Id Set Interface.
Definition: common/grid.hh:360
Map::mapped_type Value
Definition: persistentcontainermap.hh:35
Enables iteration over all entities of a given codimension and level of a grid. See also the document...
Definition: common/leveliterator.hh:29
void clear()
Definition: persistentcontainermap.hh:120
Definition: persistentcontainermap.hh:27