This utility template class allows clients to store objects of a concrete class derived from Resource in memory. Within resources_ a given resource object id may exist only once.
The class also provides functionality to read/write lock individual objects or the whole list of resources.
Definition at line 78 of file resourcelists.h.
typedef std::list<R> OSB_LIB::ResourceList< R >::List |
typedef RwGuard OSB_LIB::ResourceList< R >::ListRg |
typedef RwGuard OSB_LIB::ResourceList< R >::ListWg |
typedef ReadGuard<R*> OSB_LIB::ResourceList< R >::Rg |
typedef WriteGuard<R*> OSB_LIB::ResourceList< R >::Wg |
enum OSB_LIB::ResourceList::GuardStatus |
Status of issued guards.
success | Success, none of the other values. |
lockFailed | Locking failed. |
objectNotFound | Object not found. |
Definition at line 91 of file resourcelists.h.
OSB_LIB::ResourceList< R >::ResourceList | ( | bool | useLocks | ) | [explicit] |
Constructor with locking flag.
useLocks | Flag if locking should be applied or not. |
Definition at line 607 of file resourcelists.h.
bool OSB_LIB::ResourceList< R >::clear | ( | ) |
Delete all resources from the list.
Definition at line 816 of file resourcelists.h.
References OSB_LIB::RwGuard::locked(), OSB_LIB::ResourceList< R >::resources_, and OSB_LIB::ResourceList< R >::writeLock().
bool OSB_LIB::ResourceList< R >::erase | ( | const Id< Resource > & | id | ) |
Delete a resource from the list.
id | Id of the resource to delete. |
Definition at line 800 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::eraseUnlocked(), OSB_LIB::RwGuard::locked(), and OSB_LIB::ResourceList< R >::writeLock().
void OSB_LIB::ResourceList< R >::eraseUnlocked | ( | const Id< Resource > & | id | ) | [private] |
Delete a resource from the list without locking.
id | Id of the resource to delete. |
Definition at line 809 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::findIter(), and OSB_LIB::ResourceList< R >::resources_.
Referenced by OSB_LIB::ResourceList< R >::erase(), and OSB_LIB::ResourceList< R >::replaceUnlocked().
const R * OSB_LIB::ResourceList< R >::find | ( | const Id< Resource > & | id, | |
bool | doThrow | |||
) | const |
Find a resource object by it's id.
id | Id of the resource to search. | |
doThrow | Flag to throw if the resource is not found. |
OsbException | if doThrow is true and the resource is not found. |
Definition at line 652 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::find().
R * OSB_LIB::ResourceList< R >::find | ( | const Id< Resource > & | id, | |
bool | doThrow | |||
) |
Find a resource object by it's id.
id | Id of the resource to search. | |
doThrow | Flag to throw if the resource is not found. |
OsbException | if doThrow is true and the resource is not found. |
Definition at line 635 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::findIter(), and OSB_LIB::ResourceList< R >::resources_.
Referenced by OSB_LIB::ResourceList< R >::find(), OSB_LIB::ResourceList< R >::insert(), OSB_LIB::ResourceList< R >::readLock(), OSB_LIB::ResourceList< R >::replaceUnlocked(), and OSB_LIB::ResourceList< R >::writeLock().
ResourceList< R >::List::iterator OSB_LIB::ResourceList< R >::findIter | ( | const Id< Resource > & | id | ) | [private] |
Get an iterator to a resource object.
id | Id of the resource to find. |
Definition at line 621 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::resources_.
Referenced by OSB_LIB::ResourceList< R >::eraseUnlocked(), and OSB_LIB::ResourceList< R >::find().
bool OSB_LIB::ResourceList< R >::greaterResNum | ( | const R & | lhs, | |
const R & | rhs | |||
) | [static, private] |
Compare two resources by their resource number.
lhs | One resource. | |
rhs | The other resource. |
Definition at line 833 of file resourcelists.h.
Referenced by OSB_LIB::ResourceList< R >::sortByResNum().
bool OSB_LIB::ResourceList< R >::insert | ( | const R & | r | ) |
Insert a resource to the list.
r | Resource to insert. |
Definition at line 755 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::find(), OSB_LIB::RwGuard::locked(), OSB_LIB::ResourceList< R >::resources_, and OSB_LIB::ResourceList< R >::writeLock().
bool OSB_LIB::ResourceList< R >::lessResNum | ( | const R & | lhs, | |
const R & | rhs | |||
) | [static, private] |
Compare two resources by their resource number.
lhs | One resource. | |
rhs | The other resource. |
Definition at line 825 of file resourcelists.h.
Referenced by OSB_LIB::ResourceList< R >::sortByResNum().
ResourceList< R >::ListRg OSB_LIB::ResourceList< R >::readLock | ( | ) | const |
Read-lock the whole list of resources.
Definition at line 724 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::mutex_, OSB_LIB::RwMutex::readLock(), OSB_LIB::RwMutex::readUnlock(), and OSB_LIB::ResourceList< R >::useLocks_.
ResourceList< R >::Rg OSB_LIB::ResourceList< R >::readLock | ( | const Id< Resource > & | id, | |
bool | doThrow | |||
) | const |
Read-lock a resource object.
id | Id of the resource to lock. | |
doThrow | Flag to throw if the resource is not found. |
OsbException | if doThrow is true and the resource is not found. |
Definition at line 662 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::find(), OSB_LIB::ResourceList< R >::lockFailed, OSB_LIB::ResourceList< R >::mutex_, OSB_LIB::ResourceList< R >::objectNotFound, OSB_LIB::RwMutex::readLock(), and OSB_LIB::ResourceList< R >::useLocks_.
bool OSB_LIB::ResourceList< R >::replace | ( | const ResourceList< R > & | src | ) |
Replace resources in the list.
src | List of resource to replace. |
Definition at line 768 of file resourcelists.h.
References OSB_LIB::RwGuard::locked(), OSB_LIB::ResourceList< R >::replaceUnlocked(), OSB_LIB::ResourceList< R >::resources_, and OSB_LIB::ResourceList< R >::writeLock().
bool OSB_LIB::ResourceList< R >::replace | ( | const R & | r | ) |
Replace a resource in the list.
r | Resource to replace. |
Definition at line 781 of file resourcelists.h.
References OSB_LIB::RwGuard::locked(), OSB_LIB::ResourceList< R >::replaceUnlocked(), and OSB_LIB::ResourceList< R >::writeLock().
void OSB_LIB::ResourceList< R >::replaceUnlocked | ( | const R & | r | ) | [private] |
Replace a resource in the list without locking.
r | Resource to replace. |
Definition at line 790 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::eraseUnlocked(), OSB_LIB::ResourceList< R >::find(), and OSB_LIB::ResourceList< R >::resources_.
Referenced by OSB_LIB::ResourceList< R >::replace().
void OSB_LIB::ResourceList< R >::sortByResNum | ( | bool | desc = false |
) |
Sort resource lists by name.
desc | Flag to sort in descending (true) or ascending (false) order. |
Definition at line 841 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::greaterResNum(), OSB_LIB::ResourceList< R >::lessResNum(), and OSB_LIB::ResourceList< R >::resources_.
bool OSB_LIB::ResourceList< R >::useLocks | ( | ) | const |
Locks applicable?
Definition at line 614 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::useLocks_.
ResourceList< R >::ListWg OSB_LIB::ResourceList< R >::writeLock | ( | ) |
Write-lock the whole list of resources.
Definition at line 740 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::mutex_, OSB_LIB::ResourceList< R >::useLocks_, OSB_LIB::RwMutex::writeLock(), and OSB_LIB::RwMutex::writeUnlock().
Referenced by OSB_LIB::ResourceList< R >::clear(), OSB_LIB::ResourceList< R >::erase(), OSB_LIB::ResourceList< R >::insert(), and OSB_LIB::ResourceList< R >::replace().
ResourceList< R >::Wg OSB_LIB::ResourceList< R >::writeLock | ( | const Id< Resource > & | id, | |
bool | doThrow | |||
) |
Write-lock a resource object.
id | Id of the resource to lock. | |
doThrow | Flag to throw if the resource is not found. |
OsbException | if doThrow is true and the resource is not found. |
Definition at line 693 of file resourcelists.h.
References OSB_LIB::ResourceList< R >::find(), OSB_LIB::ResourceList< R >::lockFailed, OSB_LIB::ResourceList< R >::mutex_, OSB_LIB::ResourceList< R >::objectNotFound, OSB_LIB::ResourceList< R >::useLocks_, and OSB_LIB::RwMutex::writeLock().
RwMutex OSB_LIB::ResourceList< R >::mutex_ [mutable, private] |
Mutex to lock the whole list.
Definition at line 265 of file resourcelists.h.
Referenced by OSB_LIB::ResourceList< R >::readLock(), and OSB_LIB::ResourceList< R >::writeLock().
List OSB_LIB::ResourceList< R >::resources_ |
List with the resource objects.
This member is public, if applicable clients are responsible to aquire the necessary lock before accessing it.
Definition at line 113 of file resourcelists.h.
Referenced by OSB_LIB::ResourceList< R >::clear(), OSB_LIB::ResourceList< R >::eraseUnlocked(), OSB_LIB::ResourceList< R >::find(), OSB_LIB::ResourceList< R >::findIter(), OSB_LIB::ResourceList< R >::insert(), OSB_LIB::ResourceList< R >::replace(), OSB_LIB::ResourceList< R >::replaceUnlocked(), and OSB_LIB::ResourceList< R >::sortByResNum().
bool OSB_LIB::ResourceList< R >::useLocks_ [private] |
Flag if locking should be applied.
Definition at line 263 of file resourcelists.h.
Referenced by OSB_LIB::ResourceList< R >::readLock(), OSB_LIB::ResourceList< R >::useLocks(), and OSB_LIB::ResourceList< R >::writeLock().