From b1eaa45c6a2316f084f5f6d3b0c004337963b63b Mon Sep 17 00:00:00 2001 From: QueensGambit Date: Mon, 5 Apr 2021 02:04:07 +0200 Subject: [PATCH] re-added get_file_ending_with() (#72) --- engine/src/nn/neuralnetapi.cpp | 9 +++++++++ engine/src/nn/neuralnetapi.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/engine/src/nn/neuralnetapi.cpp b/engine/src/nn/neuralnetapi.cpp index 64c3f245..e2fd0231 100644 --- a/engine/src/nn/neuralnetapi.cpp +++ b/engine/src/nn/neuralnetapi.cpp @@ -48,6 +48,15 @@ vector get_items_by_elment(const vector &stringVector, const str return returnVector; } +string get_file_ending_with(const string& dir, const string& suffix) { + const vector files = get_directory_files(dir); + const string retString = get_string_ending_with(files, suffix); + if (retString == "") { + throw invalid_argument( "The given directory at " + dir + " doesn't contain a file ending with " + suffix); + } + return retString; +} + unsigned int NeuralNetAPI::get_batch_size() const { diff --git a/engine/src/nn/neuralnetapi.h b/engine/src/nn/neuralnetapi.h index 961d71bc..09d9c2ac 100644 --- a/engine/src/nn/neuralnetapi.h +++ b/engine/src/nn/neuralnetapi.h @@ -82,6 +82,14 @@ string get_string_ending_with(const vector& stringVector, const string& */ vector get_items_by_elment(const vector& stringVector, const string& targetString, bool shouldContain); +/** + * @brief get_file_ending_with Returns the first file of a directory ending with the given suffix + * @param dir Directory where to look for the file + * @param suffix Suffix which must be at the end of the file + * @return The filename of found file excluding the directory and "" and invalid_argument if no file was found + */ +string get_file_ending_with(const string& dir, const string& suffix); + template /**