3#ifndef DUNE_PERSISTENTCONTAINERMAP_HH
4#define DUNE_PERSISTENTCONTAINERMAP_HH
20 template<
class G,
class IdSet,
class Map >
26 template<
class reference,
class iterator >
27 class IteratorWrapper;
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 >
51 const Value &operator[] (
const Entity &entity )
const
54 typename Map::const_iterator pos = data_.find( idSet().
id( entity ) );
55 assert( pos != data_.end() );
59 template<
class Entity >
60 Value &operator[] (
const Entity &entity )
63 typename Map::iterator pos = data_.find( idSet().
id( entity ) );
64 assert( pos != data_.end() );
68 template<
class Entity >
69 const Value &operator() (
const Entity &entity,
int subEntity )
const
71 typename Map::const_iterator pos = data_.find( idSet().subId( entity, subEntity, codimension() ) );
72 assert( pos != data_.end() );
76 template<
class Entity >
77 Value &operator() (
const Entity &entity,
int subEntity )
79 typename Map::iterator pos = data_.find( idSet().subId( entity, subEntity, codimension() ) );
80 assert( pos != data_.end() );
84 Size size ()
const {
return data_.size(); }
86 void resize (
const Value &value = Value() )
91 void shrinkToFit () {}
93 void fill (
const Value &value ) { std::fill( begin(), end(), value ); }
95 void swap (
This &other )
97 std::swap( grid_, other.grid_ );
98 std::swap( codim_, other.codim_ );
99 std::swap( idSet_, other.idSet_ );
100 std::swap( data_, other.data_ );
103 ConstIterator begin ()
const;
106 ConstIterator end ()
const;
109 int codimension ()
const {
return codim_; }
134 const Grid &grid ()
const {
return *grid_; }
136 template<
int codim >
137 void resize (
const Value &value );
139 template<
int codim >
140 void migrateLevel (
int level,
const Value &value, Map &data,
143 template<
int codim >
144 void migrateLevel (
int level,
const Value &value, Map &data,
147 static void migrateEntry (
const typename IdSet::IdType &
id,
const Value &value,
148 Map &oldData, Map &newData );
151 const IdSet &idSet ()
const {
return *idSet_; }
164 template<
class G,
class IdSet,
class Map >
165 template<
class value,
class iterator >
169 typedef IteratorWrapper< const value, typename Map::const_iterator > ConstWrapper;
172 IteratorWrapper (
const iterator &it ) : it_( it ) {}
174 operator ConstWrapper ()
const {
return ConstWrapper( it_ ); }
176 value &operator* () {
return it_->second; }
177 value *operator-> () {
return &(it_->second); }
179 bool operator== (
const IteratorWrapper &other )
const {
return (it_ == other.it_); }
180 bool operator!= (
const IteratorWrapper &other )
const {
return (it_ != other.it_); }
182 IteratorWrapper &operator++ () { ++it_;
return *
this; }
193 template<
class G,
class IdSet,
class Map >
194 template<
int codim >
195 struct PersistentContainerMap< G, IdSet, Map >::Resize
197 static void apply ( PersistentContainerMap< G, IdSet, Map > &container,
200 if( codim == container.codimension() )
201 container.template resize< codim >( value );
210 template<
class G,
class IdSet,
class Map >
211 inline typename PersistentContainerMap< G, IdSet, Map >::ConstIterator
212 PersistentContainerMap< G, IdSet, Map >::begin ()
const
214 return ConstIterator( data_.begin() );
217 template<
class G,
class IdSet,
class Map >
218 inline typename PersistentContainerMap< G, IdSet, Map >::Iterator
219 PersistentContainerMap< G, IdSet, Map >::begin ()
221 return Iterator( data_.begin() );
225 template<
class G,
class IdSet,
class Map >
226 inline typename PersistentContainerMap< G, IdSet, Map >::ConstIterator
227 PersistentContainerMap< G, IdSet, Map >::end ()
const
229 return ConstIterator( data_.end() );
232 template<
class G,
class IdSet,
class Map >
233 inline typename PersistentContainerMap< G, IdSet, Map >::Iterator
234 PersistentContainerMap< G, IdSet, Map >::end ()
236 return Iterator( data_.end() );
240 template<
class G,
class IdSet,
class Map >
241 template<
int codim >
242 inline void PersistentContainerMap< G, IdSet, Map >::resize (
const Value &value )
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 >
260 inline void PersistentContainerMap< G, IdSet, Map >
261 ::migrateLevel (
int level,
const Value &value, Map &data,
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 >
276 inline void PersistentContainerMap< G, IdSet, Map >
277 ::migrateLevel (
int level,
const Value &value, Map &data,
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 )
287 const typename LevelIterator::Entity &entity = *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 >
295 inline void PersistentContainerMap< G, IdSet, Map >
296 ::migrateEntry (
const typename IdSet::IdType &
id,
const Value &value,
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 );
Wrapper class for entities.
Definition: entity.hh:57
@ codimension
Know your own codimension.
Definition: entity.hh:99
A static loop using TMP.
Definition: forloop.hh:223
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: grid.hh:426
Id Set Interface.
Definition: indexidset.hh:403
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:406
map-based implementation of the PersistentContainer
Definition: persistentcontainermap.hh:22
A set of traits classes to store static information about grid implementation.
A static for loop for template meta-programming.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:231
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:253
Dune namespace.
Definition: alignment.hh:14
Generate a type for a given integral constant.
Definition: typetraits.hh:457
Traits for type conversions and type information.