Commit 18e61d10 for tesseract

commit 18e61d10ce4007584323f1aaee55e356043af6fc
Author: Egor Pugin <egor.pugin@gmail.com>
Date:   Tue Apr 6 23:37:14 2021 +0300

    Rework big clist macro into template and small macro. Remove unused macros QUOTE_IT and CLISTIZE (source file macro).

diff --git a/src/ccstruct/blobs.cpp b/src/ccstruct/blobs.cpp
index 74ce962e..c61280ff 100644
--- a/src/ccstruct/blobs.cpp
+++ b/src/ccstruct/blobs.cpp
@@ -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
diff --git a/src/ccstruct/pageres.cpp b/src/ccstruct/pageres.cpp
index db8e6d60..88c9a3c4 100644
--- a/src/ccstruct/pageres.cpp
+++ b/src/ccstruct/pageres.cpp
@@ -46,7 +46,6 @@ struct Pix;
 namespace tesseract {

 ELISTIZE(BLOCK_RES)
-CLISTIZE(BLOCK_RES)
 ELISTIZE(ROW_RES)
 ELISTIZE(WERD_RES)

diff --git a/src/ccstruct/pdblock.cpp b/src/ccstruct/pdblock.cpp
index fa4b9870..7ee76e65 100644
--- a/src/ccstruct/pdblock.cpp
+++ b/src/ccstruct/pdblock.cpp
@@ -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
  *
diff --git a/src/ccutil/clst.h b/src/ccutil/clst.h
index 940f0189..160f8c3e 100644
--- a/src/ccutil/clst.h
+++ b/src/ccutil/clst.h
@@ -692,154 +692,58 @@ 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
-***********************************************************************/
-
-#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.
+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;

-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
+  void deep_clear() {
+    internal_deep_clear([](void *link) {delete static_cast<CLASSNAME *>(link);});
+  }
+};

-NOTE:
-Generated names do NOT clash with those generated by ELISTIZE and ELIST2ISE.
+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) {}

-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
-***********************************************************************/
+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());
+  }
+};

-/***********************************************************************
-  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)                                    \
+  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) {} \
   };

-#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);                                    \
-  }
-
 } // namespace tesseract

 #endif
diff --git a/src/textord/colpartition.cpp b/src/textord/colpartition.cpp
index 54b5a635..fcef29fe 100644
--- a/src/textord/colpartition.cpp
+++ b/src/textord/colpartition.cpp
@@ -36,7 +36,6 @@
 namespace tesseract {

 ELIST2IZE(ColPartition)
-CLISTIZE(ColPartition)

 //////////////// ColPartition Implementation ////////////////

diff --git a/src/textord/pitsync1.cpp b/src/textord/pitsync1.cpp
index 21af0d94..8f2ecadc 100644
--- a/src/textord/pitsync1.cpp
+++ b/src/textord/pitsync1.cpp
@@ -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");
diff --git a/src/textord/tablefind.cpp b/src/textord/tablefind.cpp
index 982a346f..ea4cd7f5 100644
--- a/src/textord/tablefind.cpp
+++ b/src/textord/tablefind.cpp
@@ -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.
diff --git a/src/textord/tabvector.cpp b/src/textord/tabvector.cpp
index cdafbd94..c5a9b43a 100644
--- a/src/textord/tabvector.cpp
+++ b/src/textord/tabvector.cpp
@@ -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...

diff --git a/src/textord/tordmain.cpp b/src/textord/tordmain.cpp
index 8ade06d6..842d4392 100644
--- a/src/textord/tordmain.cpp
+++ b/src/textord/tordmain.cpp
@@ -59,8 +59,6 @@ namespace tesseract {

 #define MAX_NEAREST_DIST 600 // for block skew stats

-CLISTIZE(WordWithBox)
-
 /**********************************************************************
  * SetBlobStrokeWidth
  *
diff --git a/unittest/list_test.cc b/unittest/list_test.cc
index e2ef81b5..5310214a 100644
--- a/unittest/list_test.cc
+++ b/unittest/list_test.cc
@@ -44,7 +44,6 @@ public:
 };

 CLISTIZEH(Clst)
-CLISTIZE(Clst)
 ELISTIZEH(Elst)
 ELISTIZE(Elst)
 ELIST2IZEH(Elst2)