diff --git a/src/ccstruct/boxread.cpp b/src/ccstruct/boxread.cpp index a5212e19..aa65cf1b 100644 --- a/src/ccstruct/boxread.cpp +++ b/src/ccstruct/boxread.cpp @@ -56,7 +56,7 @@ bool ReadAllBoxes(int target_page, bool skip_blanks, const STRING& filename, GenericVector* box_texts, GenericVector* pages) { GenericVector box_data; - if (!tesseract::LoadDataFromFile(BoxFileName(filename), &box_data)) + if (!tesseract::LoadDataFromFile(BoxFileName(filename).c_str(), &box_data)) return false; // Convert the array of bytes to a string, so it can be used by the parser. box_data.push_back('\0'); diff --git a/src/ccutil/genericvector.h b/src/ccutil/genericvector.h index 55384d04..6e79d548 100644 --- a/src/ccutil/genericvector.h +++ b/src/ccutil/genericvector.h @@ -361,16 +361,11 @@ inline bool LoadDataFromFile(const char* filename, GenericVector* data) { return result; } -inline bool LoadDataFromFile(const STRING& filename, - GenericVector* data) { - return LoadDataFromFile(filename.string(), data); -} - // The default FileWriter writes the vector of char to the filename file, // returning false on error. inline bool SaveDataToFile(const GenericVector& data, - const STRING& filename) { - FILE* fp = fopen(filename.string(), "wb"); + const char* filename) { + FILE* fp = fopen(filename, "wb"); if (fp == nullptr) { return false; } @@ -380,10 +375,10 @@ inline bool SaveDataToFile(const GenericVector& data, return result; } // Reads a file as a vector of STRING. -inline bool LoadFileLinesToStrings(const STRING& filename, +inline bool LoadFileLinesToStrings(const char* filename, GenericVector* lines) { GenericVector data; - if (!LoadDataFromFile(filename.string(), &data)) { + if (!LoadDataFromFile(filename, &data)) { return false; } STRING lines_str(&data[0], data.size()); diff --git a/src/ccutil/serialis.cpp b/src/ccutil/serialis.cpp index 6faeb6f0..b740a5b5 100644 --- a/src/ccutil/serialis.cpp +++ b/src/ccutil/serialis.cpp @@ -2,7 +2,6 @@ * File: serialis.cpp (Formerly serialmac.h) * Description: Inline routines and macros for serialisation functions * Author: Phil Cheatle - * Created: Tue Oct 08 08:33:12 BST 1991 * * (C) Copyright 1990, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -202,9 +201,9 @@ bool TFile::Open(const STRING& filename, FileReader reader) { is_writing_ = false; swap_ = false; if (reader == nullptr) - return LoadDataFromFile(filename, data_); + return LoadDataFromFile(filename.c_str(), data_); else - return (*reader)(filename, data_); + return (*reader)(filename.c_str(), data_); } bool TFile::Open(const char* data, int size) { @@ -310,9 +309,9 @@ void TFile::OpenWrite(GenericVector* data) { bool TFile::CloseWrite(const STRING& filename, FileWriter writer) { ASSERT_HOST(is_writing_); if (writer == nullptr) - return SaveDataToFile(*data_, filename); + return SaveDataToFile(*data_, filename.c_str()); else - return (*writer)(*data_, filename); + return (*writer)(*data_, filename.c_str()); } int TFile::FWrite(const void* buffer, size_t size, int count) { diff --git a/src/ccutil/serialis.h b/src/ccutil/serialis.h index 604f44c2..076d28e7 100644 --- a/src/ccutil/serialis.h +++ b/src/ccutil/serialis.h @@ -46,10 +46,10 @@ constexpr size_t countof(T const (&)[N]) noexcept { // Function to read a GenericVector from a whole file. // Returns false on failure. -using FileReader = bool (*)(const STRING&, GenericVector*); +using FileReader = bool (*)(const char* filename, GenericVector* data); // Function to write a GenericVector to a whole file. // Returns false on failure. -using FileWriter = bool (*)(const GenericVector&, const STRING&); +using FileWriter = bool (*)(const GenericVector& data, const char* filename); // Deserialize data from file. bool DeSerialize(FILE* fp, char* data, size_t n = 1); diff --git a/src/ccutil/tessdatamanager.cpp b/src/ccutil/tessdatamanager.cpp index ef83ba9f..ecd400c1 100644 --- a/src/ccutil/tessdatamanager.cpp +++ b/src/ccutil/tessdatamanager.cpp @@ -157,9 +157,9 @@ bool TessdataManager::SaveFile(const STRING &filename, GenericVector data; Serialize(&data); if (writer == nullptr) - return SaveDataToFile(data, filename); + return SaveDataToFile(data, filename.c_str()); else - return (*writer)(data, filename); + return (*writer)(data, filename.c_str()); } // Serializes to the given vector. @@ -253,7 +253,7 @@ bool TessdataManager::CombineDataFiles( FILE *fp = fopen(filename.string(), "rb"); if (fp != nullptr) { fclose(fp); - if (!LoadDataFromFile(filename, &entries_[type])) { + if (!LoadDataFromFile(filename.c_str(), &entries_[type])) { tprintf("Load of file %s failed!\n", filename.string()); return false; } diff --git a/src/training/lstmtester.cpp b/src/training/lstmtester.cpp index 045820d8..826039df 100644 --- a/src/training/lstmtester.cpp +++ b/src/training/lstmtester.cpp @@ -29,7 +29,7 @@ LSTMTester::LSTMTester(int64_t max_memory) // loaded. The arg is a filename of a file that lists the filenames. bool LSTMTester::LoadAllEvalData(const STRING& filenames_file) { GenericVector filenames; - if (!LoadFileLinesToStrings(filenames_file, &filenames)) { + if (!LoadFileLinesToStrings(filenames_file.c_str(), &filenames)) { tprintf("Failed to load list of eval filenames from %s\n", filenames_file.string()); return false; diff --git a/src/training/lstmtrainer.cpp b/src/training/lstmtrainer.cpp index 78bf8ba0..5185a78e 100644 --- a/src/training/lstmtrainer.cpp +++ b/src/training/lstmtrainer.cpp @@ -320,7 +320,7 @@ bool LSTMTrainer::MaintainCheckpoints(TestCallback tester, STRING* log_msg) { SaveTrainingDump(NO_BEST_TRAINER, this, &best_trainer_); if (error_rate < error_rate_of_last_saved_best_ * kBestCheckpointFraction) { STRING best_model_name = DumpFilename(); - if (!SaveDataToFile(best_trainer_, best_model_name)) { + if (!SaveDataToFile(best_trainer_, best_model_name.c_str())) { *log_msg += " failed to write best model:"; } else { *log_msg += " wrote best model:"; @@ -358,7 +358,7 @@ bool LSTMTrainer::MaintainCheckpoints(TestCallback tester, STRING* log_msg) { // Write a current checkpoint. GenericVector checkpoint; if (!SaveTrainingDump(FULL, this, &checkpoint) || - !SaveDataToFile(checkpoint, checkpoint_name_)) { + !SaveDataToFile(checkpoint, checkpoint_name_.c_str())) { *log_msg += " failed to write checkpoint."; } else { *log_msg += " wrote checkpoint.";