1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi: set et ts=4 sw=2 sts=2: 3 #ifndef DUNE_PERSISTENTCONTAINERWRAPPER_HH 4 #define DUNE_PERSISTENTCONTAINERWRAPPER_HH 5 6 #include <dune/grid/utility/hostgridaccess.hh> 7 #include <dune/grid/utility/persistentcontainer.hh> 8 9 namespace Dune 10 { 11 12 // PersistentContainerWrapper 13 // -------------------------- 14 15 template< class G, class T > 16 class PersistentContainerWrapper 17 { 18 typedef PersistentContainerWrapper< G, T > This; 19 20 typedef Dune::HostGridAccess< G > HostGridAccess; 21 22 typedef typename HostGridAccess::HostGrid HostGrid; 23 typedef PersistentContainer< HostGrid, T > PersistentContainerHostGrid; 24 25 public: 26 typedef G Grid; 27 28 typedef typename PersistentContainer< HostGrid, T >::Value Value; 29 typedef typename PersistentContainer< HostGrid, T >::Size Size; 30 31 typedef typename PersistentContainer< HostGrid, T >::Iterator Iterator; 32 typedef typename PersistentContainer< HostGrid, T >::ConstIterator ConstIterator; 33 PersistentContainerWrapper(const Grid & grid,int codim,const Value & value=Value ())34 PersistentContainerWrapper ( const Grid &grid, int codim, const Value &value = Value() ) 35 : hostContainer_( HostGridAccess::hostGrid( grid ), codim, value ) 36 {} 37 38 template< class Entity > operator [](const Entity & entity) const39 const Value &operator[] ( const Entity &entity ) const 40 { 41 return hostContainer_[ HostGridAccess::hostEntity( entity ) ]; 42 } 43 44 template< class Entity > operator [](const Entity & entity)45 Value &operator[] ( const Entity &entity ) 46 { 47 return hostContainer_[ HostGridAccess::hostEntity( entity ) ]; 48 } 49 50 template< class Entity > operator ()(const Entity & entity,int subEntity) const51 const Value &operator() ( const Entity &entity, int subEntity ) const 52 { 53 return hostContainer_( HostGridAccess::hostEntity( entity ), subEntity ); 54 } 55 56 template< class Entity > operator ()(const Entity & entity,int subEntity)57 Value &operator() ( const Entity &entity, int subEntity ) 58 { 59 return hostContainer_( HostGridAccess::hostEntity( entity ), subEntity ); 60 } 61 size() const62 Size size () const { return hostContainer_.size(); } 63 resize(const Value & value=Value ())64 void resize ( const Value &value = Value() ) { hostContainer_.resize( value ); } shrinkToFit()65 void shrinkToFit () { return hostContainer_.shrinkToFit(); } 66 fill(const Value & value=Value ())67 void fill ( const Value &value = Value() ) { hostContainer_.fill( value ); } 68 swap(This & other)69 void swap ( This &other ) { hostContainer_.swap( other.hostContainer_ ); } 70 begin() const71 ConstIterator begin () const { return hostContainer_.begin(); } begin()72 Iterator begin () { return hostContainer_.begin(); } 73 end() const74 ConstIterator end () const { return hostContainer_.end(); } end()75 Iterator end () { return hostContainer_.end(); } 76 codimension() const77 int codimension () const { return hostContainer_.codimension(); } 78 79 protected: 80 PersistentContainer< HostGrid, T > hostContainer_; 81 }; 82 83 } // namespace Dune 84 85 #endif // #ifndef DUNE_PERSISTENTCONTAINERWRAPPER_HH 86