aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-01-22 21:18:53 +0100
committer GitHub <noreply@github.com>2024-01-22 21:18:53 +0100
commit10f1f250883529e809d18a369f3668cfacd3bfd1 (patch)
tree7cd8a379963af18c24f8dabfe7525b39f2333e0c /src/openvic-simulation/dataloader
parent8205732a1b95f018f0898a2a4bc62e22f5bee0d3 (diff)
parentcaa2f31d536f568e485f15537db5e2f79f7616d5 (diff)
Merge pull request #135 from OpenVicProject/misc-changes
Miscellaneous bug fixes and format cleanup
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp9
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp10
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp10
3 files changed, 14 insertions, 15 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 6a2a3bb..cce766f 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -109,10 +109,7 @@ fs::path Dataloader::lookup_image_file(std::string_view path) const {
return lookup_file(path);
}
-template<typename _DirIterator, typename _UniqueKey>
-requires requires (_UniqueKey const& unique_key, std::string_view path) {
- { unique_key(path) } -> std::convertible_to<std::string_view>;
-}
+template<typename _DirIterator, UniqueFileKey _UniqueKey>
Dataloader::path_vector_t Dataloader::_lookup_files_in_dir(
std::string_view path, fs::path const& extension, _UniqueKey const& unique_key
) const {
@@ -129,7 +126,7 @@ Dataloader::path_vector_t Dataloader::_lookup_files_in_dir(
for (fs::directory_entry const& entry : _DirIterator { root / dirpath, ec }) {
if (entry.is_regular_file()) {
fs::path file = entry;
- if ((extension.empty() || file.extension() == extension)) {
+ if (extension.empty() || file.extension() == extension) {
const std::string full_path = file.string();
std::string_view relative_path = full_path;
relative_path.remove_prefix(root_len);
@@ -142,7 +139,7 @@ Dataloader::path_vector_t Dataloader::_lookup_files_in_dir(
ret.emplace_back(std::move(file));
} else if (it->second.root == &root) {
Logger::warning(
- "Files in the same directory with conflicting keys: ", it->first, " - ", it->second.file,
+ "Files under the same root with conflicting keys: ", it->first, " - ", it->second.file,
" (accepted) and ", key, " - ", file, " (rejected)"
);
}
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index de72fcd..31e0904 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -11,6 +11,11 @@ namespace OpenVic {
struct GameManager;
class UIManager;
+ template<typename _UniqueFileKey>
+ concept UniqueFileKey = requires(_UniqueFileKey const& unique_key, std::string_view path) {
+ requires std::same_as<std::remove_cvref_t<decltype(unique_key(path))>, std::string_view>;
+ };
+
class Dataloader {
public:
using path_vector_t = std::vector<fs::path>;
@@ -34,10 +39,7 @@ namespace OpenVic {
/* _DirIterator is fs::directory_iterator or fs::recursive_directory_iterator. _UniqueKey is the type of a callable
* which converts a string_view filepath with root removed into a string_view unique key. Any path whose key is empty
* or matches an earlier found path's key is discarded, ensuring each looked up path's key is non-empty and unique. */
- template<typename _DirIterator, typename _UniqueKey>
- requires requires (_UniqueKey const& unique_key, std::string_view path) {
- { unique_key(path) } -> std::convertible_to<std::string_view>;
- }
+ template<typename _DirIterator, UniqueFileKey _UniqueKey>
path_vector_t _lookup_files_in_dir(
std::string_view path, fs::path const& extension, _UniqueKey const& unique_key
) const;
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 4b33c6d..0845e6c 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -357,17 +357,17 @@ namespace OpenVic {
}
template<typename... Args>
- bool warn_or_error(bool warn, Args... args) {
+ bool warn_or_error(bool warn, Args&&... args) {
if (warn) {
- Logger::warning(args...);
+ Logger::warning(std::forward<Args>(args)...);
return true;
} else {
- Logger::error(args...);
+ Logger::error(std::forward<Args>(args)...);
return false;
}
}
- template<typename T, typename U, typename...SetArgs>
+ template<typename T, typename U, typename... SetArgs>
Callback<T> auto set_callback(tsl::ordered_set<U, SetArgs...>& set, bool warn = false) {
return [&set, warn](T val) -> bool {
if (set.emplace(std::move(val)).second) {
@@ -377,7 +377,7 @@ namespace OpenVic {
};
}
- template<std::derived_from<HasIdentifier> T, typename...SetArgs>
+ template<std::derived_from<HasIdentifier> T, typename... SetArgs>
Callback<T const&> auto set_callback_pointer(tsl::ordered_set<T const*, SetArgs...>& set, bool warn = false) {
return [&set, warn](T const& val) -> bool {
if (set.emplace(&val).second) {