Skip to content

Commit

Permalink
Move all tesseract symbols into tesseract namespace. Fix include orde…
Browse files Browse the repository at this point in the history
…r in many places.
  • Loading branch information
egorpugin committed Dec 25, 2020
1 parent a67fa17 commit 79a86f2
Show file tree
Hide file tree
Showing 270 changed files with 1,732 additions and 1,032 deletions.
16 changes: 9 additions & 7 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
#include <cstdio>
#include <functional> // for std::function

struct Pix;
struct Box;
struct Pixa;
struct Boxa;

namespace tesseract {

template <typename T>
class GenericVector;
class PAGE_RES;
Expand All @@ -52,10 +59,6 @@ class MATRIX;
class ROW;
class STRING;
class WERD;
struct Pix;
struct Box;
struct Pixa;
struct Boxa;
class ETEXT_DESC;
struct OSResults;
class TBOX;
Expand All @@ -66,8 +69,6 @@ struct INT_FEATURE_STRUCT;
using INT_FEATURE = INT_FEATURE_STRUCT*;
struct TBLOB;

namespace tesseract {

class Dawg;
class Dict;
class EquationDetect;
Expand Down Expand Up @@ -853,6 +854,7 @@ class TESS_API TessBaseAPI {

/** Escape a char string - remove &<>"' with HTML codes. */
STRING HOcrEscape(const char* text);
} // namespace tesseract.

} // namespace tesseract

#endif // TESSERACT_API_BASEAPI_H_
9 changes: 5 additions & 4 deletions include/tesseract/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ typedef tesseract::Orientation TessOrientation;
typedef tesseract::ParagraphJustification TessParagraphJustification;
typedef tesseract::WritingDirection TessWritingDirection;
typedef tesseract::TextlineOrder TessTextlineOrder;
typedef PolyBlockType TessPolyBlockType;
typedef tesseract::PolyBlockType TessPolyBlockType;
typedef tesseract::ETEXT_DESC ETEXT_DESC;
#else
typedef struct TessResultRenderer TessResultRenderer;
typedef struct TessBaseAPI TessBaseAPI;
Expand Down Expand Up @@ -232,13 +233,13 @@ TESS_API BOOL TessBaseAPIPrintVariablesToFile(const TessBaseAPI* handle,
#ifdef TESS_CAPI_INCLUDE_BASEAPI

TESS_API BOOL TessBaseAPIGetVariableAsString(TessBaseAPI* handle,
const char* name, STRING* val);
const char* name, tesseract::STRING* val);

TESS_API int TessBaseAPIInit(TessBaseAPI* handle, const char* datapath,
const char* language, TessOcrEngineMode mode,
char** configs, int configs_size,
const STRING* vars_vec, size_t vars_vec_size,
const STRING* vars_values, size_t vars_values_size,
const tesseract::STRING* vars_vec, size_t vars_vec_size,
const tesseract::STRING* vars_values, size_t vars_values_size,
BOOL set_only_init_params);

#endif // def TESS_CAPI_INCLUDE_BASEAPI
Expand Down
44 changes: 22 additions & 22 deletions include/tesseract/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <cstdlib>
#include <functional> // for std::function

namespace tesseract {

// Use PointerVector<T> below in preference to GenericVector<T*>, as that
// provides automatic deletion of pointers, [De]Serialize that works, and
// sort that works.
Expand Down Expand Up @@ -169,35 +171,35 @@ class GenericVector {
// Returns false on error or if the callback returns false.
// DEPRECATED. Use [De]Serialize[Classes] instead.
bool write(FILE* f, std::function<bool(FILE*, const T&)> cb) const;
bool read(tesseract::TFile* f, std::function<bool(tesseract::TFile*, T*)> cb);
bool read(TFile* f, std::function<bool(TFile*, T*)> cb);
// Writes a vector of simple types to the given file. Assumes that bitwise
// read/write of T will work. Returns false in case of error.
// TODO(rays) Change all callers to use TFile and remove deprecated methods.
bool Serialize(FILE* fp) const;
bool Serialize(tesseract::TFile* fp) const;
bool Serialize(TFile* fp) const;
// Reads a vector of simple types from the given file. Assumes that bitwise
// read/write will work with ReverseN according to sizeof(T).
// Returns false in case of error.
// If swap is true, assumes a big/little-endian swap is needed.
// TFile is assumed to know about swapping.
bool DeSerialize(bool swap, FILE* fp);
bool DeSerialize(tesseract::TFile* fp);
bool DeSerialize(TFile* fp);
// Skips the deserialization of the vector.
static bool SkipDeSerialize(tesseract::TFile* fp);
static bool SkipDeSerialize(TFile* fp);
// Writes a vector of classes to the given file. Assumes the existence of
// bool T::Serialize(FILE* fp) const that returns false in case of error.
// Returns false in case of error.
bool SerializeClasses(FILE* fp) const;
bool SerializeClasses(tesseract::TFile* fp) const;
bool SerializeClasses(TFile* fp) const;
// Reads a vector of classes from the given file. Assumes the existence of
// bool T::Deserialize(bool swap, FILE* fp) that returns false in case of
// error. Also needs T::T() and T::T(constT&), as init_to_size is used in
// this function. Returns false in case of error.
// If swap is true, assumes a big/little-endian swap is needed.
bool DeSerializeClasses(bool swap, FILE* fp);
bool DeSerializeClasses(tesseract::TFile* fp);
bool DeSerializeClasses(TFile* fp);
// Calls SkipDeSerialize on the elements of the vector.
static bool SkipDeSerializeClasses(tesseract::TFile* fp);
static bool SkipDeSerializeClasses(TFile* fp);

// Allocates a new array of double the current_size, copies over the
// information from data to the new location, deletes data and returns
Expand Down Expand Up @@ -334,8 +336,6 @@ class GenericVector {
std::function<bool(const T&, const T&)> compare_cb_;
};

namespace tesseract {

// The default FileReader loads the whole file into the vector of char,
// returning false on error.
inline bool LoadDataFromFile(const char* filename, GenericVector<char>* data) {
Expand Down Expand Up @@ -633,21 +633,19 @@ class PointerVector : public GenericVector<T*> {
}
};

} // namespace tesseract

// A useful vector that uses operator== to do comparisons.
template <typename T>
class GenericVectorEqEq : public GenericVector<T> {
public:
GenericVectorEqEq() {
using namespace std::placeholders; // for _1
GenericVector<T>::set_compare_callback(
std::bind(tesseract::cmp_eq<T>, _1, _2));
std::bind(cmp_eq<T>, _1, _2));
}
explicit GenericVectorEqEq(int size) : GenericVector<T>(size) {
using namespace std::placeholders; // for _1
GenericVector<T>::set_compare_callback(
std::bind(tesseract::cmp_eq<T>, _1, _2));
std::bind(cmp_eq<T>, _1, _2));
}
};

Expand Down Expand Up @@ -899,8 +897,8 @@ bool GenericVector<T>::write(FILE* f,
}

template <typename T>
bool GenericVector<T>::read(tesseract::TFile* f,
std::function<bool(tesseract::TFile*, T*)> cb) {
bool GenericVector<T>::read(TFile* f,
std::function<bool(TFile*, T*)> cb) {
int32_t reserved;
if (f->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand Down Expand Up @@ -936,7 +934,7 @@ bool GenericVector<T>::Serialize(FILE* fp) const {
return true;
}
template <typename T>
bool GenericVector<T>::Serialize(tesseract::TFile* fp) const {
bool GenericVector<T>::Serialize(TFile* fp) const {
if (fp->FWrite(&size_used_, sizeof(size_used_), 1) != 1) {
return false;
}
Expand Down Expand Up @@ -977,7 +975,7 @@ bool GenericVector<T>::DeSerialize(bool swap, FILE* fp) {
return true;
}
template <typename T>
bool GenericVector<T>::DeSerialize(tesseract::TFile* fp) {
bool GenericVector<T>::DeSerialize(TFile* fp) {
uint32_t reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand All @@ -993,7 +991,7 @@ bool GenericVector<T>::DeSerialize(tesseract::TFile* fp) {
return fp->FReadEndian(data_, sizeof(T), size_used_) == size_used_;
}
template <typename T>
bool GenericVector<T>::SkipDeSerialize(tesseract::TFile* fp) {
bool GenericVector<T>::SkipDeSerialize(TFile* fp) {
uint32_t reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand All @@ -1017,7 +1015,7 @@ bool GenericVector<T>::SerializeClasses(FILE* fp) const {
return true;
}
template <typename T>
bool GenericVector<T>::SerializeClasses(tesseract::TFile* fp) const {
bool GenericVector<T>::SerializeClasses(TFile* fp) const {
if (fp->FWrite(&size_used_, sizeof(size_used_), 1) != 1) {
return false;
}
Expand Down Expand Up @@ -1053,7 +1051,7 @@ bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
return true;
}
template <typename T>
bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
bool GenericVector<T>::DeSerializeClasses(TFile* fp) {
int32_t reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand All @@ -1068,7 +1066,7 @@ bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
return true;
}
template <typename T>
bool GenericVector<T>::SkipDeSerializeClasses(tesseract::TFile* fp) {
bool GenericVector<T>::SkipDeSerializeClasses(TFile* fp) {
int32_t reserved;
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) {
return false;
Expand Down Expand Up @@ -1100,7 +1098,7 @@ void GenericVector<T>::move(GenericVector<T>* from) {

template <typename T>
void GenericVector<T>::sort() {
sort(&tesseract::sort_cmp<T>);
sort(&sort_cmp<T>);
}

// Internal recursive version of choose_nth_item.
Expand Down Expand Up @@ -1164,4 +1162,6 @@ int GenericVector<T>::choose_nth_item(int target_index, int start, int end,
return choose_nth_item(target_index, prev_greater, end, seed);
}

} // namespace tesseract

#endif // TESSERACT_CCUTIL_GENERICVECTOR_H_
5 changes: 2 additions & 3 deletions include/tesseract/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <functional>
#include <string>

// TODO(rays) Put the rest of the helpers in the namespace.
namespace tesseract {

// A simple linear congruential random number generator, using Knuth's
Expand Down Expand Up @@ -70,8 +69,6 @@ class TRand {
uint64_t seed_{1};
};

} // namespace tesseract

// Remove newline (if any) at the end of the string.
inline void chomp_string(char* str) {
int last_index = static_cast<int>(strlen(str)) - 1;
Expand Down Expand Up @@ -207,4 +204,6 @@ inline void Reverse64(void* ptr) {
ReverseN(ptr, 8);
}

} // namespace tesseract

#endif // TESSERACT_CCUTIL_HELPERS_H_
4 changes: 2 additions & 2 deletions include/tesseract/ltrresultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#include "publictypes.h" // for PageIteratorLevel
#include "unichar.h" // for StrongScriptDirection

namespace tesseract {

class BLOB_CHOICE_IT;
class PAGE_RES;
class WERD_RES;

namespace tesseract {

class Tesseract;

// Class to iterate over tesseract results, providing access to all levels
Expand Down
4 changes: 4 additions & 0 deletions include/tesseract/ocrclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <chrono>
#include <ctime>

namespace tesseract {

/**********************************************************************
* EANYCODE_CHAR
* Description of a single character. The character code is defined by
Expand Down Expand Up @@ -150,4 +152,6 @@ class ETEXT_DESC { // output header
}
};

} // namespace tesseract

#endif // CCUTIL_OCRCLASS_H_
6 changes: 4 additions & 2 deletions include/tesseract/osdetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "platform.h" // for TESS_API

namespace tesseract {

class BLOBNBOX;
class BLOBNBOX_CLIST;
class BLOB_CHOICE_LIST;
Expand All @@ -30,9 +32,7 @@ class UNICHARSET;
template <typename T>
class GenericVector;

namespace tesseract {
class Tesseract;
}

// Max number of scripts in ICU + "NULL" + Japanese and Korean + Fraktur
const int kMaxNumberOfScripts = 116 + 1 + 2 + 1;
Expand Down Expand Up @@ -134,4 +134,6 @@ bool os_detect_blob(BLOBNBOX* bbox, OrientationDetector* o, ScriptDetector* s,
// applied for the text to be upright (readable).
TESS_API int OrientationIdToValue(const int& id);

} // namespace tesseract

#endif // TESSERACT_CCMAIN_OSDETECT_H_
9 changes: 5 additions & 4 deletions include/tesseract/pageiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
#include "platform.h"
#include "publictypes.h"

struct Pix;
struct Pta;

namespace tesseract {

struct BlamerBundle;
class C_BLOB_IT;
class PAGE_RES;
class PAGE_RES_IT;
class WERD;
struct Pix;
struct Pta;

namespace tesseract {

class Tesseract;

Expand Down
3 changes: 2 additions & 1 deletion include/tesseract/publictypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef TESSERACT_CCSTRUCT_PUBLICTYPES_H_
#define TESSERACT_CCSTRUCT_PUBLICTYPES_H_

namespace tesseract {

// This file contains types that are used both by the API and internally
// to Tesseract. In order to decouple the API from Tesseract and prevent cyclic
// dependencies, THIS FILE SHOULD NOT DEPEND ON ANY OTHER PART OF TESSERACT.
Expand Down Expand Up @@ -89,7 +91,6 @@ inline bool PTIsPulloutType(PolyBlockType type) {
return type == PT_PULLOUT_IMAGE || type == PT_PULLOUT_TEXT;
}

namespace tesseract {
/**
* +------------------+ Orientation Example:
* | 1 Aaaa Aaaa Aaaa | ====================
Expand Down
4 changes: 2 additions & 2 deletions include/tesseract/resultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
#include <set> // for std::pair
#include <vector> // for std::vector

namespace tesseract {

template <typename T>
class GenericVector;
template <typename T>
class GenericVectorEqEq;

class STRING;

namespace tesseract {

class Tesseract;

class TESS_API ResultIterator : public LTRResultIterator {
Expand Down
4 changes: 2 additions & 2 deletions include/tesseract/serialis.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <cstdlib>
#include <cstring>

namespace tesseract {

template <typename T>
class GenericVector;

Expand All @@ -35,8 +37,6 @@ Replace <parm> with "<parm>". <parm> may be an arbitrary number of tokens

#define QUOTE_IT(parm) #parm

namespace tesseract {

// Return number of elements of an array.
template <typename T, size_t N>
constexpr size_t countof(T const (&)[N]) noexcept {
Expand Down
Loading

0 comments on commit 79a86f2

Please sign in to comment.