mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-23 18:49:08 +08:00
Rework big clist macro into template and small macro. Remove unused macros QUOTE_IT and CLISTIZE (source file macro).
This commit is contained in:
parent
0c189908ec
commit
18e61d10ce
@ -56,8 +56,6 @@ const TPOINT kDivisibleVerticalItalic(1, 5);
|
||||
F u n c t i o n s
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
CLISTIZE(EDGEPT)
|
||||
|
||||
// Returns true when the two line segments cross each other.
|
||||
// (Moved from outlines.cpp).
|
||||
// Finds where the projected lines would cross and then checks to see if the
|
||||
|
@ -46,7 +46,6 @@ struct Pix;
|
||||
namespace tesseract {
|
||||
|
||||
ELISTIZE(BLOCK_RES)
|
||||
CLISTIZE(BLOCK_RES)
|
||||
ELISTIZE(ROW_RES)
|
||||
ELISTIZE(WERD_RES)
|
||||
|
||||
|
@ -36,7 +36,6 @@ namespace tesseract {
|
||||
constexpr ERRCODE BADBLOCKLINE("Y coordinate in block out of bounds");
|
||||
constexpr ERRCODE LOSTBLOCKLINE("Can't find rectangle for line");
|
||||
|
||||
CLISTIZE(PDBLK)
|
||||
/**********************************************************************
|
||||
* PDBLK::PDBLK
|
||||
*
|
||||
|
@ -692,153 +692,57 @@ inline void CLIST_ITERATOR::add_to_end( // element to add
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
QUOTE_IT MACRO DEFINITION
|
||||
===========================
|
||||
Replace <parm> with "<parm>". <parm> may be an arbitrary number of tokens
|
||||
***********************************************************************/
|
||||
template <typename CLASSNAME>
|
||||
class X_CLIST : public CLIST {
|
||||
public:
|
||||
X_CLIST() = default;
|
||||
X_CLIST(const X_CLIST &) = delete;
|
||||
X_CLIST &operator=(const X_CLIST &) = delete;
|
||||
|
||||
#define QUOTE_IT(parm) #parm
|
||||
|
||||
/***********************************************************************
|
||||
CLISTIZE(CLASSNAME) MACRO DEFINITION
|
||||
======================================
|
||||
|
||||
CLASSNAME is assumed to be the name of a class to be used in a CONS list
|
||||
|
||||
NOTE: Because we don't use virtual functions in the list code, the list code
|
||||
will NOT work correctly for classes derived from this.
|
||||
|
||||
The macro generates:
|
||||
- An element deletion function: CLASSNAME##_c1_zapper
|
||||
- An element copier function:
|
||||
CLASSNAME##_c1_copier
|
||||
- A CLIST subclass: CLASSNAME##_CLIST
|
||||
- A CLIST_ITERATOR subclass:
|
||||
CLASSNAME##_C_IT
|
||||
|
||||
NOTE:
|
||||
Generated names do NOT clash with those generated by ELISTIZE and ELIST2ISE.
|
||||
|
||||
Two macros are provided: CLISTIZE and CLISTIZEH
|
||||
The ...IZEH macros just define the class names for use in .h files
|
||||
The ...IZE macros define the code use in .c files
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
CLISTIZEH(CLASSNAME) MACRO
|
||||
|
||||
CLISTIZEH is a concatenation of 3 fragments CLISTIZEH_A, CLISTIZEH_B and
|
||||
CLISTIZEH_C.
|
||||
***********************************************************************/
|
||||
|
||||
#define CLISTIZEH_A(CLASSNAME) \
|
||||
\
|
||||
extern void CLASSNAME##_c1_zapper( /*delete a link*/ \
|
||||
void *link); /*link to delete*/ \
|
||||
\
|
||||
extern void *CLASSNAME##_c1_copier( /*deep copy a link*/ \
|
||||
void *old_element); /*source link */
|
||||
|
||||
#define CLISTIZEH_B(CLASSNAME) \
|
||||
\
|
||||
/*********************************************************************** \
|
||||
* CLASS - \
|
||||
*CLASSNAME##_CLIST \
|
||||
* \
|
||||
* List class for class \
|
||||
*CLASSNAME \
|
||||
* \
|
||||
**********************************************************************/ \
|
||||
\
|
||||
class CLASSNAME##_CLIST : public CLIST { \
|
||||
public: \
|
||||
CLASSNAME##_CLIST() : CLIST() {} \
|
||||
/* constructor */ \
|
||||
\
|
||||
CLASSNAME##_CLIST(const CLASSNAME##_CLIST &) = delete; \
|
||||
void operator=(const CLASSNAME##_CLIST &) = delete; \
|
||||
\
|
||||
void deep_clear() /* delete elements */ \
|
||||
{ \
|
||||
CLIST::internal_deep_clear(&CLASSNAME##_c1_zapper); \
|
||||
} \
|
||||
|
||||
#define CLISTIZEH_C(CLASSNAME) \
|
||||
} \
|
||||
; \
|
||||
\
|
||||
/*********************************************************************** \
|
||||
* CLASS - CLASSNAME##_C_IT \
|
||||
* \
|
||||
* Iterator class for class CLASSNAME##_CLIST \
|
||||
* \
|
||||
* Note: We don't need to coerce pointers to member functions input \
|
||||
* parameters as these are automatically converted to the type of the base \
|
||||
* type. ("A ptr to a class may be converted to a pointer to a public base \
|
||||
* class of that class") \
|
||||
**********************************************************************/ \
|
||||
\
|
||||
class CLASSNAME##_C_IT : public CLIST_ITERATOR { \
|
||||
public: \
|
||||
CLASSNAME##_C_IT() : CLIST_ITERATOR() {} \
|
||||
\
|
||||
CLASSNAME##_C_IT(CLASSNAME##_CLIST *list) : CLIST_ITERATOR(list) {} \
|
||||
\
|
||||
CLASSNAME *data() { \
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::data()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *data_relative(int8_t offset) { \
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::data_relative(offset)); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *forward() { \
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::forward()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *extract() { \
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::extract()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *move_to_first() { \
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::move_to_first()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *move_to_last() { \
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::move_to_last()); \
|
||||
} \
|
||||
};
|
||||
|
||||
#define CLISTIZEH(CLASSNAME) \
|
||||
\
|
||||
CLISTIZEH_A(CLASSNAME) \
|
||||
\
|
||||
CLISTIZEH_B(CLASSNAME) \
|
||||
\
|
||||
CLISTIZEH_C(CLASSNAME)
|
||||
|
||||
/***********************************************************************
|
||||
CLISTIZE(CLASSNAME) MACRO
|
||||
***********************************************************************/
|
||||
|
||||
#define CLISTIZE(CLASSNAME) \
|
||||
\
|
||||
/*********************************************************************** \
|
||||
* CLASSNAME##_c1_zapper \
|
||||
* \
|
||||
* A function which can delete a CLASSNAME element. This is passed to the \
|
||||
* generic deep_clear list member function so that when a list is cleared \
|
||||
*the \
|
||||
* elements on the list are properly destroyed from the base class, even \
|
||||
* though we don't use a virtual destructor function. \
|
||||
**********************************************************************/ \
|
||||
\
|
||||
void CLASSNAME##_c1_zapper( /*delete a link*/ \
|
||||
void *link) /*link to delete*/ \
|
||||
{ \
|
||||
delete static_cast<CLASSNAME *>(link); \
|
||||
void deep_clear() {
|
||||
internal_deep_clear([](void *link) {delete static_cast<CLASSNAME *>(link);});
|
||||
}
|
||||
};
|
||||
|
||||
template <typename CLASSNAME>
|
||||
class X_C_IT : public CLIST_ITERATOR {
|
||||
public:
|
||||
X_C_IT() = default;
|
||||
protected:
|
||||
template <typename U>
|
||||
X_C_IT(U *list) : CLIST_ITERATOR(list) {}
|
||||
|
||||
public:
|
||||
CLASSNAME *data() {
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::data());
|
||||
}
|
||||
CLASSNAME *data_relative(int8_t offset) {
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::data_relative(offset));
|
||||
}
|
||||
CLASSNAME *forward() {
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::forward());
|
||||
}
|
||||
CLASSNAME *extract() {
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::extract());
|
||||
}
|
||||
CLASSNAME *move_to_first() {
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::move_to_first());
|
||||
}
|
||||
CLASSNAME *move_to_last() {
|
||||
return static_cast<CLASSNAME *>(CLIST_ITERATOR::move_to_last());
|
||||
}
|
||||
};
|
||||
|
||||
#define CLISTIZEH(CLASSNAME) \
|
||||
class CLASSNAME##_CLIST : public X_CLIST<CLASSNAME> { \
|
||||
public: \
|
||||
using X_CLIST<CLASSNAME>::X_CLIST; \
|
||||
}; \
|
||||
class CLASSNAME##_C_IT : public X_C_IT<CLASSNAME> { \
|
||||
public: \
|
||||
using X_C_IT<CLASSNAME>::X_C_IT; \
|
||||
CLASSNAME##_C_IT(CLASSNAME##_CLIST *list) : X_C_IT(list) {} \
|
||||
};
|
||||
|
||||
} // namespace tesseract
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
namespace tesseract {
|
||||
|
||||
ELIST2IZE(ColPartition)
|
||||
CLISTIZE(ColPartition)
|
||||
|
||||
//////////////// ColPartition Implementation ////////////////
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
namespace tesseract {
|
||||
|
||||
ELISTIZE(FPSEGPT)
|
||||
CLISTIZE(FPSEGPT_LIST)
|
||||
|
||||
INT_VAR(pitsync_linear_version, 6, "Use new fast algorithm");
|
||||
double_VAR(pitsync_joined_edge, 0.75, "Dist inside big blob for chopping");
|
||||
|
@ -151,7 +151,6 @@ static BOOL_VAR(textord_tablefind_recognize_tables, false,
|
||||
"Enables the table recognizer for table layout and filtering.");
|
||||
|
||||
ELISTIZE(ColSegment)
|
||||
CLISTIZE(ColSegment)
|
||||
|
||||
// Templated helper function used to create destructor callbacks for the
|
||||
// BBGrid::ClearGridData() method.
|
||||
|
@ -166,7 +166,6 @@ void TabConstraint::GetConstraints(TabConstraint_LIST *constraints, int *y_min,
|
||||
}
|
||||
|
||||
ELIST2IZE(TabVector)
|
||||
CLISTIZE(TabVector)
|
||||
|
||||
// The constructor is private. See the bottom of the file...
|
||||
|
||||
|
@ -59,8 +59,6 @@ namespace tesseract {
|
||||
|
||||
#define MAX_NEAREST_DIST 600 // for block skew stats
|
||||
|
||||
CLISTIZE(WordWithBox)
|
||||
|
||||
/**********************************************************************
|
||||
* SetBlobStrokeWidth
|
||||
*
|
||||
|
@ -44,7 +44,6 @@ public:
|
||||
};
|
||||
|
||||
CLISTIZEH(Clst)
|
||||
CLISTIZE(Clst)
|
||||
ELISTIZEH(Elst)
|
||||
ELISTIZE(Elst)
|
||||
ELIST2IZEH(Elst2)
|
||||
|
Loading…
Reference in New Issue
Block a user