From c8b8d266d64b7affa15492551fd75a0529817ae9 Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Sat, 26 Dec 2020 04:17:13 +0300 Subject: [PATCH] Fix some of vector cases for msvc. --- include/tesseract/genericvector.h | 7 +++++++ src/ccmain/control.cpp | 14 +++++++------- src/ccutil/unicharcompress.cpp | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/tesseract/genericvector.h b/include/tesseract/genericvector.h index 846e0f8d..fbf26a16 100644 --- a/include/tesseract/genericvector.h +++ b/include/tesseract/genericvector.h @@ -309,6 +309,13 @@ class GenericVector : public std::vector { std::function compare_cb_; }; +#ifdef _MSC_VER +// msvc does not have ::data() in vector, +// so we add custom specialization +template <> +class GenericVector : public std::vector {}; +#endif + // The default FileReader loads the whole file into the vector of char, // returning false on error. inline bool LoadDataFromFile(const char* filename, GenericVector* data) { diff --git a/src/ccmain/control.cpp b/src/ccmain/control.cpp index 8964f62e..8ab9e867 100644 --- a/src/ccmain/control.cpp +++ b/src/ccmain/control.cpp @@ -1007,9 +1007,9 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs( GenericVector* overlapped_any_blob, GenericVector* target_blobs) { GenericVector blob_wanted; - word_wanted->init_to_size(outlines.size(), false); - overlapped_any_blob->init_to_size(outlines.size(), false); - target_blobs->init_to_size(outlines.size(), nullptr); + word_wanted->resize(outlines.size(), false); + overlapped_any_blob->resize(outlines.size(), false); + target_blobs->resize(outlines.size(), nullptr); // For each real blob, find the outlines that seriously overlap it. // A single blob could be several merged characters, so there can be quite // a few outlines overlapping, and the full engine needs to be used to chop @@ -1018,7 +1018,7 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs( for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) { C_BLOB* blob = blob_it.data(); const TBOX blob_box = blob->bounding_box(); - blob_wanted.init_to_size(outlines.size(), false); + blob_wanted.resize(outlines.size(), false); int num_blob_outlines = 0; for (int i = 0; i < outlines.size(); ++i) { if (blob_box.major_x_overlap(outlines[i]->bounding_box()) && @@ -1059,13 +1059,13 @@ void Tesseract::AssignDiacriticsToNewBlobs( PAGE_RES_IT* pr_it, GenericVector* word_wanted, GenericVector* target_blobs) { GenericVector blob_wanted; - word_wanted->init_to_size(outlines.size(), false); - target_blobs->init_to_size(outlines.size(), nullptr); + word_wanted->resize(outlines.size(), false); + target_blobs->resize(outlines.size(), nullptr); // Check for outlines that need to be turned into stand-alone blobs. for (int i = 0; i < outlines.size(); ++i) { if (outlines[i] == nullptr) continue; // Get a set of adjacent outlines that don't overlap any existing blob. - blob_wanted.init_to_size(outlines.size(), false); + blob_wanted.resize(outlines.size(), false); int num_blob_outlines = 0; TBOX total_ol_box(outlines[i]->bounding_box()); while (i < outlines.size() && outlines[i] != nullptr) { diff --git a/src/ccutil/unicharcompress.cpp b/src/ccutil/unicharcompress.cpp index 29ed947e..3abaa9b9 100644 --- a/src/ccutil/unicharcompress.cpp +++ b/src/ccutil/unicharcompress.cpp @@ -372,7 +372,7 @@ void UnicharCompress::ComputeCodeRange() { // Initializes the decoding hash_map from the encoding array. void UnicharCompress::SetupDecoder() { Cleanup(); - is_valid_start_.init_to_size(code_range_, false); + is_valid_start_.resize(code_range_, false); for (int c = 0; c < encoder_.size(); ++c) { const RecodedCharID& code = encoder_[c]; decoder_[code] = c;