1#ifndef DUNE_FEM_OBJECTSTACK_HH
2#define DUNE_FEM_OBJECTSTACK_HH
4#include <dune/fem/storage/referencecounter.hh>
5#include <dune/fem/misc/threads/threadsafevalue.hh>
13 template<
class ObjectFactoryImp >
16 template<
class ObjectFactoryImp >
17 class ObjectStackEntry;
20 template<
class ObjectFactoryImp >
21 struct ObjectStackEntryTraits
23 typedef ObjectStackEntry< ObjectFactoryImp > ReferenceCounterType;
25 typedef typename ObjectFactoryImp :: ObjectType ObjectType;
29 template<
class ObjectFactoryImp >
30 class ObjectStackEntry
31 :
public ReferenceCounterDefault< ObjectStackEntryTraits< ObjectFactoryImp > >
34 typedef ObjectFactoryImp ObjectFactoryType;
36 typedef ObjectStackEntryTraits< ObjectFactoryType > Traits;
39 typedef ObjectStackEntry< ObjectFactoryType > ThisType;
40 typedef ReferenceCounterDefault< Traits > BaseType;
42 friend class ObjectStack< ObjectFactoryType >;
45 typedef ObjectStack< ObjectFactoryType > ObjectStackType;
48 typedef typename ObjectFactoryType :: ObjectType ObjectType;
52 ObjectStackType &stack_;
55 ObjectType *
const object_;
60 inline explicit ObjectStackEntry ( ObjectStackType &stack )
63 object_( stack_.factory().newObject() )
68 ObjectStackEntry (
const ThisType& ) =
delete;
70 inline ~ObjectStackEntry ()
75 ThisType& operator= (
const ThisType& ) =
delete;
77 inline operator const ObjectType& ()
const
82 inline operator ObjectType& ()
87 inline void deleteObject ()
92 inline const ObjectType &getObject ()
const
97 inline ObjectType &getObject ()
108 template<
class ObjectFactoryImp >
111 typedef ObjectFactoryImp ObjectFactoryType;
116 friend class ObjectStackEntry< ObjectFactoryType >;
129 const ObjectFactoryType &factory_;
140 : factory_( factory ),
141 stackEntries_( StackEntryPtrType(0) )
152 assert( MPIManager::singleThreadMode() );
153 const size_t threadSize = stackEntries_.
size();
154 for(
size_t i=0; i<threadSize; ++i )
156 StackEntryPtrType& stackEntry = stackEntries_[ i ];
157 while ( stackEntry != 0 )
160 stackEntry = obj->next_;
166 ThisType& operator= (
const ThisType& ) =
delete;
175 inline const ObjectFactoryType &factory()
const
184 push( obj, *stackEntries_ );
191 return pop( *stackEntries_ );
196 inline void push (
StackEntryType *obj, StackEntryPtrType& stackEntry )
198 obj->next_ = stackEntry;
207 stackEntry = stackEntry->next_;
models a pointer to a reference countable object
Definition: referencecounter.hh:224
Definition: objectstack.hh:110
~ObjectStack()
delete all objects on stack
Definition: objectstack.hh:148
ObjectFactoryType::ObjectType ObjectType
type of the stored objects
Definition: objectstack.hh:120
ObjectStack(const ObjectFactoryType &factory)
constructor
Definition: objectstack.hh:139
ObjectStackEntry< ObjectFactoryType > StackEntryType
type of the storage objects
Definition: objectstack.hh:123
PointerType getObject()
get an object pointer to a storage object
Definition: objectstack.hh:169
ObjectPointer< StackEntryType > PointerType
type of object pointers
Definition: objectstack.hh:126
size_t size() const
return number of threads
Definition: threadsafevalue.hh:62
Dune namespace.
Definition: alignedallocator.hh:13