1 #ifndef DUNE_PERSISTENTCONTAINER_HH
2 #define DUNE_PERSISTENTCONTAINER_HH
8 #include <dune/common/misc.hh>
9 #include <dune/common/forloop.hh>
42 template <
class Gr
id,
class Data,
class Allocator=std::allocator<Data> >
48 template <
class Gr
id,
class Index,
class Vector>
52 typedef typename Vector::value_type
Data;
75 const double overEstimate,
76 const typename Vector::allocator_type &allocator )
99 template <
class Entity>
103 assert( (
typename Index::IndexType)
index_.index( entity ) < (
typename Index::IndexType)
data_.size() );
108 template <
class Entity>
112 assert( (
typename Index::IndexType)
index_.index( entity ) < (
typename Index::IndexType)
data_.size() );
119 assert( (
typename Index::IndexType)
index_.subIndex( element, subEntity,
codim_ ) < (
typename Index::IndexType)
data_.size() );
126 assert( (
typename Index::IndexType)
index_.subIndex( element, subEntity,
codim_ ) < (
typename Index::IndexType)
data_.size() );
133 return data_.begin();
139 return data_.begin();
160 if( (
typename Index::IndexType)
index_.size(
codim_ ) > (
typename Index::IndexType)
data_.size() )
179 if (newSize <
data_.capacity())
192 template <
class Gr
id,
class Id,
class Map>
198 typedef typename Map :: mapped_type
Data;
209 template <
class D,
class IteratorType >
226 template <
class IteratorType>
254 template<
int codim ,
bool gr
idHasCodim >
259 if( codim == myCodim )
260 container.template adaptCodim< codim > ( value );
264 template<
int codim >
272 template<
int codim >
274 :
public AdaptCodimBase< codim, Capabilities :: hasEntity < GridType, codim > :: v >
287 const typename Map::key_compare& comp,
288 const typename Map::allocator_type &allocator )
292 ,
data_(comp,allocator)
317 template <
class Entity>
325 template <
class Entity>
392 ForLoop< AdaptCodim, 0, GridType :: dimension > :: apply( *
this, value,
codim_ );
398 assert(
codim_ == codim );
401 std::swap( oldData,
data_ );
403 const iterator olddataend = oldData.end();
408 const LevelIterator endit =
grid_.template lend< codim > ( l );
409 for( LevelIterator it =
grid_.template lbegin< codim > ( l ); it != endit; ++ it )
411 const Entity& entity = * it ;
414 iterator entry = oldData.find(
id );
415 if( entry != olddataend )
416 data = (*entry).second;
424 template <
class Gr
id,
class Data,
class Allocator>
425 class PersistentContainer
426 :
public PersistentContainerMap< Grid, typename Grid::Traits::LocalIdSet,
427 std::map<const typename Grid::Traits::LocalIdSet::IdType, Data,
428 std::less<const typename Grid::Traits::LocalIdSet::IdType>,
429 typename Allocator::template rebind<typename Grid::Traits::LocalIdSet::IdType>::other > >
434 typedef typename Grid::Traits::LocalIdSet
IdSet;
436 typedef typename Allocator::template rebind<IdType>::other
IdAllocator;
437 typedef std::map<const IdType, Data, std::less<const IdType>,
445 :
BaseType( grid, codim, grid.localIdSet(), std::less<const
IdType>(), allocator )
449 #if 0 // the following implementation can be used for a grid providing a hash for the id type
450 #include <unordered_map>
451 template <
class MyGr
id,
class Data,
class Allocator >
452 class PersistentContainer
453 :
public PersistentContainerMap< MyGrid, typename MyGrid::Traits::LocalIdSet,
454 std::unordered_map<const typename MyGrid::Traits::LocalIdSet::IdType, Data,
455 std::hash<typename MyGrid::Traits::LocalIdSet::IdType>,
456 std::equal_to<const typename MyGrid::Traits::LocalIdSet::IdType>, Allocator> >
459 typedef typename GridType::Traits::LocalIdSet
IdSet;
461 typedef std::unordered_map<const IdType, Data, std::hash<IdType>, std::equal_to<const IdType>, Allocator>
Map;
462 typedef PersistentContainerMap< GridType, IdSet, Map >
BaseType;
471 :
BaseType( grid, codim, grid.localIdSet() )
477 #endif // end DUNE_PERSISTENTCONTAINER_HH