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 & >
98 assert( Fem :: ThreadManager :: singleThreadMode() );
105 ++( *(objValue.second) );
106 return *(objValue.first);
110 ObjectType *
object = FactoryType::createObject( key, std::forward< Args >( args )... );
112 ValueType value(
object,
new unsigned int( 1 ) );
123 assert( Fem :: ThreadManager :: singleThreadMode() );
126 for( ListIteratorType it =
singletonList().begin(); it != end; ++it )
128 if( (*it).second.first == &
object )
135 std :: cerr <<
"Object could not be deleted, "
136 <<
"because it is not in the list anymore!" << std :: endl;
143 for(ListIteratorType it =
singletonList().begin(); it!=endit; ++it)
145 if( (*it).first == key )
157 unsigned int &refCount = *(value.second);
159 assert( refCount > 0 );
160 if( (--refCount) == 0 )
165 static void deleteItem(ListIteratorType & it)
171 FactoryType :: deleteObject( val.first );
177 template<
class Key,
class Object,
class Factory >
198 return singletonList_;
207 FactoryType :: deleteObject( val.first );
Definition: bindguard.hh:11
static Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:101
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:120
static ListType & singletonList()
Definition: singletonlist.hh:81
static ValueType getObjFromList(const KeyType &key)
Definition: singletonlist.hh:140
Object ObjectType
Definition: singletonlist.hh:58
static void eraseItem(ListIteratorType &it)
Definition: singletonlist.hh:154
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:179
SingletonListStorage()
Definition: singletonlist.hh:186
ListType singletonList_
Definition: singletonlist.hh:183
void deleteItem(const ListIteratorType &it)
Definition: singletonlist.hh:201
~SingletonListStorage()
Definition: singletonlist.hh:190
ListType & singletonList()
Definition: singletonlist.hh:196