Skip to content

Commit

Permalink
Modernize C++ code using auto
Browse files Browse the repository at this point in the history
The modifications were done using this command:

    run-clang-tidy-8.py -header-filter='.*' -checks='-*,modernize-use-auto' -fix

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 26, 2019
1 parent 36f7688 commit a0fd905
Show file tree
Hide file tree
Showing 102 changed files with 280 additions and 280 deletions.
24 changes: 12 additions & 12 deletions src/api/baseapi.cpp
Expand Up @@ -176,8 +176,8 @@ static void addAvailableLanguages(const STRING &datadir, const STRING &base,

// Compare two STRING values (used for sorting).
static int CompareSTRING(const void* p1, const void* p2) {
const STRING* s1 = static_cast<const STRING*>(p1);
const STRING* s2 = static_cast<const STRING*>(p2);
const auto* s1 = static_cast<const STRING*>(p1);
const auto* s2 = static_cast<const STRING*>(p2);
return strcmp(s1->c_str(), s2->c_str());
}

Expand Down Expand Up @@ -298,29 +298,29 @@ bool TessBaseAPI::SetDebugVariable(const char* name, const char* value) {
}

bool TessBaseAPI::GetIntVariable(const char *name, int *value) const {
IntParam *p = ParamUtils::FindParam<IntParam>(
auto *p = ParamUtils::FindParam<IntParam>(
name, GlobalParams()->int_params, tesseract_->params()->int_params);
if (p == nullptr) return false;
*value = (int32_t)(*p);
return true;
}

bool TessBaseAPI::GetBoolVariable(const char *name, bool *value) const {
BoolParam *p = ParamUtils::FindParam<BoolParam>(
auto *p = ParamUtils::FindParam<BoolParam>(
name, GlobalParams()->bool_params, tesseract_->params()->bool_params);
if (p == nullptr) return false;
*value = (BOOL8)(*p);
return true;
}

const char *TessBaseAPI::GetStringVariable(const char *name) const {
StringParam *p = ParamUtils::FindParam<StringParam>(
auto *p = ParamUtils::FindParam<StringParam>(
name, GlobalParams()->string_params, tesseract_->params()->string_params);
return (p != nullptr) ? p->string() : nullptr;
}

bool TessBaseAPI::GetDoubleVariable(const char *name, double *value) const {
DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
auto *p = ParamUtils::FindParam<DoubleParam>(
name, GlobalParams()->double_params, tesseract_->params()->double_params);
if (p == nullptr) return false;
*value = (double)(*p);
Expand Down Expand Up @@ -873,7 +873,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {

if (truth_cb_ != nullptr) {
tesseract_->wordrec_run_blamer.set_value(true);
PageIterator *page_it = new PageIterator(
auto *page_it = new PageIterator(
page_res_, tesseract_, thresholder_->GetScaleFactor(),
thresholder_->GetScaledYResolution(),
rect_left_, rect_top_, rect_width_, rect_height_);
Expand Down Expand Up @@ -1989,7 +1989,7 @@ bool TessBaseAPI::Threshold(Pix** pix) {
y_res, kMinCredibleResolution);
thresholder_->SetSourceYResolution(kMinCredibleResolution);
}
PageSegMode pageseg_mode =
auto pageseg_mode =
static_cast<PageSegMode>(
static_cast<int>(tesseract_->tessedit_pageseg_mode));
if (!thresholder_->ThresholdToPix(pageseg_mode, pix)) return false;
Expand Down Expand Up @@ -2419,7 +2419,7 @@ void TessBaseAPI::AdaptToCharacter(const char *unichar_repr,


PAGE_RES* TessBaseAPI::RecognitionPass1(BLOCK_LIST* block_list) {
PAGE_RES *page_res = new PAGE_RES(false, block_list,
auto *page_res = new PAGE_RES(false, block_list,
&(tesseract_->prev_word_best_choice_));
tesseract_->recog_all_words(page_res, nullptr, nullptr, nullptr, 1);
return page_res;
Expand Down Expand Up @@ -2461,7 +2461,7 @@ ELISTIZEH(TESS_CHAR)
ELISTIZE(TESS_CHAR)

static void add_space(TESS_CHAR_IT* it) {
TESS_CHAR *t = new TESS_CHAR(0, " ");
auto *t = new TESS_CHAR(0, " ");
it->add_after_then_move(t);
}

Expand Down Expand Up @@ -2493,7 +2493,7 @@ static void extract_result(TESS_CHAR_IT* out,
add_space(out);
int n = strlen(len);
for (int i = 0; i < n; i++) {
TESS_CHAR *tc = new TESS_CHAR(rating_to_cost(word->best_choice->rating()),
auto *tc = new TESS_CHAR(rating_to_cost(word->best_choice->rating()),
str, *len);
tc->box = real_rect.intersection(word->box_word->BlobBox(i));
out->add_after_then_move(tc);
Expand Down Expand Up @@ -2619,7 +2619,7 @@ void TessBaseAPI::RunAdaptiveClassifier(TBLOB* blob,
int* unichar_ids,
float* ratings,
int* num_matches_returned) {
BLOB_CHOICE_LIST* choices = new BLOB_CHOICE_LIST;
auto* choices = new BLOB_CHOICE_LIST;
tesseract_->AdaptiveClassifier(blob, choices);
BLOB_CHOICE_IT choices_it(choices);
int& index = *num_matches_returned;
Expand Down
18 changes: 9 additions & 9 deletions src/api/tesseractmain.cpp
Expand Up @@ -429,7 +429,7 @@ static void PreloadRenderers(
if (b) {
bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info);
tesseract::TessHOcrRenderer* renderer =
auto* renderer =
new tesseract::TessHOcrRenderer(outputbase, font_info);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -443,7 +443,7 @@ static void PreloadRenderers(

api->GetBoolVariable("tessedit_create_alto", &b);
if (b) {
tesseract::TessAltoRenderer* renderer =
auto* renderer =
new tesseract::TessAltoRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -459,7 +459,7 @@ static void PreloadRenderers(
if (b) {
bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info);
tesseract::TessTsvRenderer* renderer =
auto* renderer =
new tesseract::TessTsvRenderer(outputbase, font_info);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -479,7 +479,7 @@ static void PreloadRenderers(
#endif // WIN32
bool textonly;
api->GetBoolVariable("textonly_pdf", &textonly);
tesseract::TessPDFRenderer* renderer =
auto* renderer =
new tesseract::TessPDFRenderer(outputbase, api->GetDatapath(),
textonly);
if (renderer->happy()) {
Expand All @@ -495,7 +495,7 @@ static void PreloadRenderers(
api->GetBoolVariable("tessedit_write_unlv", &b);
if (b) {
api->SetVariable("unlv_tilde_crunching", "true");
tesseract::TessUnlvRenderer* renderer =
auto* renderer =
new tesseract::TessUnlvRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -509,7 +509,7 @@ static void PreloadRenderers(

api->GetBoolVariable("tessedit_create_lstmbox", &b);
if (b) {
tesseract::TessLSTMBoxRenderer* renderer =
auto* renderer =
new tesseract::TessLSTMBoxRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -523,7 +523,7 @@ static void PreloadRenderers(

api->GetBoolVariable("tessedit_create_boxfile", &b);
if (b) {
tesseract::TessBoxTextRenderer* renderer =
auto* renderer =
new tesseract::TessBoxTextRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -537,7 +537,7 @@ static void PreloadRenderers(

api->GetBoolVariable("tessedit_create_wordstrbox", &b);
if (b) {
tesseract::TessWordStrBoxRenderer* renderer =
auto* renderer =
new tesseract::TessWordStrBoxRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand All @@ -551,7 +551,7 @@ static void PreloadRenderers(

api->GetBoolVariable("tessedit_create_txt", &b);
if (b || (!error && renderers->empty())) {
tesseract::TessTextRenderer* renderer =
auto* renderer =
new tesseract::TessTextRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
Expand Down
2 changes: 1 addition & 1 deletion src/arch/intsimdmatrixavx2.cpp
Expand Up @@ -85,7 +85,7 @@ static inline void ExtractResults(__m256i& result, __m256i& shift_id,
const int8_t*& wi, const double*& scales,
int num_out, double*& v) {
for (int out = 0; out < num_out; ++out) {
int32_t res =
auto res =
#ifndef _MSC_VER
_mm256_extract_epi32(result, 0)
#else
Expand Down
14 changes: 7 additions & 7 deletions src/ccmain/applybox.cpp
Expand Up @@ -226,7 +226,7 @@ PAGE_RES* Tesseract::SetupApplyBoxes(const GenericVector<TBOX>& boxes,
}
}
}
PAGE_RES* page_res = new PAGE_RES(false, block_list, nullptr);
auto* page_res = new PAGE_RES(false, block_list, nullptr);
PAGE_RES_IT pr_it(page_res);
WERD_RES* word_res;
while ((word_res = pr_it.word()) != nullptr) {
Expand Down Expand Up @@ -258,7 +258,7 @@ void Tesseract::MaximallyChopWord(const GenericVector<TBOX>& boxes,
}
GenericVector<BLOB_CHOICE*> blob_choices;
ASSERT_HOST(!word_res->chopped_word->blobs.empty());
float rating = static_cast<float>(INT8_MAX);
auto rating = static_cast<float>(INT8_MAX);
for (int i = 0; i < word_res->chopped_word->NumBlobs(); ++i) {
// The rating and certainty are not quite arbitrary. Since
// select_blob_to_chop uses the worst certainty to choose, they all have
Expand All @@ -268,7 +268,7 @@ void Tesseract::MaximallyChopWord(const GenericVector<TBOX>& boxes,
// produced, however much chopping is required. The chops are thus only
// limited by the ability of the chopper to find suitable chop points,
// and not by the value of the certainties.
BLOB_CHOICE* choice =
auto* choice =
new BLOB_CHOICE(0, rating, -rating, -1, 0.0f, 0.0f, 0.0f, BCC_FAKE);
blob_choices.push_back(choice);
rating -= 0.125f;
Expand All @@ -287,7 +287,7 @@ void Tesseract::MaximallyChopWord(const GenericVector<TBOX>& boxes,
left_choice->set_rating(rating);
left_choice->set_certainty(-rating);
// combine confidence w/ serial #
BLOB_CHOICE* right_choice = new BLOB_CHOICE(++right_chop_index,
auto* right_choice = new BLOB_CHOICE(++right_chop_index,
rating - 0.125f, -rating, -1,
0.0f, 0.0f, 0.0f, BCC_FAKE);
blob_choices.insert(right_choice, blob_number + 1);
Expand Down Expand Up @@ -566,7 +566,7 @@ bool Tesseract::FindSegmentation(const GenericVector<UNICHAR_ID>& target_text,
WERD_RES* word_res) {
// Classify all required combinations of blobs and save results in choices.
const int word_length = word_res->box_word->length();
GenericVector<BLOB_CHOICE_LIST*>* choices =
auto* choices =
new GenericVector<BLOB_CHOICE_LIST*>[word_length];
for (int i = 0; i < word_length; ++i) {
for (int j = 1; j <= kMaxGroupSize && i + j <= word_length; ++j) {
Expand Down Expand Up @@ -719,7 +719,7 @@ void Tesseract::TidyUp(PAGE_RES* page_res) {
for (; (word_res = pr_it.word()) != nullptr; pr_it.forward()) {
int ok_in_word = 0;
int blob_count = word_res->correct_text.size();
WERD_CHOICE* word_choice = new WERD_CHOICE(word_res->uch_set, blob_count);
auto* word_choice = new WERD_CHOICE(word_res->uch_set, blob_count);
word_choice->set_permuter(TOP_CHOICE_PERM);
for (int c = 0; c < blob_count; ++c) {
if (word_res->correct_text[c].length() > 0) {
Expand Down Expand Up @@ -781,7 +781,7 @@ void Tesseract::CorrectClassifyWords(PAGE_RES* page_res) {
PAGE_RES_IT pr_it(page_res);
for (WERD_RES *word_res = pr_it.word(); word_res != nullptr;
word_res = pr_it.forward()) {
WERD_CHOICE* choice = new WERD_CHOICE(word_res->uch_set,
auto* choice = new WERD_CHOICE(word_res->uch_set,
word_res->correct_text.size());
for (int i = 0; i < word_res->correct_text.size(); ++i) {
// The part before the first space is the real ground truth, and the
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/control.cpp
Expand Up @@ -197,7 +197,7 @@ void Tesseract::SetupWordPassN(int pass_n, WordData* word) {
for (int s = 0; s <= sub_langs_.size(); ++s) {
// The sub_langs_.size() entry is for the master language.
Tesseract* lang_t = s < sub_langs_.size() ? sub_langs_[s] : this;
WERD_RES* word_res = new WERD_RES;
auto* word_res = new WERD_RES;
word_res->InitForRetryRecognition(*word->word);
word->lang_words.push_back(word_res);
// LSTM doesn't get setup for pass2.
Expand Down Expand Up @@ -444,7 +444,7 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res,
// end jetsoft
#endif //ndef DISABLED_LEGACY_ENGINE

const PageSegMode pageseg_mode = static_cast<PageSegMode>(
const auto pageseg_mode = static_cast<PageSegMode>(
static_cast<int>(tessedit_pageseg_mode));
textord_.CleanupSingleRowResult(pageseg_mode, page_res);

Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/equationdetect.cpp
Expand Up @@ -1511,7 +1511,7 @@ void EquationDetect::PrintSpecialBlobsDensity(const ColPartition* part) const {
box.print();
tprintf("blobs count = %d, density = ", part->boxes_count());
for (int i = 0; i < BSTT_COUNT; ++i) {
BlobSpecialTextType type = static_cast<BlobSpecialTextType>(i);
auto type = static_cast<BlobSpecialTextType>(i);
tprintf("%d:%f ", i, part->SpecialBlobsDensity(type));
}
tprintf("\n");
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/fixspace.cpp
Expand Up @@ -699,7 +699,7 @@ void Tesseract::break_noisiest_blob_word(WERD_RES_LIST &words) {
new_rej_cblob_it.add_after_then_move(rej_cblob_it.extract());
}

WERD_RES* new_word_res = new WERD_RES(new_word);
auto* new_word_res = new WERD_RES(new_word);
new_word_res->combination = true;
worst_word_it.add_before_then_move(new_word_res);

Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/osdetect.cpp
Expand Up @@ -300,7 +300,7 @@ int os_detect_blobs(const GenericVector<int>* allowed_scripts,
return 0;
}

BLOBNBOX** blobs = new BLOBNBOX*[filtered_it.length()];
auto** blobs = new BLOBNBOX*[filtered_it.length()];
int number_of_blobs = 0;
for (filtered_it.mark_cycle_pt (); !filtered_it.cycled_list ();
filtered_it.forward ()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/pagesegmain.cpp
Expand Up @@ -103,7 +103,7 @@ int Tesseract::SegmentPage(const STRING* input_file, BLOCK_LIST* blocks,
int width = pixGetWidth(pix_binary_);
int height = pixGetHeight(pix_binary_);
// Get page segmentation mode.
PageSegMode pageseg_mode = static_cast<PageSegMode>(
auto pageseg_mode = static_cast<PageSegMode>(
static_cast<int>(tessedit_pageseg_mode));
// If a UNLV zone file can be found, use that instead of segmentation.
if (!PSM_COL_FIND_ENABLED(pageseg_mode) &&
Expand All @@ -118,7 +118,7 @@ int Tesseract::SegmentPage(const STRING* input_file, BLOCK_LIST* blocks,
// No UNLV file present. Work according to the PageSegMode.
// First make a single block covering the whole image.
BLOCK_IT block_it(blocks);
BLOCK* block = new BLOCK("", TRUE, 0, 0, 0, 0, width, height);
auto* block = new BLOCK("", TRUE, 0, 0, 0, 0, width, height);
block->set_right_to_left(right_to_left());
block_it.add_to_end(block);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/paragraphs.cpp
Expand Up @@ -1229,7 +1229,7 @@ const ParagraphModel *ParagraphTheory::AddModel(const ParagraphModel &model) {
if ((*models_)[i]->Comparable(model))
return (*models_)[i];
}
ParagraphModel *m = new ParagraphModel(model);
auto *m = new ParagraphModel(model);
models_->push_back(m);
models_we_added_.push_back_new(m);
return m;
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/paramsd.cpp
Expand Up @@ -190,7 +190,7 @@ int ParamContent::Compare(const void* v1, const void* v2) {
// SVMenuNode tree from it.
// TODO (wanke): This is actually sort of hackish.
SVMenuNode* ParamsEditor::BuildListOfAllLeaves(tesseract::Tesseract *tess) {
SVMenuNode* mr = new SVMenuNode();
auto* mr = new SVMenuNode();
ParamContent_LIST vclist;
ParamContent_IT vc_it(&vclist);
// Amount counts the number of entries for a specific char*.
Expand Down Expand Up @@ -341,7 +341,7 @@ void ParamsEditor::WriteParams(char *filename,
return;
}

for (std::map<int, ParamContent*>::iterator iter = vcMap.begin();
for (auto iter = vcMap.begin();
iter != vcMap.end();
++iter) {
ParamContent* cur = iter->second;
Expand Down
6 changes: 3 additions & 3 deletions src/ccmain/pgedit.cpp
Expand Up @@ -168,7 +168,7 @@ ScrollView* bln_word_window_handle() { // return handle
bln_word_window = new ScrollView(editor_word_name.string(),
editor_word_xpos, editor_word_ypos, editor_word_width,
editor_word_height, 4000, 4000, true);
BlnEventHandler* a = new BlnEventHandler();
auto* a = new BlnEventHandler();
bln_word_window->AddEventHandler(a);
pgeditor_msg("Creating BLN word window...Done");
}
Expand Down Expand Up @@ -245,7 +245,7 @@ void PGEventHandler::Notify(const SVEvent* event) {
namespace tesseract {
SVMenuNode *Tesseract::build_menu_new() {
SVMenuNode* parent_menu;
SVMenuNode* root_menu_item = new SVMenuNode();
auto* root_menu_item = new SVMenuNode();

SVMenuNode* modes_menu_item = root_menu_item->AddChild("MODES");

Expand Down Expand Up @@ -827,7 +827,7 @@ bool Tesseract::word_display(PAGE_RES_IT* pr_it) {
(ScrollView::Color)((int32_t)
editor_image_word_bb_color));

ScrollView::Color c = (ScrollView::Color)
auto c = (ScrollView::Color)
((int32_t) editor_image_blob_bb_color);
image_win->Pen(c);
// cblob iterator
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/recogtraining.cpp
Expand Up @@ -227,7 +227,7 @@ void Tesseract::ambigs_classify_and_output(const char *label,

// Dump all paths through the ratings matrix (which is normally small).
int dim = werd_res->ratings->dimension();
const BLOB_CHOICE** blob_choices = new const BLOB_CHOICE*[dim];
const auto** blob_choices = new const BLOB_CHOICE*[dim];
PrintMatrixPaths(0, dim, *werd_res->ratings, 0, blob_choices,
unicharset, label, output_file);
delete [] blob_choices;
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/resultiterator.cpp
Expand Up @@ -38,7 +38,7 @@ ResultIterator::ResultIterator(const LTRResultIterator &resit)
at_beginning_of_minor_run_ = false;
preserve_interword_spaces_ = false;

BoolParam *p = ParamUtils::FindParam<BoolParam>(
auto *p = ParamUtils::FindParam<BoolParam>(
"preserve_interword_spaces", GlobalParams()->bool_params,
tesseract_->params()->bool_params);
if (p != nullptr) preserve_interword_spaces_ = (bool)(*p);
Expand Down Expand Up @@ -704,7 +704,7 @@ void ResultIterator::AppendUTF8ParagraphText(STRING *text) const {

bool ResultIterator::BidiDebug(int min_level) const {
int debug_level = 1;
IntParam *p = ParamUtils::FindParam<IntParam>(
auto *p = ParamUtils::FindParam<IntParam>(
"bidi_debug", GlobalParams()->int_params,
tesseract_->params()->int_params);
if (p != nullptr) debug_level = (int32_t)(*p);
Expand Down

0 comments on commit a0fd905

Please sign in to comment.