Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make list classes templated #4356

Merged
merged 17 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,6 @@ endif
noinst_LTLIBRARIES += libtesseract_ccutil.la

libtesseract_ccutil_la_SOURCES = src/ccutil/ccutil.cpp
libtesseract_ccutil_la_SOURCES += src/ccutil/clst.cpp
libtesseract_ccutil_la_SOURCES += src/ccutil/elst2.cpp
libtesseract_ccutil_la_SOURCES += src/ccutil/elst.cpp
libtesseract_ccutil_la_SOURCES += src/ccutil/errcode.cpp
libtesseract_ccutil_la_SOURCES += src/ccutil/serialis.cpp
libtesseract_ccutil_la_SOURCES += src/ccutil/scanutils.cpp
Expand Down
7 changes: 2 additions & 5 deletions src/ccmain/fixspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ class ROW;
**********************************************************************/

static int c_blob_comparator( // sort blobs
const void *blob1p, // ptr to ptr to blob1
const void *blob2p // ptr to ptr to blob2
const C_BLOB *blob1,
const C_BLOB *blob2
) {
const C_BLOB *blob1 = *reinterpret_cast<const C_BLOB *const *>(blob1p);
const C_BLOB *blob2 = *reinterpret_cast<const C_BLOB *const *>(blob2p);

return blob1->bounding_box().left() - blob2->bounding_box().left();
}

Expand Down
4 changes: 1 addition & 3 deletions src/ccmain/paramsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ void ParamsEditor::GetPrefixes(const char *s, std::string *level_one, std::strin
}

// Compare two VC objects by their name.
int ParamContent::Compare(const void *v1, const void *v2) {
const ParamContent *one = *static_cast<const ParamContent *const *>(v1);
const ParamContent *two = *static_cast<const ParamContent *const *>(v2);
int ParamContent::Compare(const ParamContent *one, const ParamContent *two) {
return strcmp(one->GetName(), two->GetName());
}

Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/paramsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ enum ParamType { VT_INTEGER, VT_BOOLEAN, VT_STRING, VT_DOUBLE };
// comparisond or getting its value. It is used in the context of the
// ParamsEditor as a bridge from the internal tesseract parameters to the
// ones displayed by the ScrollView server.
class ParamContent : public ELIST_LINK {
class ParamContent : public ELIST<ParamContent>::LINK {
public:
// Compare two VC objects by their name.
static int Compare(const void *v1, const void *v2);
static int Compare(const ParamContent *v1, const ParamContent *v2);

// Gets a VC object identified by its ID.
static ParamContent *GetParamContentById(int id);
Expand Down
6 changes: 3 additions & 3 deletions src/ccstruct/blobbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ColPartition;

class BLOBNBOX;
ELISTIZEH(BLOBNBOX)
class BLOBNBOX : public ELIST_LINK {
class BLOBNBOX : public ELIST<BLOBNBOX>::LINK {
public:
BLOBNBOX() {
ReInit();
Expand Down Expand Up @@ -552,7 +552,7 @@ class BLOBNBOX : public ELIST_LINK {
bool owns_cblob_ = false;
};

class TO_ROW : public ELIST2_LINK {
class TO_ROW : public ELIST2<TO_ROW>::LINK {
public:
static const int kErrorWeight = 3;

Expand Down Expand Up @@ -695,7 +695,7 @@ class TO_ROW : public ELIST2_LINK {
};

ELIST2IZEH(TO_ROW)
class TESS_API TO_BLOCK : public ELIST_LINK {
class TESS_API TO_BLOCK : public ELIST<TO_BLOCK>::LINK {
public:
TO_BLOCK() : pitch_decision(PITCH_DUNNO) {
clear();
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/coutln.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct EdgeOffset {
class C_OUTLINE; // forward declaration

ELISTIZEH(C_OUTLINE)
class C_OUTLINE : public ELIST_LINK {
class C_OUTLINE : public ELIST<C_OUTLINE>::LINK {
public:
C_OUTLINE() {
stepcount = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/ccstruct/ocrblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ BLOCK::BLOCK(const char *name, ///< filename
* Sort Comparator: Return <0 if row1 top < row2 top
*/

static int decreasing_top_order(const void *row1, const void *row2) {
return (*reinterpret_cast<ROW *const *>(row2))->bounding_box().top() -
(*reinterpret_cast<ROW *const *>(row1))->bounding_box().top();
static int decreasing_top_order(const ROW *row1, const ROW *row2) {
return row2->bounding_box().top() -
row1->bounding_box().top();
}

/**
Expand Down Expand Up @@ -222,7 +222,7 @@ void BLOCK::print( // print list of sides
BLOCK &BLOCK::operator=( // assignment
const BLOCK &source // from this
) {
this->ELIST_LINK::operator=(source);
this->ELIST<BLOCK>::LINK::operator=(source);
pdblk = source.pdblk;
proportional = source.proportional;
kerning = source.kerning;
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/ocrblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BLOCK; // forward decl

ELISTIZEH(BLOCK)

class TESS_API BLOCK : public ELIST_LINK
class TESS_API BLOCK : public ELIST<BLOCK>::LINK
// page block
{
friend class BLOCK_RECT_IT; // block iterator
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/ocrpara.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace tesseract {

class ParagraphModel;

struct PARA : public ELIST_LINK {
struct PARA : public ELIST<PARA>::LINK {
public:
PARA()
: model(nullptr)
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/ocrrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void ROW::plot( // draw it
**********************************************************************/

ROW &ROW::operator=(const ROW &source) {
this->ELIST_LINK::operator=(source);
this->ELIST<ROW>::LINK::operator=(source);
kerning = source.kerning;
spacing = source.spacing;
xheight = source.xheight;
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/ocrrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TO_ROW;

struct PARA;

class ROW : public ELIST_LINK {
class ROW : public ELIST<ROW>::LINK {
friend void tweak_row_baseline(ROW *, double, double);

public:
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/pageres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ROW_RES::ROW_RES(bool merge_similar_words, ROW *the_row) {
}

WERD_RES &WERD_RES::operator=(const WERD_RES &source) {
this->ELIST_LINK::operator=(source);
this->ELIST<WERD_RES>::LINK::operator=(source);
Clear();
if (source.combination) {
word = new WERD;
Expand Down
8 changes: 4 additions & 4 deletions src/ccstruct/pageres.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PAGE_RES { // page result
* BLOCK_RES - Block results
*************************************************************************/

class BLOCK_RES : public ELIST_LINK {
class BLOCK_RES : public ELIST<BLOCK_RES>::LINK {
public:
BLOCK *block; // real block
int32_t char_count; // chars in block
Expand All @@ -139,7 +139,7 @@ class BLOCK_RES : public ELIST_LINK {
* ROW_RES - Row results
*************************************************************************/

class ROW_RES : public ELIST_LINK {
class ROW_RES : public ELIST<ROW_RES>::LINK {
public:
ROW *row; // real row
int32_t char_count; // chars in block
Expand All @@ -161,7 +161,7 @@ enum CRUNCH_MODE { CR_NONE, CR_KEEP_SPACE, CR_LOOSE_SPACE, CR_DELETE };

// WERD_RES is a collection of publicly accessible members that gathers
// information about a word result.
class TESS_API WERD_RES : public ELIST_LINK {
class TESS_API WERD_RES : public ELIST<WERD_RES>::LINK {
public:
// Which word is which?
// There are 3 coordinate spaces in use here: a possibly rotated pixel space,
Expand Down Expand Up @@ -345,7 +345,7 @@ class TESS_API WERD_RES : public ELIST_LINK {
}
// Deep copies everything except the ratings MATRIX.
// To get that use deep_copy below.
WERD_RES(const WERD_RES &source) : ELIST_LINK(source) {
WERD_RES(const WERD_RES &source) : ELIST<WERD_RES>::LINK(source) {
// combination is used in function Clear which is called from operator=.
combination = false;
*this = source; // see operator=
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/points.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class ICOORD {
TDimension ycoord; ///< y value
};

class ICOORDELT : public ELIST_LINK,
class ICOORDELT : public ELIST<ICOORDELT>::LINK,
public ICOORD
// embedded coord list
{
Expand Down
7 changes: 2 additions & 5 deletions src/ccstruct/polyblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace tesseract {

#define INTERSECTING INT16_MAX

int lessthan(const void *first, const void *second);
int lessthan(const ICOORDELT *first, const ICOORDELT *second);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int lessthan(const ICOORDELT *first, const ICOORDELT *second);
static int lessthan(const ICOORDELT *first, const ICOORDELT *second);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll reconsider those functions. Maybe change to lambdas one-use funcs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be fine for if this is done later. If you want, the PR can be merged as soon as the missing include statements which currently break my local build were added. Should we squash the commits, or do you prefer to keep them all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR has 2-3 unrelated tiny fixes around msvc warnings, sw build.

Not sure what is better here.
I'd prefer to keep separate commits because of separate changes to each of three lists.


POLY_BLOCK::POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType t) {
ICOORDELT_IT v = &vertices;
Expand Down Expand Up @@ -371,10 +371,7 @@ ICOORDELT_LIST *PB_LINE_IT::get_line(TDimension y) {
return result;
}

int lessthan(const void *first, const void *second) {
const ICOORDELT *p1 = *reinterpret_cast<const ICOORDELT *const *>(first);
const ICOORDELT *p2 = *reinterpret_cast<const ICOORDELT *const *>(second);

int lessthan(const ICOORDELT *p1, const ICOORDELT *p2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int lessthan(const ICOORDELT *p1, const ICOORDELT *p2) {
static int lessthan(const ICOORDELT *p1, const ICOORDELT *p2) {

if (p1->x() < p2->x()) {
return (-1);
} else if (p1->x() > p2->x()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ccstruct/ratngs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BLOB_CHOICE::BLOB_CHOICE(UNICHAR_ID src_unichar_id, // character id
*
* Constructor to build a BLOB_CHOICE from another BLOB_CHOICE.
*/
BLOB_CHOICE::BLOB_CHOICE(const BLOB_CHOICE &other) : ELIST_LINK(other) {
BLOB_CHOICE::BLOB_CHOICE(const BLOB_CHOICE &other) : ELIST<BLOB_CHOICE>::LINK(other) {
unichar_id_ = other.unichar_id();
rating_ = other.rating();
certainty_ = other.certainty();
Expand All @@ -129,7 +129,7 @@ BLOB_CHOICE::BLOB_CHOICE(const BLOB_CHOICE &other) : ELIST_LINK(other) {

// Copy assignment operator.
BLOB_CHOICE &BLOB_CHOICE::operator=(const BLOB_CHOICE &other) {
ELIST_LINK::operator=(other);
ELIST<BLOB_CHOICE>::LINK::operator=(other);
unichar_id_ = other.unichar_id();
rating_ = other.rating();
certainty_ = other.certainty();
Expand Down
6 changes: 3 additions & 3 deletions src/ccstruct/ratngs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum BlobChoiceClassifier {
BCC_FAKE, // From some other process.
};

class BLOB_CHOICE : public ELIST_LINK {
class BLOB_CHOICE : public ELIST<BLOB_CHOICE>::LINK {
public:
BLOB_CHOICE() {
unichar_id_ = UNICHAR_SPACE;
Expand Down Expand Up @@ -255,7 +255,7 @@ enum ScriptPos { SP_NORMAL, SP_SUBSCRIPT, SP_SUPERSCRIPT, SP_DROPCAP };

const char *ScriptPosToString(ScriptPos script_pos);

class TESS_API WERD_CHOICE : public ELIST_LINK {
class TESS_API WERD_CHOICE : public ELIST<WERD_CHOICE>::LINK {
public:
static const float kBadRating;
static const char *permuter_name(uint8_t permuter);
Expand All @@ -272,7 +272,7 @@ class TESS_API WERD_CHOICE : public ELIST_LINK {
this->init(src_string, src_lengths, src_rating, src_certainty, src_permuter);
}
WERD_CHOICE(const char *src_string, const UNICHARSET &unicharset);
WERD_CHOICE(const WERD_CHOICE &word) : ELIST_LINK(word), unicharset_(word.unicharset_) {
WERD_CHOICE(const WERD_CHOICE &word) : ELIST<WERD_CHOICE>::LINK(word), unicharset_(word.unicharset_) {
this->init(word.length());
this->operator=(word);
}
Expand Down
7 changes: 2 additions & 5 deletions src/ccstruct/stepblob.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class C_BLOB;
class DENORM;

ELISTIZEH(C_BLOB)

class TESS_API C_BLOB : public ELIST_LINK {
class TESS_API C_BLOB : public ELIST<C_BLOB>::LINK {
public:
C_BLOB() = default;
explicit C_BLOB(C_OUTLINE_LIST *outline_list);
Expand Down Expand Up @@ -121,9 +120,7 @@ class TESS_API C_BLOB : public ELIST_LINK {
return blob;
}

static int SortByXMiddle(const void *v1, const void *v2) {
const C_BLOB *blob1 = *static_cast<const C_BLOB *const *>(v1);
const C_BLOB *blob2 = *static_cast<const C_BLOB *const *>(v2);
static int SortByXMiddle(const C_BLOB *blob1, const C_BLOB *blob2) {
return blob1->bounding_box().x_middle() - blob2->bounding_box().x_middle();
}

Expand Down
6 changes: 2 additions & 4 deletions src/ccstruct/werd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ WERD *WERD::shallow_copy() {
*/

WERD &WERD::operator=(const WERD &source) {
this->ELIST2_LINK::operator=(source);
this->ELIST2<WERD>::LINK::operator=(source);
blanks = source.blanks;
flags = source.flags;
script_id_ = source.script_id_;
Expand All @@ -374,9 +374,7 @@ WERD &WERD::operator=(const WERD &source) {
* order of left edge.
*/

int word_comparator(const void *word1p, const void *word2p) {
const WERD *word1 = *reinterpret_cast<const WERD *const *>(word1p);
const WERD *word2 = *reinterpret_cast<const WERD *const *>(word2p);
int word_comparator(const WERD *word1, const WERD *word2) {
return word1->bounding_box().left() - word2->bounding_box().left();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ccstruct/werd.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum DISPLAY_FLAGS {

class ROW; // forward decl

class TESS_API WERD : public ELIST2_LINK {
class TESS_API WERD : public ELIST2<WERD>::LINK {
public:
WERD() = default;
// WERD constructed with:
Expand Down Expand Up @@ -205,7 +205,7 @@ ELIST2IZEH(WERD)
namespace tesseract {

// compare words by increasing order of left edge, suitable for qsort(3)
int word_comparator(const void *word1p, const void *word2p);
int word_comparator(const WERD *word1, const WERD *word2);

} // namespace tesseract

Expand Down
6 changes: 2 additions & 4 deletions src/ccutil/ambigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ class UnicharIdArrayUtils {

// AMBIG_SPEC_LIST stores a list of dangerous ambigs that
// start with the same unichar (e.g. r->t rn->m rr1->m).
class AmbigSpec : public ELIST_LINK {
class AmbigSpec : public ELIST<AmbigSpec>::LINK {
public:
AmbigSpec();
~AmbigSpec() = default;

// Comparator function for sorting AmbigSpec_LISTs. The lists will
// be sorted by their wrong_ngram arrays. Example of wrong_ngram vectors
// in a sorted AmbigSpec_LIST: [9 1 3], [9 3 4], [9 8], [9, 8 1].
static int compare_ambig_specs(const void *spec1, const void *spec2) {
const AmbigSpec *s1 = *static_cast<const AmbigSpec *const *>(spec1);
const AmbigSpec *s2 = *static_cast<const AmbigSpec *const *>(spec2);
static int compare_ambig_specs(const AmbigSpec *s1, const AmbigSpec *s2) {
int result = UnicharIdArrayUtils::compare(s1->wrong_ngram, s2->wrong_ngram);
if (result != 0) {
return result;
Expand Down
Loading
Loading