diff --git a/src/ccutil/object_cache.h b/src/ccutil/object_cache.h index c03f9140..1ff459ba 100644 --- a/src/ccutil/object_cache.h +++ b/src/ccutil/object_cache.h @@ -2,7 +2,6 @@ // File: object_cache.h // Description: A string indexed object cache. // Author: David Eger -// Created: Fri Jan 27 12:08:00 PST 2012 // // (C) Copyright 2012, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +19,10 @@ #ifndef TESSERACT_CCUTIL_OBJECT_CACHE_H_ #define TESSERACT_CCUTIL_OBJECT_CACHE_H_ +#include // for std::function #include "ccutil.h" #include "errcode.h" #include "genericvector.h" -#include "tesscallback.h" namespace tesseract { @@ -57,8 +56,7 @@ class ObjectCache { // and return nullptr -- further attempts to load will fail (even // with a different loader) until DeleteUnusedObjects() is called. // We delete the given loader. - T *Get(STRING id, - TessResultCallback *loader) { + T* Get(STRING id, std::function loader) { T *retval = nullptr; mu_.Lock(); for (int i = 0; i < cache_.size(); i++) { @@ -68,14 +66,13 @@ class ObjectCache { 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(); + retval = rc.object = loader(); rc.count = (retval != nullptr) ? 1 : 0; mu_.Unlock(); return retval; diff --git a/src/dict/dawg_cache.cpp b/src/dict/dawg_cache.cpp index ea24c0df..d79c5bd4 100644 --- a/src/dict/dawg_cache.cpp +++ b/src/dict/dawg_cache.cpp @@ -2,7 +2,6 @@ // File: dawg_cache.cpp // Description: A class that knows about loading and caching dawgs. // Author: David Eger -// Created: Fri Jan 27 12:08:00 PST 2012 // // (C) Copyright 2012, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -48,7 +47,7 @@ Dawg *DawgCache::GetSquishedDawg(const STRING &lang, STRING data_id = data_file->GetDataFileName(); data_id += kTessdataFileSuffixes[tessdata_dawg_type]; DawgLoader loader(lang, tessdata_dawg_type, debug_level, data_file); - return dawgs_.Get(data_id, NewTessCallback(&loader, &DawgLoader::Load)); + return dawgs_.Get(data_id, std::bind(&DawgLoader::Load, &loader)); } Dawg *DawgLoader::Load() {