3 #ifndef DUNE_PERSISTENTCONTAINERMAP_HH 4 #define DUNE_PERSISTENTCONTAINERMAP_HH 9 #include <dune/common/hybridutilities.hh> 10 #include <dune/common/std/utility.hh> 11 #include <dune/common/typetraits.hh> 21 template<
class G,
class IdSet,
class Map >
27 template<
class reference,
class iterator >
28 class IteratorWrapper;
33 typedef typename Map::mapped_type
Value;
34 typedef typename Map::size_type
Size;
36 typedef IteratorWrapper< const Value, typename Map::const_iterator >
ConstIterator;
37 typedef IteratorWrapper< Value, typename Map::iterator >
Iterator;
48 template<
class Entity >
52 typename Map::const_iterator pos =
data_.find(
idSet().
id( entity ) );
53 assert( pos !=
data_.end() );
57 template<
class Entity >
61 typename Map::iterator pos =
data_.find(
idSet().
id( entity ) );
62 assert( pos !=
data_.end() );
66 template<
class Entity >
70 assert( pos !=
data_.end() );
74 template<
class Entity >
78 assert( pos !=
data_.end() );
86 Hybrid::forEach( Std::make_index_sequence< Grid::dimension+1 >{},
87 [ & ](
auto i ){
if( i == this->
codimension() ) this->
template resize< i >( value ); } );
92 void fill (
const Value &value ) { std::fill(
begin(),
end(), value ); }
102 ConstIterator
begin ()
const;
105 ConstIterator
end ()
const;
113 template<
int codim >
114 void resize (
const Value &value );
116 template<
int codim >
117 void migrateLevel (
int level,
const Value &value, Map &data,
118 std::integral_constant< bool, true > );
120 template<
int codim >
121 void migrateLevel (
int level,
const Value &value, Map &data,
122 std::integral_constant< bool, false > );
125 Map &oldData, Map &newData );
140 template<
class G,
class IdSet,
class Map >
141 template<
class value,
class iterator >
145 typedef IteratorWrapper< const value, typename Map::const_iterator > ConstWrapper;
150 operator ConstWrapper ()
const {
return ConstWrapper( it_ ); }
152 value &operator* () {
return it_->second; }
153 value *operator-> () {
return &(it_->second); }
170 template<
class G,
class IdSet,
class Map >
177 template<
class G,
class IdSet,
class Map >
185 template<
class G,
class IdSet,
class Map >
192 template<
class G,
class IdSet,
class Map >
200 template<
class G,
class IdSet,
class Map >
201 template<
int codim >
204 std::integral_constant< bool, Capabilities::hasEntity< Grid, codim >::v > hasEntity;
209 std::swap( data,
data_ );
212 const int maxLevel =
grid().maxLevel();
213 for (
int level = 0; level <= maxLevel; ++level )
214 migrateLevel< codim >( level, value, data, hasEntity );
218 template<
class G,
class IdSet,
class Map >
219 template<
int codim >
222 std::integral_constant< bool, true > )
225 typedef typename LevelView::template Codim< codim >::Iterator LevelIterator;
227 const LevelView levelView =
grid().levelGridView( level );
228 const LevelIterator
end = levelView.template end< codim >();
229 for( LevelIterator it = levelView.template begin< codim >(); it !=
end; ++it )
234 template<
class G,
class IdSet,
class Map >
235 template<
int codim >
238 std::integral_constant< bool, false > )
241 typedef typename LevelView::template Codim< 0 >::Iterator LevelIterator;
243 const LevelView levelView =
grid().levelGridView( level );
244 const LevelIterator
end = levelView.template end< 0 >();
245 for( LevelIterator it = levelView.template begin< 0 >(); it !=
end; ++it )
247 const typename LevelIterator::Entity &entity = *it;
248 const int subEntities = entity.subEntities( codim );
249 for(
int i = 0; i < subEntities; ++i )
255 template<
class G,
class IdSet,
class Map >
258 Map &oldData, Map &newData )
261 const std::pair< typename Map::iterator, bool > inserted
262 = newData.insert( std::make_pair(
id, value ) );
265 if( inserted.second )
267 const typename Map::iterator pos = oldData.find(
id );
268 if( pos != oldData.end() )
270 inserted.first->second = pos->second;
271 oldData.erase( pos );
278 #endif // #ifndef DUNE_PERSISTENTCONTAINERMAP_HH const IdSet * idSet_
Definition: persistentcontainermap.hh:131
Include standard header files.
Definition: agrid.hh:58
void swap(This &other)
Definition: persistentcontainermap.hh:94
map-based implementation of the PersistentContainer
Definition: persistentcontainermap.hh:22
const Value & operator[](const Entity &entity) const
Definition: persistentcontainermap.hh:49
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:448
const IdSet & idSet() const
Definition: persistentcontainermap.hh:127
IteratorWrapper(const iterator &it)
Definition: persistentcontainermap.hh:148
G Grid
Definition: persistentcontainermap.hh:28
int codim_
Definition: persistentcontainermap.hh:130
static void migrateEntry(const typename IdSet::IdType &id, const Value &value, Map &oldData, Map &newData)
Definition: persistentcontainermap.hh:257
Definition: persistentcontainermap.hh:28
Wrapper class for entities.
Definition: common/entity.hh:63
void fill(const Value &value)
Definition: persistentcontainermap.hh:92
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: common/grid.hh:406
ConstIterator end() const
Definition: persistentcontainermap.hh:187
IteratorWrapper< Value, typename Map::iterator > Iterator
Definition: persistentcontainermap.hh:37
const Grid * grid_
Definition: persistentcontainermap.hh:129
int codimension() const
Definition: persistentcontainermap.hh:108
IteratorWrapper< const Value, typename Map::const_iterator > ConstIterator
Definition: persistentcontainermap.hh:36
void resize(const Value &value=Value())
Definition: persistentcontainermap.hh:84
Know your own codimension.
Definition: common/entity.hh:105
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainermap.hh:67
const Grid & grid() const
Definition: persistentcontainermap.hh:111
Size size() const
Definition: persistentcontainermap.hh:82
A set of traits classes to store static information about grid implementation.
PersistentContainerMap(const Grid &grid, int codim, const IdSet &idSet, const Value &value)
Definition: persistentcontainermap.hh:39
void shrinkToFit()
Definition: persistentcontainermap.hh:90
Map::mapped_type Value
Definition: persistentcontainermap.hh:33
ConstIterator begin() const
Definition: persistentcontainermap.hh:172
Id Set Interface.
Definition: common/grid.hh:347
Map data_
Definition: persistentcontainermap.hh:132
void migrateLevel(int level, const Value &value, Map &data, std::integral_constant< bool, true >)
Definition: persistentcontainermap.hh:221
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:444
Map::size_type Size
Definition: persistentcontainermap.hh:34