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 );
93 void fill (
const Value &value ) { std::fill(
begin(),
end(), value ); }
103 ConstIterator
begin ()
const;
106 ConstIterator
end ()
const;
114 template<
int codim >
115 void resize (
const Value &value );
117 template<
int codim >
118 void migrateLevel (
int level,
const Value &value, Map &data,
119 std::integral_constant< bool, true > );
121 template<
int codim >
122 void migrateLevel (
int level,
const Value &value, Map &data,
123 std::integral_constant< bool, false > );
126 Map &oldData, Map &newData );
141 template<
class G,
class IdSet,
class Map >
142 template<
class value,
class iterator >
146 typedef IteratorWrapper< const value, typename Map::const_iterator > ConstWrapper;
151 operator ConstWrapper ()
const {
return ConstWrapper( it_ ); }
153 value &operator* () {
return it_->second; }
154 value *operator-> () {
return &(it_->second); }
170 template<
class G,
class IdSet,
class Map >
171 template<
int codim >
178 container.template resize< codim >( value );
187 template<
class G,
class IdSet,
class Map >
194 template<
class G,
class IdSet,
class Map >
202 template<
class G,
class IdSet,
class Map >
209 template<
class G,
class IdSet,
class Map >
217 template<
class G,
class IdSet,
class Map >
218 template<
int codim >
221 std::integral_constant< bool, Capabilities::hasEntity< Grid, codim >::v > hasEntity;
226 std::swap( data,
data_ );
229 const int maxLevel =
grid().maxLevel();
230 for (
int level = 0; level <= maxLevel; ++level )
231 migrateLevel< codim >( level, value, data, hasEntity );
235 template<
class G,
class IdSet,
class Map >
236 template<
int codim >
239 std::integral_constant< bool, true > )
242 typedef typename LevelView::template Codim< codim >::Iterator LevelIterator;
244 const LevelView levelView =
grid().levelGridView( level );
245 const LevelIterator
end = levelView.template end< codim >();
246 for( LevelIterator it = levelView.template begin< codim >(); it !=
end; ++it )
251 template<
class G,
class IdSet,
class Map >
252 template<
int codim >
255 std::integral_constant< bool, false > )
258 typedef typename LevelView::template Codim< 0 >::Iterator LevelIterator;
260 const LevelView levelView =
grid().levelGridView( level );
261 const LevelIterator
end = levelView.template end< 0 >();
262 for( LevelIterator it = levelView.template begin< 0 >(); it !=
end; ++it )
264 const typename LevelIterator::Entity &entity = *it;
265 const int subEntities = entity.subEntities( codim );
266 for(
int i = 0; i < subEntities; ++i )
272 template<
class G,
class IdSet,
class Map >
275 Map &oldData, Map &newData )
278 const std::pair< typename Map::iterator, bool > inserted
279 = newData.insert( std::make_pair(
id, value ) );
282 if( inserted.second )
284 const typename Map::iterator pos = oldData.find(
id );
285 if( pos != oldData.end() )
287 inserted.first->second = pos->second;
288 oldData.erase( pos );
295 #endif // #ifndef DUNE_PERSISTENTCONTAINERMAP_HH const IdSet * idSet_
Definition: persistentcontainermap.hh:132
Definition: persistentcontainermap.hh:27
IteratorWrapper(const iterator &it)
Definition: persistentcontainermap.hh:149
ConstIterator end() const
Definition: persistentcontainermap.hh:204
Map data_
Definition: persistentcontainermap.hh:133
Size size() const
Definition: persistentcontainermap.hh:84
const IdSet & idSet() const
Definition: persistentcontainermap.hh:128
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: common/grid.hh:406
void shrinkToFit()
Definition: persistentcontainermap.hh:91
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:409
void fill(const Value &value)
Definition: persistentcontainermap.hh:93
Map::size_type Size
Definition: persistentcontainermap.hh:36
Map::mapped_type Value
Definition: persistentcontainermap.hh:35
int codimension() const
Definition: persistentcontainermap.hh:109
static void migrateEntry(const typename IdSet::IdType &id, const Value &value, Map &oldData, Map &newData)
Definition: persistentcontainermap.hh:274
Know your own codimension.
Definition: common/entity.hh:107
IteratorWrapper< const Value, typename Map::const_iterator > ConstIterator
Definition: persistentcontainermap.hh:38
G Grid
Definition: persistentcontainermap.hh:30
static void apply(PersistentContainerMap< G, IdSet, Map > &container, const Value &value)
Definition: persistentcontainermap.hh:174
map-based implementation of the PersistentContainer
Definition: persistentcontainermap.hh:21
A set of traits classes to store static information about grid implementation.
Include standard header files.
Definition: agrid.hh:59
Id Set Interface.
Definition: common/grid.hh:347
PersistentContainerMap(const Grid &grid, int codim, const IdSet &idSet, const Value &value)
Definition: persistentcontainermap.hh:41
void resize(const Value &value=Value())
Definition: persistentcontainermap.hh:86
Wrapper class for entities.
Definition: common/entity.hh:64
IteratorWrapper< Value, typename Map::iterator > Iterator
Definition: persistentcontainermap.hh:39
void migrateLevel(int level, const Value &value, Map &data, std::integral_constant< bool, true >)
Definition: persistentcontainermap.hh:238
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:405
const Value & operator()(const Entity &entity, int subEntity) const
Definition: persistentcontainermap.hh:69
const Grid & grid() const
Definition: persistentcontainermap.hh:112
const Grid * grid_
Definition: persistentcontainermap.hh:130
Definition: persistentcontainermap.hh:30
void swap(This &other)
Definition: persistentcontainermap.hh:95
ConstIterator begin() const
Definition: persistentcontainermap.hh:189
const Value & operator[](const Entity &entity) const
Definition: persistentcontainermap.hh:51
int codim_
Definition: persistentcontainermap.hh:131