mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-12 07:29:07 +08:00
Use C++-11 code instead of TessCallback for function set_compare_callback
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
ffd8101986
commit
242e1db7fa
@ -430,8 +430,9 @@ void Tesseract::SetupUniversalFontIds() {
|
||||
// Note that we can get away with bitwise copying FontInfo in
|
||||
// all_fonts, as it is a temporary structure and we avoid setting the
|
||||
// delete callback.
|
||||
using namespace std::placeholders; // for _1, _2
|
||||
UnicityTable<FontInfo> all_fonts;
|
||||
all_fonts.set_compare_callback(NewPermanentTessCallback(CompareFontInfo));
|
||||
all_fonts.set_compare_callback(std::bind(CompareFontInfo, _1, _2));
|
||||
|
||||
// Create the universal ID table.
|
||||
CollectFonts(get_fontinfo_table(), &all_fonts);
|
||||
|
@ -37,8 +37,8 @@ bool FontInfo::DeSerialize(TFile* fp) {
|
||||
}
|
||||
|
||||
FontInfoTable::FontInfoTable() {
|
||||
using namespace std::placeholders; // for _1
|
||||
set_compare_callback(NewPermanentTessCallback(CompareFontInfo));
|
||||
using namespace std::placeholders; // for _1, _2
|
||||
set_compare_callback(std::bind(CompareFontInfo, _1, _2));
|
||||
set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
|
||||
}
|
||||
|
||||
@ -83,8 +83,8 @@ bool FontInfoTable::SetContainsMultipleFontProperties(
|
||||
|
||||
// Moves any non-empty FontSpacingInfo entries from other to this.
|
||||
void FontInfoTable::MoveSpacingInfoFrom(FontInfoTable* other) {
|
||||
set_compare_callback(NewPermanentTessCallback(CompareFontInfo));
|
||||
using namespace std::placeholders; // for _1
|
||||
using namespace std::placeholders; // for _1, _2
|
||||
set_compare_callback(std::bind(CompareFontInfo, _1, _2));
|
||||
set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
|
||||
for (int i = 0; i < other->size(); ++i) {
|
||||
GenericVector<FontSpacingInfo*>* spacing_vec = other->get(i).spacing_vec;
|
||||
@ -106,8 +106,8 @@ void FontInfoTable::MoveSpacingInfoFrom(FontInfoTable* other) {
|
||||
// Moves this to the target unicity table.
|
||||
void FontInfoTable::MoveTo(UnicityTable<FontInfo>* target) {
|
||||
target->clear();
|
||||
target->set_compare_callback(NewPermanentTessCallback(CompareFontInfo));
|
||||
using namespace std::placeholders; // for _1
|
||||
using namespace std::placeholders; // for _1, _2
|
||||
target->set_compare_callback(std::bind(CompareFontInfo, _1, _2));
|
||||
target->set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
// Bit copy the FontInfo and steal all the pointers.
|
||||
|
@ -147,7 +147,7 @@ class GenericVector {
|
||||
|
||||
// Add a callback to be called to compare the elements when needed (contains,
|
||||
// get_id, ...)
|
||||
void set_compare_callback(TessResultCallback2<bool, T const&, T const&>* cb) {
|
||||
void set_compare_callback(std::function<bool(const T&, const T&)> cb) {
|
||||
compare_cb_ = cb;
|
||||
}
|
||||
|
||||
@ -336,8 +336,7 @@ class GenericVector {
|
||||
int32_t size_reserved_{};
|
||||
T* data_;
|
||||
std::function<void(T)> clear_cb_;
|
||||
// Mutable because Run method is not const
|
||||
mutable TessResultCallback2<bool, T const&, T const&>* compare_cb_;
|
||||
std::function<bool(const T&, const T&)> compare_cb_;
|
||||
};
|
||||
|
||||
namespace tesseract {
|
||||
@ -669,12 +668,14 @@ template <typename T>
|
||||
class GenericVectorEqEq : public GenericVector<T> {
|
||||
public:
|
||||
GenericVectorEqEq() {
|
||||
using namespace std::placeholders; // for _1
|
||||
GenericVector<T>::set_compare_callback(
|
||||
NewPermanentTessCallback(tesseract::cmp_eq<T>));
|
||||
std::bind(tesseract::cmp_eq<T>, _1, _2));
|
||||
}
|
||||
explicit GenericVectorEqEq(int size) : GenericVector<T>(size) {
|
||||
using namespace std::placeholders; // for _1
|
||||
GenericVector<T>::set_compare_callback(
|
||||
NewPermanentTessCallback(tesseract::cmp_eq<T>));
|
||||
std::bind(tesseract::cmp_eq<T>, _1, _2));
|
||||
}
|
||||
};
|
||||
|
||||
@ -808,7 +809,7 @@ template <typename T>
|
||||
int GenericVector<T>::get_index(const T& object) const {
|
||||
for (int i = 0; i < size_used_; ++i) {
|
||||
assert(compare_cb_ != nullptr);
|
||||
if (compare_cb_->Run(object, data_[i])) {
|
||||
if (compare_cb_(object, data_[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -892,7 +893,6 @@ void GenericVector<T>::clear() {
|
||||
size_used_ = 0;
|
||||
size_reserved_ = 0;
|
||||
clear_cb_ = nullptr;
|
||||
delete compare_cb_;
|
||||
compare_cb_ = nullptr;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,10 @@ class UnicityTable {
|
||||
|
||||
/// Add a callback to be called to compare the elements when needed (contains,
|
||||
/// get_id, ...)
|
||||
void set_compare_callback(TessResultCallback2<bool, T const &, T const &>* cb);
|
||||
void set_compare_callback(std::function<bool(const T&, const T&)> cb) {
|
||||
table_.set_compare_callback(cb);
|
||||
compare_cb_ = cb;
|
||||
}
|
||||
|
||||
/// Clear the table, calling the callback function if any.
|
||||
/// All the owned Callbacks are also deleted.
|
||||
@ -93,16 +96,16 @@ class UnicityTable {
|
||||
|
||||
private:
|
||||
GenericVector<T> table_;
|
||||
// Mutable because Run method is not const
|
||||
mutable TessResultCallback2<bool, T const &, T const &>* compare_cb_;
|
||||
std::function<bool(const T&, const T&)> compare_cb_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class UnicityTableEqEq : public UnicityTable<T> {
|
||||
public:
|
||||
UnicityTableEqEq() {
|
||||
using namespace std::placeholders; // for _1, _2
|
||||
UnicityTable<T>::set_compare_callback(
|
||||
NewPermanentTessCallback(tesseract::cmp_eq<T>));
|
||||
std::bind(tesseract::cmp_eq<T>, _1, _2));
|
||||
}
|
||||
};
|
||||
|
||||
@ -167,14 +170,6 @@ int UnicityTable<T>::push_back(T object) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
// Add a callback to be called to delete the elements when the table took
|
||||
// their ownership.
|
||||
template <typename T>
|
||||
void UnicityTable<T>::set_compare_callback(TessResultCallback2<bool, T const &, T const &>* cb) {
|
||||
table_.set_compare_callback(cb);
|
||||
compare_cb_ = cb;
|
||||
}
|
||||
|
||||
// Clear the table, calling the callback function if any.
|
||||
template <typename T>
|
||||
void UnicityTable<T>::clear() {
|
||||
|
@ -186,12 +186,10 @@ Classify::Classify()
|
||||
shape_table_(nullptr),
|
||||
dict_(this),
|
||||
static_classifier_(nullptr) {
|
||||
using namespace std::placeholders; // for _1
|
||||
fontinfo_table_.set_compare_callback(
|
||||
NewPermanentTessCallback(CompareFontInfo));
|
||||
using namespace std::placeholders; // for _1, _2
|
||||
fontinfo_table_.set_compare_callback(std::bind(CompareFontInfo, _1, _2));
|
||||
fontinfo_table_.set_clear_callback(std::bind(FontInfoDeleteCallback, _1));
|
||||
fontset_table_.set_compare_callback(
|
||||
NewPermanentTessCallback(CompareFontSet));
|
||||
fontset_table_.set_compare_callback(std::bind(CompareFontSet, _1, _2));
|
||||
fontset_table_.set_clear_callback(std::bind(FontSetDeleteCallback, _1));
|
||||
AdaptedTemplates = nullptr;
|
||||
BackupAdaptedTemplates = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user