Skip to content

Commit

Permalink
Use using instead of typedef. Reason: https://github.com/isocpp/CppCo…
Browse files Browse the repository at this point in the history
  • Loading branch information
zamazan4ik committed May 19, 2018
1 parent 0248c7f commit 0697235
Show file tree
Hide file tree
Showing 42 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/ccmain/paragraphs_internal.h
Expand Up @@ -88,7 +88,7 @@ struct LineHypothesis {

class ParagraphTheory; // Forward Declaration

typedef GenericVectorEqEq<const ParagraphModel *> SetOfModels;
using SetOfModels = GenericVectorEqEq<const ParagraphModel *>;

// Row Scratch Registers are data generated by the paragraph detection
// algorithm based on a RowInfo input.
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/blobs.h
Expand Up @@ -71,7 +71,7 @@ struct TPOINT {
int16_t x; // absolute x coord.
int16_t y; // absolute y coord.
};
typedef TPOINT VECTOR; // structure for coordinates.
using VECTOR = TPOINT; // structure for coordinates.

struct EDGEPT {
EDGEPT()
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/detlinefit.h
Expand Up @@ -120,7 +120,7 @@ class DetLineFit {
// Type holds the distance of each point from the fitted line and the point
// itself. Use of double allows integer distances from ICOORDs to be stored
// exactly, and also the floating point results from ConstrainedFit.
typedef KDPairInc<double, ICOORD> DistPointPair;
using DistPointPair = KDPairInc<double, ICOORD>;

// Computes and returns the squared evaluation metric for a line fit.
double EvaluateLineFit();
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/matrix.h
Expand Up @@ -628,6 +628,6 @@ struct MATRIX_COORD {
};

// The MatrixCoordPair contains a MATRIX_COORD and its priority.
typedef tesseract::KDPairInc<float, MATRIX_COORD> MatrixCoordPair;
using MatrixCoordPair = tesseract::KDPairInc<float, MATRIX_COORD>;

#endif // TESSERACT_CCSTRUCT_MATRIX_H_
2 changes: 1 addition & 1 deletion src/ccstruct/params_training_featdef.h
Expand Up @@ -119,7 +119,7 @@ struct ParamsTrainingHypothesis {
};

// A list of hypotheses explored during one run of segmentation search.
typedef GenericVector<ParamsTrainingHypothesis> ParamsTrainingHypothesisList;
using ParamsTrainingHypothesisList = GenericVector<ParamsTrainingHypothesis>;

// A bundle that accumulates all of the hypothesis lists explored during all
// of the runs of segmentation search on a word (e.g. a list of hypotheses
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/ratngs.h
Expand Up @@ -637,7 +637,7 @@ class WERD_CHOICE : public ELIST_LINK {

// Make WERD_CHOICE listable.
ELISTIZEH(WERD_CHOICE)
typedef GenericVector<BLOB_CHOICE_LIST *> BLOB_CHOICE_LIST_VECTOR;
using BLOB_CHOICE_LIST_VECTOR = GenericVector<BLOB_CHOICE_LIST *>;

// Utilities for comparing WERD_CHOICEs

Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/seam.h
Expand Up @@ -39,7 +39,7 @@
/*----------------------------------------------------------------------
T y p e s
----------------------------------------------------------------------*/
typedef float PRIORITY; /* PRIORITY */
using PRIORITY = float; /* PRIORITY */

class SEAM {
public:
Expand Down
4 changes: 2 additions & 2 deletions src/ccutil/ambigs.h
Expand Up @@ -31,7 +31,7 @@

namespace tesseract {

typedef GenericVector<UNICHAR_ID> UnicharIdVector;
using UnicharIdVector = GenericVector<UNICHAR_ID>;

static const int kUnigramAmbigsBufferSize = 1000;
static const char kAmbigNgramSeparator[] = { ' ', '\0' };
Expand Down Expand Up @@ -138,7 +138,7 @@ ELISTIZEH(AmbigSpec)

// AMBIG_TABLE[i] stores a set of ambiguities whose
// wrong ngram starts with unichar id i.
typedef GenericVector<AmbigSpec_LIST *> UnicharAmbigsVector;
using UnicharAmbigsVector = GenericVector<AmbigSpec_LIST *>;

class UnicharAmbigs {
public:
Expand Down
6 changes: 3 additions & 3 deletions src/ccutil/host.h
Expand Up @@ -31,9 +31,9 @@
#include <cstdint> // int32_t, ...

// definitions of portable data types (numbers and characters)
typedef float FLOAT32;
typedef double FLOAT64;
typedef unsigned char BOOL8;
using FLOAT32 = float;
using FLOAT64 = double;
using BOOL8 = unsigned char;

#if defined(_WIN32)

Expand Down
2 changes: 1 addition & 1 deletion src/ccutil/kdpair.h
Expand Up @@ -176,7 +176,7 @@ struct KDPtrPairDec : public KDPtrPair<Key, Data> {
};

// Specialization for a pair of ints in increasing order.
typedef KDPairInc<int, int> IntKDPair;
using IntKDPair = KDPairInc<int, int>;

// Vector of IntKDPair.
class KDVector : public GenericVector<IntKDPair> {
Expand Down
6 changes: 3 additions & 3 deletions src/ccutil/unichar.h
Expand Up @@ -32,7 +32,7 @@

// TODO(rays) Move these to the tesseract namespace.
// A UNICHAR_ID is the unique id of a unichar.
typedef int UNICHAR_ID;
using UNICHAR_ID = int;

// A variable to indicate an invalid or uninitialized unichar id.
static const int INVALID_UNICHAR_ID = -1;
Expand All @@ -49,7 +49,7 @@ enum StrongScriptDirection {

namespace tesseract {

typedef signed int char32;
using char32 = signed int;

// The UNICHAR class holds a single classification result. This may be
// a single Unicode character (stored as between 1 and 4 utf8 bytes) or
Expand Down Expand Up @@ -106,7 +106,7 @@ class UNICHAR {
// tprintf("Char = %s\n", buf);
// }
class const_iterator {
typedef const_iterator CI;
using CI = const_iterator ;

public:
// Step to the next UTF8 character.
Expand Down
4 changes: 2 additions & 2 deletions src/ccutil/unicharcompress.cpp
Expand Up @@ -44,9 +44,9 @@ static int RadicalPreHash(const std::vector<int>& rs) {
}

// A hash map to convert unicodes to radical encoding.
typedef std::unordered_map<int, std::unique_ptr<std::vector<int>>> RSMap;
using RSMap = std::unordered_map<int, std::unique_ptr<std::vector<int>>>;
// A hash map to count occurrences of each radical encoding.
typedef std::unordered_map<int, int> RSCounts;
using RSCounts = std::unordered_map<int, int>;

static bool DecodeRadicalLine(STRING* radical_data_line, RSMap* radical_map) {
if (radical_data_line->length() == 0 || (*radical_data_line)[0] == '#')
Expand Down
4 changes: 2 additions & 2 deletions src/classify/cluster.cpp
Expand Up @@ -164,8 +164,8 @@ struct TEMPCLUSTER {
CLUSTER *Neighbor;
};

typedef tesseract::KDPairInc<float, TEMPCLUSTER*> ClusterPair;
typedef tesseract::GenericHeap<ClusterPair> ClusterHeap;
using ClusterPair = tesseract::KDPairInc<float, TEMPCLUSTER*>;
using ClusterHeap = tesseract::GenericHeap<ClusterPair>;

struct STATISTICS {
FLOAT32 AvgVariance;
Expand Down
4 changes: 2 additions & 2 deletions src/classify/featdefs.h
Expand Up @@ -43,14 +43,14 @@ struct CHAR_DESC_STRUCT {
uint32_t NumFeatureSets;
FEATURE_SET FeatureSets[NUM_FEATURE_TYPES];
};
typedef CHAR_DESC_STRUCT *CHAR_DESC;
using CHAR_DESC = CHAR_DESC_STRUCT *;

struct FEATURE_DEFS_STRUCT {
int32_t NumFeatureTypes;
const FEATURE_DESC_STRUCT* FeatureDesc[NUM_FEATURE_TYPES];
int FeatureEnabled[NUM_FEATURE_TYPES];
};
typedef FEATURE_DEFS_STRUCT *FEATURE_DEFS;
using FEATURE_DEFS = FEATURE_DEFS_STRUCT *;

/*----------------------------------------------------------------------
Generic functions for manipulating character descriptions
Expand Down
2 changes: 1 addition & 1 deletion src/classify/fpoint.h
Expand Up @@ -30,7 +30,7 @@ typedef struct
{
FLOAT32 x, y;
} FPOINT;
typedef FPOINT FVECTOR;
using FVECTOR = FPOINT;

/**----------------------------------------------------------------------------
Macros
Expand Down
8 changes: 4 additions & 4 deletions src/classify/ocrfeatures.h
Expand Up @@ -58,26 +58,26 @@ struct FEATURE_DESC_STRUCT {
const char *ShortName; // short name for feature
const PARAM_DESC *ParamDesc; // array - one per param
};
typedef FEATURE_DESC_STRUCT *FEATURE_DESC;
using FEATURE_DESC = FEATURE_DESC_STRUCT *;

struct FEATURE_STRUCT {
const FEATURE_DESC_STRUCT *Type; // points to description of feature type
FLOAT32 Params[1]; // variable size array - params for feature
};
typedef FEATURE_STRUCT *FEATURE;
using FEATURE = FEATURE_STRUCT *;

struct FEATURE_SET_STRUCT {
uint16_t NumFeatures; // number of features in set
uint16_t MaxNumFeatures; // maximum size of feature set
FEATURE Features[1]; // variable size array of features
};
typedef FEATURE_SET_STRUCT *FEATURE_SET;
using FEATURE_SET = FEATURE_SET_STRUCT *;

// A generic character description as a char pointer. In reality, it will be
// a pointer to some data structure. Paired feature extractors/matchers need
// to agree on the data structure to be used, however, the high level
// classifier does not need to know the details of this data structure.
typedef char *CHAR_FEATURES;
using CHAR_FEATURES = char *;

/*----------------------------------------------------------------------
Macros for defining the parameters of a new features
Expand Down
8 changes: 4 additions & 4 deletions src/classify/protos.h
Expand Up @@ -37,7 +37,7 @@
/*----------------------------------------------------------------------
T y p e s
----------------------------------------------------------------------*/
typedef BIT_VECTOR *CONFIGS;
using CONFIGS = BIT_VECTOR *;

typedef struct
{
Expand All @@ -49,7 +49,7 @@ typedef struct
FLOAT32 Angle;
FLOAT32 Length;
} PROTO_STRUCT;
typedef PROTO_STRUCT *PROTO;
using PROTO = PROTO_STRUCT *;

struct CLASS_STRUCT {
CLASS_STRUCT()
Expand All @@ -64,8 +64,8 @@ struct CLASS_STRUCT {
CONFIGS Configurations;
UnicityTableEqEq<int> font_set;
};
typedef CLASS_STRUCT *CLASS_TYPE;
typedef CLASS_STRUCT *CLASSES;
using CLASS_TYPE = CLASS_STRUCT *;
using CLASSES = CLASS_STRUCT *;

/*----------------------------------------------------------------------
C o n s t a n t s
Expand Down
2 changes: 1 addition & 1 deletion src/classify/shapetable.h
Expand Up @@ -153,7 +153,7 @@ struct ShapeQueueEntry {
// Which level in the tree did this come from?
int level;
};
typedef GenericHeap<ShapeQueueEntry> ShapeQueue;
using ShapeQueue = GenericHeap<ShapeQueueEntry>;

// Simple struct to hold a set of fonts associated with a single unichar-id.
// A vector of UnicharAndFonts makes a shape.
Expand Down
2 changes: 1 addition & 1 deletion src/cutil/bitvec.h
Expand Up @@ -25,7 +25,7 @@
-----------------------------------------------------------------------------*/
// TODO(rays) Rename BITSINLONG to BITSINuint32_t, and use sizeof.
#define BITSINLONG 32 /**< no of bits in a long */
typedef uint32_t *BIT_VECTOR;
using BIT_VECTOR = uint32_t *;

/*-----------------------------------------------------------------------------
Public Function Prototypes
Expand Down
2 changes: 1 addition & 1 deletion src/cutil/danerror.h
Expand Up @@ -24,7 +24,7 @@
#define NOERROR 0
#define DO_NOTHING 0

typedef int TRAPERROR;
using TRAPERROR = int;
typedef void (*VOID_PROC) ();

/**----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/cutil/oldlist.h
Expand Up @@ -129,7 +129,7 @@ struct list_rec
struct list_rec *node;
struct list_rec *next;
};
typedef list_rec *LIST;
using LIST = list_rec *;

/*----------------------------------------------------------------------
M a c r o s
Expand Down
16 changes: 8 additions & 8 deletions src/dict/dawg.h
Expand Up @@ -50,11 +50,11 @@
----------------------------------------------------------------------*/
class UNICHARSET;

typedef uint64_t EDGE_RECORD;
typedef EDGE_RECORD *EDGE_ARRAY;
typedef int64_t EDGE_REF;
typedef int64_t NODE_REF;
typedef EDGE_REF *NODE_MAP;
using EDGE_RECORD = uint64_t;
using EDGE_ARRAY = EDGE_RECORD *;
using EDGE_REF = int64_t;
using NODE_REF = int64_t;
using NODE_MAP = EDGE_REF *;

namespace tesseract {

Expand All @@ -65,9 +65,9 @@ struct NodeChild {
NodeChild(): unichar_id(INVALID_UNICHAR_ID), edge_ref(NO_EDGE) {}
};

typedef GenericVector<NodeChild> NodeChildVector;
typedef GenericVector<int> SuccessorList;
typedef GenericVector<SuccessorList *> SuccessorListsVector;
using NodeChildVector = GenericVector<NodeChild>;
using SuccessorList = GenericVector<int>;
using SuccessorListsVector = GenericVector<SuccessorList *>;

enum DawgType {
DAWG_TYPE_PUNCTUATION,
Expand Down
2 changes: 1 addition & 1 deletion src/dict/dict.h
Expand Up @@ -46,7 +46,7 @@ struct CHAR_FRAGMENT_INFO {

namespace tesseract {

typedef GenericVector<Dawg *> DawgVector;
using DawgVector = GenericVector<Dawg *>;

//
// Constants
Expand Down
10 changes: 5 additions & 5 deletions src/dict/matchdefs.h
Expand Up @@ -32,19 +32,19 @@
#define MAX_CLASS_ID (MAX_NUM_CLASSES - 1)

/** a CLASS_ID is the ascii character to be associated with a class */
typedef UNICHAR_ID CLASS_ID;
using CLASS_ID = UNICHAR_ID;
#define NO_CLASS (0)

/** a PROTO_ID is the index of a prototype within it's class. Valid proto
id's are 0 to N-1 where N is the number of prototypes that make up the
class. */
typedef int16_t PROTO_ID;
using PROTO_ID = int16_t;
#define NO_PROTO (-1)

/** FEATURE_ID is the index of a feature within a character description
The feature id ranges from 0 to N-1 where N is the number
of features in a character description. */
typedef uint8_t FEATURE_ID;
using FEATURE_ID = uint8_t;
#define NO_FEATURE 255
#define NOISE_FEATURE 254
#define MISSING_PROTO 254
Expand All @@ -53,13 +53,13 @@ typedef uint8_t FEATURE_ID;

/** a RATING is the match rating returned by a classifier.
Higher is better. */
typedef FLOAT32 RATING;
using RATING = FLOAT32;

/** a CERTAINTY is an indication of the degree of confidence of the
classifier. Higher is better. 0 means the match is as good as the
mean of the matches seen in training. -1 means the match was one
standard deviation worse than the training matches, etc. */
typedef FLOAT32 CERTAINTY;
using CERTAINTY = FLOAT32;

/** define a data structure to hold a single match result */
typedef struct
Expand Down
4 changes: 2 additions & 2 deletions src/dict/stopper.h
Expand Up @@ -29,7 +29,7 @@

class WERD_CHOICE;

typedef uint8_t BLOB_WIDTH;
using BLOB_WIDTH = uint8_t;

struct DANGERR_INFO {
DANGERR_INFO() :
Expand All @@ -44,7 +44,7 @@ struct DANGERR_INFO {
UNICHAR_ID leftmost; // in the replacement, what's the leftmost character?
};

typedef GenericVector<DANGERR_INFO> DANGERR;
using DANGERR = GenericVector<DANGERR_INFO>;


#endif
8 changes: 4 additions & 4 deletions src/dict/trie.h
Expand Up @@ -41,15 +41,15 @@ class UNICHARSET;
// It might be cleanest to change the types of most of the Trie/Dawg related
// typedefs to int and restrict the casts to extracting these values from
// the 64 bit EDGE_RECORD.
typedef int64_t EDGE_INDEX; // index of an edge in a given node
typedef bool *NODE_MARKER;
typedef GenericVector<EDGE_RECORD> EDGE_VECTOR;
using EDGE_INDEX = int64_t ; // index of an edge in a given node
using NODE_MARKER = bool *;
using EDGE_VECTOR = GenericVector<EDGE_RECORD> ;

struct TRIE_NODE_RECORD {
EDGE_VECTOR forward_edges;
EDGE_VECTOR backward_edges;
};
typedef GenericVector<TRIE_NODE_RECORD *> TRIE_NODES;
using TRIE_NODES = GenericVector<TRIE_NODE_RECORD *> ;

namespace tesseract {

Expand Down
2 changes: 1 addition & 1 deletion src/lstm/lstmtrainer.cpp
Expand Up @@ -1243,7 +1243,7 @@ double LSTMTrainer::ComputeCharError(const GenericVector<int>& truth_str,
// Computes word recall error rate using a very simple bag of words algorithm.
// NOTE that this is destructive on both input strings.
double LSTMTrainer::ComputeWordError(STRING* truth_str, STRING* ocr_str) {
typedef std::unordered_map<std::string, int, std::hash<std::string> > StrMap;
using StrMap = std::unordered_map<std::string, int, std::hash<std::string>>;
GenericVector<STRING> truth_words, ocr_words;
truth_str->split(' ', &truth_words);
if (truth_words.empty()) return 0.0;
Expand Down

0 comments on commit 0697235

Please sign in to comment.