Commit a74bbb60 for tesseract

commit a74bbb6032aa78f3816f37a668313f84d9321505
Author: Stefan Weil <sw@weilnetz.de>
Date:   Thu Apr 8 07:36:42 2021 +0200

    Remove bits16.h and BITS16 data type

    Add also const attribute to some functions.

    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/Makefile.am b/Makefile.am
index 63a1ced3..5f828c58 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -335,7 +335,6 @@ if !NO_TESSDATA_PREFIX
 libtesseract_ccutil_la_CPPFLAGS += -DTESSDATA_PREFIX=@datadir@
 endif

-noinst_HEADERS += src/ccutil/bits16.h
 noinst_HEADERS += src/ccutil/ccutil.h
 noinst_HEADERS += src/ccutil/clst.h
 noinst_HEADERS += src/ccutil/elst2.h
diff --git a/src/ccmain/adaptions.cpp b/src/ccmain/adaptions.cpp
index 8b9660ee..8783b720 100644
--- a/src/ccmain/adaptions.cpp
+++ b/src/ccmain/adaptions.cpp
@@ -40,7 +40,7 @@ bool Tesseract::word_adaptable( // should we adapt?
   }

   bool status = false;
-  BITS16 flags(mode);
+  std::bitset<16> flags(mode);

   enum MODES {
     ADAPTABLE_WERD,
diff --git a/src/ccmain/pgedit.cpp b/src/ccmain/pgedit.cpp
index 26f1613a..d4151fde 100644
--- a/src/ccmain/pgedit.cpp
+++ b/src/ccmain/pgedit.cpp
@@ -108,7 +108,7 @@ static bool recog_done = false; // recog_all_words was called

 // These variables should remain global, since they are only used for the
 // debug mode (in which only a single Tesseract thread/instance will exist).
-static BITS16 word_display_mode;
+static std::bitset<16> word_display_mode;
 static ColorationMode color_mode = CM_RAINBOW;
 static bool display_image = false;
 static bool display_blocks = false;
diff --git a/src/ccstruct/coutln.h b/src/ccstruct/coutln.h
index 7477e90d..3aa25519 100644
--- a/src/ccstruct/coutln.h
+++ b/src/ccstruct/coutln.h
@@ -19,7 +19,6 @@
 #ifndef COUTLN_H
 #define COUTLN_H

-#include "bits16.h"     // for BITS16
 #include "elst.h"       // for ELIST_ITERATOR, ELISTIZEH, ELIST_LINK
 #include "mod128.h"     // for DIR128, DIRBITS
 #include "points.h"     // for ICOORD, FCOORD
@@ -29,6 +28,7 @@
 #include <tesseract/export.h> // for DLLSYM

 #include <cstdint> // for int16_t, int32_t
+#include <bitset>  // for std::bitset<16>

 struct Pix;

@@ -285,7 +285,7 @@ private:
   TBOX box;                // bounding box
   ICOORD start;            // start coord
   int16_t stepcount;       // no of steps
-  BITS16 flags;            // flags about outline
+  std::bitset<16> flags;   // flags about outline
   std::vector<uint8_t> steps; // step array
   EdgeOffset *offsets;     // Higher precision edge.
   C_OUTLINE_LIST children; // child elements
diff --git a/src/ccstruct/rejctmap.cpp b/src/ccstruct/rejctmap.cpp
index ae5b4e98..a69a374c 100644
--- a/src/ccstruct/rejctmap.cpp
+++ b/src/ccstruct/rejctmap.cpp
@@ -24,39 +24,39 @@

 namespace tesseract {

-bool REJ::perm_rejected() { // Is char perm reject?
+bool REJ::perm_rejected() const { // Is char perm reject?
   return (flag(R_TESS_FAILURE) || flag(R_SMALL_XHT) || flag(R_EDGE_CHAR) || flag(R_1IL_CONFLICT) ||
           flag(R_POSTNN_1IL) || flag(R_REJ_CBLOB) || flag(R_BAD_REPETITION) || flag(R_MM_REJECT));
 }

-bool REJ::rej_before_nn_accept() {
+bool REJ::rej_before_nn_accept() const {
   return flag(R_POOR_MATCH) || flag(R_NOT_TESS_ACCEPTED) || flag(R_CONTAINS_BLANKS) ||
          flag(R_BAD_PERMUTER);
 }

-bool REJ::rej_between_nn_and_mm() {
+bool REJ::rej_between_nn_and_mm() const {
   return flag(R_HYPHEN) || flag(R_DUBIOUS) || flag(R_NO_ALPHANUMS) || flag(R_MOSTLY_REJ) ||
          flag(R_XHT_FIXUP);
 }

-bool REJ::rej_between_mm_and_quality_accept() {
+bool REJ::rej_between_mm_and_quality_accept() const {
   return flag(R_BAD_QUALITY);
 }

-bool REJ::rej_between_quality_and_minimal_rej_accept() {
+bool REJ::rej_between_quality_and_minimal_rej_accept() const {
   return flag(R_DOC_REJ) || flag(R_BLOCK_REJ) || flag(R_ROW_REJ) || flag(R_UNLV_REJ);
 }

-bool REJ::rej_before_mm_accept() {
+bool REJ::rej_before_mm_accept() const {
   return rej_between_nn_and_mm() ||
          (rej_before_nn_accept() && !flag(R_NN_ACCEPT) && !flag(R_HYPHEN_ACCEPT));
 }

-bool REJ::rej_before_quality_accept() {
+bool REJ::rej_before_quality_accept() const {
   return rej_between_mm_and_quality_accept() || (!flag(R_MM_ACCEPT) && rej_before_mm_accept());
 }

-bool REJ::rejected() { // Is char rejected?
+bool REJ::rejected() const { // Is char rejected?
   if (flag(R_MINIMAL_REJ_ACCEPT)) {
     return false;
   } else {
@@ -65,7 +65,7 @@ bool REJ::rejected() { // Is char rejected?
   }
 }

-bool REJ::accept_if_good_quality() { // potential rej?
+bool REJ::accept_if_good_quality() const { // potential rej?
   return (rejected() && !perm_rejected() && flag(R_BAD_PERMUTER) && !flag(R_POOR_MATCH) &&
           !flag(R_NOT_TESS_ACCEPTED) && !flag(R_CONTAINS_BLANKS) &&
           (!rej_between_nn_and_mm() && !rej_between_mm_and_quality_accept() &&
@@ -183,7 +183,7 @@ void REJ::setrej_minimal_rej_accept() {
   set_flag(R_MINIMAL_REJ_ACCEPT);
 }

-void REJ::full_print(FILE *fp) {
+void REJ::full_print(FILE *fp) const {
   fprintf(fp, "R_TESS_FAILURE: %s\n", flag(R_TESS_FAILURE) ? "T" : "F");
   fprintf(fp, "R_SMALL_XHT: %s\n", flag(R_SMALL_XHT) ? "T" : "F");
   fprintf(fp, "R_EDGE_CHAR: %s\n", flag(R_EDGE_CHAR) ? "T" : "F");
@@ -226,7 +226,7 @@ void REJMAP::initialise(int16_t length) {
   len = length;
 }

-int16_t REJMAP::accept_count() { // How many accepted?
+int16_t REJMAP::accept_count() const { // How many accepted?
   int i;
   int16_t count = 0;

@@ -238,7 +238,7 @@ int16_t REJMAP::accept_count() { // How many accepted?
   return count;
 }

-bool REJMAP::recoverable_rejects() { // Any non perm rejs?
+bool REJMAP::recoverable_rejects() const { // Any non perm rejs?
   for (int i = 0; i < len; i++) {
     if (ptr[i].recoverable()) {
       return true;
@@ -247,7 +247,7 @@ bool REJMAP::recoverable_rejects() { // Any non perm rejs?
   return false;
 }

-bool REJMAP::quality_recoverable_rejects() { // Any potential rejs?
+bool REJMAP::quality_recoverable_rejects() const { // Any potential rejs?
   for (int i = 0; i < len; i++) {
     if (ptr[i].accept_if_good_quality()) {
       return true;
@@ -269,7 +269,7 @@ void REJMAP::remove_pos( // Cut out an element
   }
 }

-void REJMAP::print(FILE *fp) {
+void REJMAP::print(FILE *fp) const {
   int i;
   char buff[512];

@@ -280,7 +280,7 @@ void REJMAP::print(FILE *fp) {
   fprintf(fp, "\"%s\"", buff);
 }

-void REJMAP::full_print(FILE *fp) {
+void REJMAP::full_print(FILE *fp) const {
   int i;

   for (i = 0; i < len; i++) {
diff --git a/src/ccstruct/rejctmap.h b/src/ccstruct/rejctmap.h
index 30371eb7..56340ab7 100644
--- a/src/ccstruct/rejctmap.h
+++ b/src/ccstruct/rejctmap.h
@@ -2,7 +2,6 @@
  * File:        rejctmap.h  (Formerly rejmap.h)
  * Description: REJ and REJMAP class functions.
  * Author:    Phil Cheatle
- * Created:   Thu Jun  9 13:46:38 BST 1994
  *
  * (C) Copyright 1994, Hewlett-Packard Ltd.
  ** Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,10 +40,10 @@ OF THIS IMPLIED TEMPORAL ORDERING OF THE FLAGS!!!!
 #ifndef REJCTMAP_H
 #define REJCTMAP_H

-#include "bits16.h"
 #include "errcode.h"
 #include "params.h"

+#include <bitset>
 #include <memory>

 namespace tesseract {
@@ -98,8 +97,8 @@ enum REJ_FLAGS {
 #define MAP_REJECT_POTENTIAL '3'

 class REJ {
-  BITS16 flags1;
-  BITS16 flags2;
+  std::bitset<16> flags1;
+  std::bitset<16> flags2;

   void set_flag(REJ_FLAGS rej_flag) {
     if (rej_flag < 16) {
@@ -109,12 +108,12 @@ class REJ {
     }
   }

-  bool rej_before_nn_accept();
-  bool rej_between_nn_and_mm();
-  bool rej_between_mm_and_quality_accept();
-  bool rej_between_quality_and_minimal_rej_accept();
-  bool rej_before_mm_accept();
-  bool rej_before_quality_accept();
+  bool rej_before_nn_accept() const;
+  bool rej_between_nn_and_mm() const;
+  bool rej_between_mm_and_quality_accept() const;
+  bool rej_between_quality_and_minimal_rej_accept() const;
+  bool rej_before_mm_accept() const;
+  bool rej_before_quality_accept() const;

 public:
   REJ() = default;
@@ -128,7 +127,7 @@ public:
   REJ &operator=( // assign REJ
       const REJ &source) = default;

-  bool flag(REJ_FLAGS rej_flag) {
+  bool flag(REJ_FLAGS rej_flag) const {
     if (rej_flag < 16) {
       return flags1[rej_flag];
     } else {
@@ -136,7 +135,7 @@ public:
     }
   }

-  char display_char() {
+  char display_char() const {
     if (perm_rejected()) {
       return MAP_REJECT_PERM;
     } else if (accept_if_good_quality()) {
@@ -148,18 +147,18 @@ public:
     }
   }

-  bool perm_rejected(); // Is char perm reject?
+  bool perm_rejected() const; // Is char perm reject?

-  bool rejected(); // Is char rejected?
+  bool rejected() const; // Is char rejected?

-  bool accepted() { // Is char accepted?
+  bool accepted() const { // Is char accepted?
     return !rejected();
   }

   // potential rej?
-  bool accept_if_good_quality();
+  bool accept_if_good_quality() const;

-  bool recoverable() {
+  bool recoverable() const {
     return (rejected() && !perm_rejected());
   }

@@ -196,7 +195,7 @@ public:
   // Accept all except blank
   void setrej_minimal_rej_accept();

-  void full_print(FILE *fp);
+  void full_print(FILE *fp) const;
 };

 class REJMAP {
@@ -226,22 +225,22 @@ public:
     return len;
   }

-  int16_t accept_count(); // How many accepted?
+  int16_t accept_count() const; // How many accepted?

-  int16_t reject_count() { // How many rejects?
+  int16_t reject_count() const { // How many rejects?
     return len - accept_count();
   }

   void remove_pos(  // Cut out an element
       int16_t pos); // element to remove

-  void print(FILE *fp);
+  void print(FILE *fp) const;

-  void full_print(FILE *fp);
+  void full_print(FILE *fp) const;

-  bool recoverable_rejects(); // Any non perm rejs?
+  bool recoverable_rejects() const; // Any non perm rejs?

-  bool quality_recoverable_rejects();
+  bool quality_recoverable_rejects() const;
   // Any potential rejs?

   void rej_word_small_xht(); // Reject whole word
diff --git a/src/ccstruct/werd.h b/src/ccstruct/werd.h
index e13c6c1c..e93da345 100644
--- a/src/ccstruct/werd.h
+++ b/src/ccstruct/werd.h
@@ -19,11 +19,12 @@
 #ifndef WERD_H
 #define WERD_H

-#include "bits16.h"
 #include "elst2.h"
 #include "params.h"
 #include "stepblob.h"

+#include <bitset>
+
 namespace tesseract {

 enum WERD_FLAGS {
@@ -96,7 +97,7 @@ public:
     return &cblobs;
   }

-  uint8_t space() { // access function
+  uint8_t space() const { // access function
     return blanks;
   }
   void set_blanks(uint8_t new_blanks) {
@@ -187,8 +188,8 @@ public:

 private:
   uint8_t blanks = 0;     // no of blanks
-  BITS16 flags;           // flags about word
-  BITS16 disp_flags;      // display flags
+  std::bitset<16> flags;  // flags about word
+  std::bitset<16> disp_flags; // display flags
   int16_t script_id_ = 0; // From unicharset.
   std::string correct;    // correct text
   C_BLOB_LIST cblobs;     // compacted blobs
diff --git a/src/ccutil/bits16.h b/src/ccutil/bits16.h
deleted file mode 100644
index 32208cbb..00000000
--- a/src/ccutil/bits16.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/**********************************************************************
- * File:        bits16.h  (Formerly bits8.h)
- * Description: Code for 8 bit field class.
- * Author:      Phil Cheatle
- *
- * (C) Copyright 1991, Hewlett-Packard Ltd.
- ** Licensed under the Apache License, Version 2.0 (the "License");
- ** you may not use this file except in compliance with the License.
- ** You may obtain a copy of the License at
- ** http://www.apache.org/licenses/LICENSE-2.0
- ** Unless required by applicable law or agreed to in writing, software
- ** distributed under the License is distributed on an "AS IS" BASIS,
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ** See the License for the specific language governing permissions and
- ** limitations under the License.
- *
- **********************************************************************/
-
-#ifndef BITS16_H
-#define BITS16_H
-
-#include <bitset>
-
-using BITS16 = std::bitset<16>;
-
-#endif