1 #ifndef DUNE_FEM_SINGLETONLIST_HH 2 #define DUNE_FEM_SINGLETONLIST_HH 20 template<
class Key,
class Object >
25 return new Object( key );
47 template<
class Key,
class Object,
58 typedef std :: pair< ObjectType * , unsigned int * >
ValueType;
62 typedef std :: list< ListObjType > ListType;
63 typedef typename ListType :: iterator ListIteratorType;
89 inline static ObjectType &
getObject(
const KeyType &key )
94 ValueType objValue = getObjFromList( key );
99 ++( *(objValue.second) );
100 return *(objValue.first);
104 ObjectType *
object = FactoryType :: createObject( key );
106 ValueType value(
object,
new unsigned int( 1 ) );
107 ListObjType tmp( key, value );
108 singletonList().push_back( tmp );
119 ListIteratorType end = singletonList().end();
120 for( ListIteratorType it = singletonList().begin(); it != end; ++it )
122 if( (*it).second.first == &
object )
129 std :: cerr <<
"Object could not be deleted, " 130 <<
"because it is not in the list anymore!" << std :: endl;
136 ListIteratorType endit = singletonList().end();
137 for(ListIteratorType it = singletonList().begin(); it!=endit; ++it)
139 if( (*it).first == key )
144 return ValueType( (ObjectType *)0, (
unsigned int *)0 );
150 ValueType value = (*it).second;
151 unsigned int &refCount = *(value.second);
153 assert( refCount > 0 );
154 if( (--refCount) == 0 )
159 static void deleteItem(ListIteratorType & it)
161 ValueType val = (*it).second;
163 singletonList().erase( it );
165 FactoryType :: deleteObject( val.first );
171 template<
class Key,
class Object,
class Factory >
186 while( !singletonList().empty() )
187 deleteItem( singletonList().begin() );
192 return singletonList_;
199 singletonList().erase( it );
201 FactoryType :: deleteObject( val.first );
210 #endif // #ifndef DUNE_FEM_SINGLETONLIST_HH
std::pair< KeyType, ValueType > ListObjType
Definition: singletonlist.hh:59
Key KeyType
Definition: singletonlist.hh:54
std::pair< ObjectType *, unsigned int * > ValueType
Definition: singletonlist.hh:58
Factory FactoryType
Definition: singletonlist.hh:56
Singleton list for key/object pairs.
Definition: singletonlist.hh:49
void deleteItem(const ListIteratorType &it)
Definition: singletonlist.hh:195
static Object * createObject(const Key &key)
Definition: singletonlist.hh:23
static ListType & singletonList()
Definition: singletonlist.hh:77
Definition: coordinate.hh:4
static void deleteObject(Object *object)
Definition: singletonlist.hh:28
static void eraseItem(ListIteratorType &it)
Definition: singletonlist.hh:148
static void removeObject(const ObjectType &object)
Definition: singletonlist.hh:114
static ObjectType & getObject(const KeyType &key)
Definition: singletonlist.hh:89
SingletonListStorage()
Definition: singletonlist.hh:180
ListType & singletonList()
Definition: singletonlist.hh:190
static ValueType getObjFromList(const KeyType &key)
Definition: singletonlist.hh:134
Definition: singletonlist.hh:172
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:217
~SingletonListStorage()
Definition: singletonlist.hh:184
Definition: singletonlist.hh:21
Object ObjectType
Definition: singletonlist.hh:55
ListType singletonList_
Definition: singletonlist.hh:177