20 #ifndef TESSERACT_CCUTIL_OBJECT_CACHE_H_ 21 #define TESSERACT_CCUTIL_OBJECT_CACHE_H_ 25 #include "genericvector.h" 26 #include "tesscallback.h" 40 for (
int i = 0; i <
cache_.size(); i++) {
42 tprintf(
"ObjectCache(%p)::~ObjectCache(): WARNING! LEAK! object %p " 43 "still has count %d (id %s)\n",
48 cache_[i].object =
nullptr;
64 for (
int i = 0; i <
cache_.size(); i++) {
67 if (
cache_[i].
object !=
nullptr) {
75 cache_.push_back(ReferenceCount());
76 ReferenceCount &rc =
cache_.back();
78 retval = rc.object = loader->
Run();
79 rc.count = (retval !=
nullptr) ? 1 : 0;
87 if (t ==
nullptr)
return false;
89 for (
int i = 0; i <
cache_.size(); i++) {
90 if (
cache_[i].
object == t) {
102 for (
int i =
cache_.size() - 1; i >= 0; i--) {
103 if (
cache_[i].count <= 0) {
125 #endif // TESSERACT_CCUTIL_OBJECT_CACHE_H_
int count
Definition: object_cache.h:115
bool Free(T *t)
Definition: object_cache.h:86
GenericVector< ReferenceCount > cache_
Definition: object_cache.h:119
Definition: tesscallback.h:36
void DeleteUnusedObjects()
Definition: object_cache.h:100
CCUtilMutex mu_
Definition: object_cache.h:118
Definition: baseapi.cpp:94
Definition: object_cache.h:35
~ObjectCache()
Definition: object_cache.h:38
T * Get(STRING id, TessResultCallback< T *> *loader)
Definition: object_cache.h:60
void Lock()
Definition: ccutil.cpp:43
void Unlock()
Definition: ccutil.cpp:51
T * object
Definition: object_cache.h:114
Definition: object_cache.h:112
STRING id
Definition: object_cache.h:113