|
tesseract 3.04.01
|
#include <object_cache.h>
Classes | |
| struct | ReferenceCount |
Public Member Functions | |
| ObjectCache () | |
| ~ObjectCache () | |
| T * | Get (STRING id, TessResultCallback< T * > *loader) |
| bool | Free (T *t) |
| void | DeleteUnusedObjects () |
Definition at line 35 of file object_cache.h.
| tesseract::ObjectCache< T >::ObjectCache | ( | ) | [inline] |
Definition at line 37 of file object_cache.h.
{}
| tesseract::ObjectCache< T >::~ObjectCache | ( | ) | [inline] |
Definition at line 38 of file object_cache.h.
{
mu_.Lock();
for (int i = 0; i < cache_.size(); i++) {
if (cache_[i].count > 0) {
tprintf("ObjectCache(%p)::~ObjectCache(): WARNING! LEAK! object %p "
"still has count %d (id %s)\n",
this, cache_[i].object, cache_[i].count,
cache_[i].id.string());
} else {
delete cache_[i].object;
cache_[i].object = NULL;
}
}
mu_.Unlock();
}
| void tesseract::ObjectCache< T >::DeleteUnusedObjects | ( | ) | [inline] |
Definition at line 100 of file object_cache.h.
| bool tesseract::ObjectCache< T >::Free | ( | T * | t | ) | [inline] |
Definition at line 86 of file object_cache.h.
{
if (t == NULL) return false;
mu_.Lock();
for (int i = 0; i < cache_.size(); i++) {
if (cache_[i].object == t) {
--cache_[i].count;
mu_.Unlock();
return true;
}
}
mu_.Unlock();
return false;
}
| T* tesseract::ObjectCache< T >::Get | ( | STRING | id, |
| TessResultCallback< T * > * | loader | ||
| ) | [inline] |
Definition at line 60 of file object_cache.h.
{
T *retval = NULL;
mu_.Lock();
for (int i = 0; i < cache_.size(); i++) {
if (id == cache_[i].id) {
retval = cache_[i].object;
if (cache_[i].object != NULL) {
cache_[i].count++;
}
mu_.Unlock();
delete loader;
return retval;
}
}
cache_.push_back(ReferenceCount());
ReferenceCount &rc = cache_.back();
rc.id = id;
retval = rc.object = loader->Run();
rc.count = (retval != NULL) ? 1 : 0;
mu_.Unlock();
return retval;
}