19 #ifndef TESSERACT_CCUTIL_OBJECT_CACHE_H_
20 #define TESSERACT_CCUTIL_OBJECT_CACHE_H_
39 std::lock_guard<std::mutex> guard(mu_);
40 for (
int i = 0; i < cache_.
size(); i++) {
41 if (cache_[i].
count > 0) {
42 tprintf(
"ObjectCache(%p)::~ObjectCache(): WARNING! LEAK! object %p "
43 "still has count %d (id %s)\n",
44 this, cache_[i].
object, cache_[i].
count,
45 cache_[i].
id.c_str());
47 delete cache_[i].object;
48 cache_[i].object =
nullptr;
61 std::lock_guard<std::mutex> guard(mu_);
62 for (
int i = 0; i < cache_.
size(); i++) {
63 if (
id == cache_[i].
id) {
64 retval = cache_[i].object;
65 if (cache_[i].
object !=
nullptr) {
72 ReferenceCount &rc = cache_.
back();
74 retval = rc.object = loader();
75 rc.count = (retval !=
nullptr) ? 1 : 0;
82 if (t ==
nullptr)
return false;
83 std::lock_guard<std::mutex> guard(mu_);
84 for (
int i = 0; i < cache_.
size(); i++) {
85 if (cache_[i].
object == t) {
94 std::lock_guard<std::mutex> guard(mu_);
95 for (
int i = cache_.
size() - 1; i >= 0; i--) {
96 if (cache_[i].
count <= 0) {
97 delete cache_[i].object;
104 struct ReferenceCount {
117 #endif // TESSERACT_CCUTIL_OBJECT_CACHE_H_