From d6be96109567a2e361ce3599fe6e1e3f6b0a5df5 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 26 Jul 2025 21:49:49 +0100 Subject: [PATCH] Be a bit more consistent with function naming This makes it so that all non-public functions use camelCase and all public functions use PascalCase. I regret choosing to use PascalCase for function names, but it's not worth breaking the whole public API to change that, and at least this approach has precedent in how Go decides if a function is public or private. --- cpp/src/api/api.cpp | 7 ++++--- cpp/src/api/exception/cyclic_interaction_error.cpp | 6 +++--- cpp/src/api/game.cpp | 12 ++++++------ cpp/src/api/game.h | 3 --- cpp/src/api/metadata/plugin_metadata.cpp | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cpp/src/api/api.cpp b/cpp/src/api/api.cpp index d1cd4923..ac277e9f 100644 --- a/cpp/src/api/api.cpp +++ b/cpp/src/api/api.cpp @@ -67,7 +67,7 @@ loot::rust::LogLevel convert(LogLevel level) { } } -void logging_callback(uint8_t level, const char* message, void* context) { +void loggingCallback(uint8_t level, const char* message, void* context) { auto& callback = *static_cast(context); callback(convert(level), message); @@ -75,9 +75,10 @@ void logging_callback(uint8_t level, const char* message, void* context) { } namespace loot { -LOOT_API void SetLoggingCallback(Callback callback) { +LOOT_API void SetLoggingCallback( + std::function callback) { STORED_CALLBACK = callback; - libloot_set_logging_callback(logging_callback, &STORED_CALLBACK); + libloot_set_logging_callback(loggingCallback, &STORED_CALLBACK); } LOOT_API void SetLogLevel(LogLevel level) { diff --git a/cpp/src/api/exception/cyclic_interaction_error.cpp b/cpp/src/api/exception/cyclic_interaction_error.cpp index d62f5332..b01ee0c7 100644 --- a/cpp/src/api/exception/cyclic_interaction_error.cpp +++ b/cpp/src/api/exception/cyclic_interaction_error.cpp @@ -56,11 +56,9 @@ std::string describeEdgeType(EdgeType edgeType) { return "Unknown"; } } -} -namespace loot { // A.esp --[Master Flag]-> B.esp --Group-> -std::string describeCycle(const std::vector& cycle) { +std::string describeCycle(const std::vector& cycle) { std::string text; for (const auto& vertex : cycle) { text += vertex.GetName(); @@ -76,7 +74,9 @@ std::string describeCycle(const std::vector& cycle) { return text; } +} +namespace loot { CyclicInteractionError::CyclicInteractionError(std::vector cycle) : std::runtime_error("Cyclic interaction detected: " + describeCycle(cycle)), cycle_(cycle) {} diff --git a/cpp/src/api/game.cpp b/cpp/src/api/game.cpp index fafac74d..939eaa7c 100644 --- a/cpp/src/api/game.cpp +++ b/cpp/src/api/game.cpp @@ -67,7 +67,7 @@ loot::rust::GameType convert(loot::GameType gameType) { } } -std::filesystem::path to_path(const rust::String& string) { +std::filesystem::path toPath(const rust::String& string) { return std::filesystem::u8path(string.begin(), string.end()); } @@ -87,7 +87,7 @@ rust::Box constructGame( } } -std::vector<::rust::Str> as_str_refs(const std::vector& vector) { +std::vector<::rust::Str> asStrRefs(const std::vector& vector) { std::vector<::rust::Str> strings; for (const auto& str : vector) { strings.push_back(str); @@ -120,7 +120,7 @@ std::vector Game::GetAdditionalDataPaths() const { try { std::vector paths; for (const auto& path_string : game_->additional_data_paths()) { - paths.push_back(to_path(path_string)); + paths.push_back(toPath(path_string)); } return paths; @@ -199,7 +199,7 @@ std::vector> Game::GetLoadedPlugins() std::vector Game::SortPlugins( const std::vector& pluginFilenames) { - const auto strs = as_str_refs(pluginFilenames); + const auto strs = asStrRefs(pluginFilenames); try { const auto results = game_->sort_plugins(::rust::Slice(strs)); @@ -228,7 +228,7 @@ bool Game::IsLoadOrderAmbiguous() const { std::filesystem::path Game::GetActivePluginsFilePath() const { try { - return to_path(game_->active_plugins_file_path()); + return toPath(game_->active_plugins_file_path()); } catch (const ::rust::Error& e) { std::rethrow_exception(mapError(e)); } @@ -243,7 +243,7 @@ std::vector Game::GetLoadOrder() const { } void Game::SetLoadOrder(const std::vector& loadOrder) { - const auto strs = as_str_refs(loadOrder); + const auto strs = asStrRefs(loadOrder); try { game_->set_load_order(::rust::Slice(strs)); diff --git a/cpp/src/api/game.h b/cpp/src/api/game.h index 7422282b..49450367 100644 --- a/cpp/src/api/game.h +++ b/cpp/src/api/game.h @@ -17,9 +17,6 @@ public: const std::filesystem::path& gamePath, const std::filesystem::path& gameLocalDataPath = ""); - // Game Interface Methods // - //////////////////////////// - GameType GetType() const override; std::vector GetAdditionalDataPaths() const override; diff --git a/cpp/src/api/metadata/plugin_metadata.cpp b/cpp/src/api/metadata/plugin_metadata.cpp index 9604e951..44980dbc 100644 --- a/cpp/src/api/metadata/plugin_metadata.cpp +++ b/cpp/src/api/metadata/plugin_metadata.cpp @@ -51,7 +51,7 @@ std::vector mergeVectors(std::vector first, return first; } -std::string TrimDotGhostExtension(std::string&& filename) { +std::string trimDotGhostExtension(std::string&& filename) { using std::string_view_literals::operator""sv; // If the name passed ends in '.ghost', that should be trimmed. constexpr std::string_view GHOST_FILE_EXTENSION = ".ghost"sv; @@ -81,7 +81,7 @@ std::string TrimDotGhostExtension(std::string&& filename) { namespace loot { // If the name passed ends in '.ghost', that should be trimmed. PluginMetadata::PluginMetadata(std::string_view n) : - name_(TrimDotGhostExtension(std::string(n))) {} + name_(trimDotGhostExtension(std::string(n))) {} void PluginMetadata::MergeMetadata(const PluginMetadata& plugin) { if (plugin.HasNameOnly())