1#ifndef DUNE_FEM_SINGLETONLIST_HH
2#define DUNE_FEM_SINGLETONLIST_HH
23 template<
class Key,
class Object >
28 return new Object( key );
50 template<
class Key,
class Object,
51 class Factory = DefaultSingletonFactory< Key, Object > >
61 typedef std :: pair< ObjectType * , unsigned int * >
ValueType;
70 typedef std :: list< ListObjType > ListType;
71 typedef typename ListType :: iterator ListIteratorType;
73 class SingletonListStorage;
87 return s.singletonList();
93 template<
class... Args >
95 -> std::enable_if_t< std::is_same< decltype( FactoryType::createObject( key, std::forward< Args >( args )... ) ),
ObjectType * >::value,
ObjectType & >
102 ++( *(objValue.second) );
103 return *(objValue.first);
107 if( ! Fem :: MPIManager :: singleThreadMode() )
113 ObjectType *
object = FactoryType::createObject( key, std::forward< Args >( args )... );
115 ValueType value(
object,
new unsigned int( 1 ) );
126 if( ! Fem :: MPIManager :: singleThreadMode() )
132 for( ListIteratorType it =
singletonList().begin(); it != end; ++it )
134 if( (*it).second.first == &
object )
141 std :: cerr <<
"Object could not be deleted, "
142 <<
"because it is not in the list anymore!" << std :: endl;
149 for(ListIteratorType it =
singletonList().begin(); it!=endit; ++it)
151 if( (*it).first == key )
163 unsigned int &refCount = *(value.second);
165 assert( refCount > 0 );
166 if( (--refCount) == 0 )
171 static void deleteItem(ListIteratorType & it)
177 FactoryType :: deleteObject( val.first );
183 template<
class Key,
class Object,
class Factory >
204 return singletonList_;
213 FactoryType :: deleteObject( val.first );
Definition: bindguard.hh:11
Exception thrown when a code segment that is supposed to be only accessed in single thread mode is ac...
Definition: mpimanager.hh:43
static DUNE_EXPORT Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:118
Definition: singletonlist.hh:25
static void deleteObject(Object *object)
Definition: singletonlist.hh:31
static Object * createObject(const Key &key)
Definition: singletonlist.hh:26
Singleton list for key/object pairs.
Definition: singletonlist.hh:53
Key KeyType
Definition: singletonlist.hh:57
static void removeObject(const ObjectType &object)
Definition: singletonlist.hh:123
static ListType & singletonList()
Definition: singletonlist.hh:81
static ValueType getObjFromList(const KeyType &key)
Definition: singletonlist.hh:146
Object ObjectType
Definition: singletonlist.hh:58
static void eraseItem(ListIteratorType &it)
Definition: singletonlist.hh:160
std ::pair< KeyType, ValueType > ListObjType
Definition: singletonlist.hh:62
std ::pair< ObjectType *, unsigned int * > ValueType
Definition: singletonlist.hh:61
Factory FactoryType
Definition: singletonlist.hh:59
SingletonList(const ThisType &)=delete
static auto getObject(const KeyType &key, Args &&... args) -> std::enable_if_t< std::is_same< decltype(FactoryType::createObject(key, std::forward< Args >(args)...)), ObjectType * >::value, ObjectType & >
Definition: singletonlist.hh:94
Definition: singletonlist.hh:65
void operator()(ObjectType *p) const
Definition: singletonlist.hh:66
Definition: singletonlist.hh:185
SingletonListStorage()
Definition: singletonlist.hh:192
ListType singletonList_
Definition: singletonlist.hh:189
void deleteItem(const ListIteratorType &it)
Definition: singletonlist.hh:207
~SingletonListStorage()
Definition: singletonlist.hh:196
ListType & singletonList()
Definition: singletonlist.hh:202