From 3744908265590238031ced3f2e339f6d8076ac8b Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 16 May 2025 21:16:05 +0100 Subject: [PATCH] Remove ConditionalMetadata While it makes sense, it doesn't really add any value and there is value in having all the relevant data and methods in a single class --- CMakeLists.txt | 2 - cmake/tests.cmake | 1 - docs/api/reference.rst | 3 - include/loot/metadata/conditional_metadata.h | 68 ------------------ include/loot/metadata/file.h | 10 ++- include/loot/metadata/message.h | 10 ++- include/loot/metadata/tag.h | 10 ++- src/api/metadata/conditional_metadata.cpp | 34 --------- src/api/metadata/file.cpp | 4 +- src/api/metadata/message.cpp | 9 ++- src/api/metadata/tag.cpp | 6 +- src/api/metadata/yaml/file.h | 6 +- src/api/metadata/yaml/message.h | 4 +- src/api/metadata/yaml/tag.h | 4 +- src/tests/api/interface/main.cpp | 1 - .../metadata/conditional_metadata_test.h | 72 ------------------- 16 files changed, 45 insertions(+), 199 deletions(-) delete mode 100644 include/loot/metadata/conditional_metadata.h delete mode 100644 src/api/metadata/conditional_metadata.cpp delete mode 100644 src/tests/api/interface/metadata/conditional_metadata_test.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 21e7f793..1fbc4ecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,7 +202,6 @@ set(LIBLOOT_SRC_API_CPP_FILES "${CMAKE_SOURCE_DIR}/src/api/exception/cyclic_interaction_error.cpp" "${CMAKE_SOURCE_DIR}/src/api/exception/undefined_group_error.cpp" "${CMAKE_SOURCE_DIR}/src/api/metadata/condition_evaluator.cpp" - "${CMAKE_SOURCE_DIR}/src/api/metadata/conditional_metadata.cpp" "${CMAKE_SOURCE_DIR}/src/api/metadata/file.cpp" "${CMAKE_SOURCE_DIR}/src/api/metadata/filename.cpp" "${CMAKE_SOURCE_DIR}/src/api/metadata/group.cpp" @@ -239,7 +238,6 @@ set(LIBLOOT_INCLUDE_H_FILES "${CMAKE_SOURCE_DIR}/include/loot/enum/message_type.h" "${CMAKE_SOURCE_DIR}/include/loot/game_interface.h" "${CMAKE_SOURCE_DIR}/include/loot/loot_version.h" - "${CMAKE_SOURCE_DIR}/include/loot/metadata/conditional_metadata.h" "${CMAKE_SOURCE_DIR}/include/loot/metadata/file.h" "${CMAKE_SOURCE_DIR}/include/loot/metadata/filename.h" "${CMAKE_SOURCE_DIR}/include/loot/metadata/group.h" diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 245047fd..e05f3c93 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -68,7 +68,6 @@ set(LIBLOOT_SRC_TESTS_INTERFACE_H_FILES "${CMAKE_SOURCE_DIR}/src/tests/api/interface/database_interface_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/interface/game_interface_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/interface/is_compatible_test.h" - "${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/conditional_metadata_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/file_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/group_test.h" "${CMAKE_SOURCE_DIR}/src/tests/api/interface/metadata/location_test.h" diff --git a/docs/api/reference.rst b/docs/api/reference.rst index fbeef358..ff5691fd 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -56,9 +56,6 @@ Interfaces Classes ======= -.. doxygenclass:: loot::ConditionalMetadata - :members: - .. doxygenclass:: loot::Filename :members: diff --git a/include/loot/metadata/conditional_metadata.h b/include/loot/metadata/conditional_metadata.h deleted file mode 100644 index eddb0f1e..00000000 --- a/include/loot/metadata/conditional_metadata.h +++ /dev/null @@ -1,68 +0,0 @@ -/* LOOT - - A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and - Fallout: New Vegas. - - Copyright (C) 2012-2016 WrinklyNinja - - This file is part of LOOT. - - LOOT is free software: you can redistribute - it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - LOOT is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with LOOT. If not, see - . - */ -#ifndef LOOT_METADATA_CONDITIONAL_METADATA -#define LOOT_METADATA_CONDITIONAL_METADATA - -#include -#include - -#include "loot/api_decorator.h" - -namespace loot { -/** - * A base class for metadata that can be conditional based on the result of - * evaluating a condition string. - */ -class ConditionalMetadata { -public: - /** - * Construct a ConditionalMetadata object with an empty condition string. - */ - LOOT_API ConditionalMetadata() = default; - - /** - * Construct a ConditionalMetadata object with a given condition string. - * @param condition - * A condition string, as defined in the LOOT metadata syntax - * documentation. - */ - LOOT_API explicit ConditionalMetadata(std::string_view condition); - - /** - * Check if the condition string is non-empty. - * @return True if the condition string is not empty, false otherwise. - */ - LOOT_API bool IsConditional() const; - - /** - * Get the condition string. - * @return The object's condition string. - */ - LOOT_API std::string GetCondition() const; - -private: - std::string condition_; -}; -} -#endif diff --git a/include/loot/metadata/file.h b/include/loot/metadata/file.h index 2411b053..1ab3fda7 100644 --- a/include/loot/metadata/file.h +++ b/include/loot/metadata/file.h @@ -28,7 +28,6 @@ #include #include "loot/api_decorator.h" -#include "loot/metadata/conditional_metadata.h" #include "loot/metadata/filename.h" #include "loot/metadata/message_content.h" @@ -36,7 +35,7 @@ namespace loot { /** * Represents a file in a game's Data folder, including files in subdirectories. */ -class File : public ConditionalMetadata { +class File { public: /** * Construct a File with blank name, display and condition strings. @@ -87,6 +86,12 @@ public: */ LOOT_API std::vector GetDetail() const; + /** + * Get the condition string. + * @return The file's condition string. + */ + LOOT_API std::string GetCondition() const; + /** * Get the constraint that applies to the file. * @return The file's constraint. @@ -97,6 +102,7 @@ private: Filename name_; std::string display_; std::vector detail_; + std::string condition_; std::string constraint_; }; diff --git a/include/loot/metadata/message.h b/include/loot/metadata/message.h index ac43f029..ca805eb7 100644 --- a/include/loot/metadata/message.h +++ b/include/loot/metadata/message.h @@ -30,14 +30,13 @@ #include "loot/api_decorator.h" #include "loot/enum/message_type.h" -#include "loot/metadata/conditional_metadata.h" #include "loot/metadata/message_content.h" namespace loot { /** * Represents a message with localisable text content. */ -class Message : public ConditionalMetadata { +class Message { public: /** * Construct a Message object of type 'say' with blank content and condition @@ -85,9 +84,16 @@ public: */ LOOT_API std::vector GetContent() const; + /** + * Get the condition string. + * @return The message's condition string. + */ + LOOT_API std::string GetCondition() const; + private: MessageType type_{MessageType::say}; std::vector content_; + std::string condition_; }; /** diff --git a/include/loot/metadata/tag.h b/include/loot/metadata/tag.h index 0bd6477a..a88521bc 100644 --- a/include/loot/metadata/tag.h +++ b/include/loot/metadata/tag.h @@ -28,13 +28,12 @@ #include #include "loot/api_decorator.h" -#include "loot/metadata/conditional_metadata.h" namespace loot { /** * Represents a Bash Tag suggestion for a plugin. */ -class Tag : public ConditionalMetadata { +class Tag { public: /** * Construct a Tag object with an empty tag name suggested for addition, with @@ -68,9 +67,16 @@ public: */ LOOT_API std::string GetName() const; + /** + * Get the condition string. + * @return The tag's condition string. + */ + LOOT_API std::string GetCondition() const; + private: std::string name_; bool addTag_{true}; + std::string condition_; }; /** diff --git a/src/api/metadata/conditional_metadata.cpp b/src/api/metadata/conditional_metadata.cpp deleted file mode 100644 index c660ed80..00000000 --- a/src/api/metadata/conditional_metadata.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* LOOT - - A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and - Fallout: New Vegas. - - Copyright (C) 2012-2016 WrinklyNinja - - This file is part of LOOT. - - LOOT is free software: you can redistribute - it and/or modify it under the terms of the GNU General Public License - as published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - LOOT is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with LOOT. If not, see - . - */ - -#include "loot/metadata/conditional_metadata.h" - -namespace loot { -ConditionalMetadata::ConditionalMetadata(std::string_view condition) : - condition_(condition) {} - -bool ConditionalMetadata::IsConditional() const { return !condition_.empty(); } - -std::string ConditionalMetadata::GetCondition() const { return condition_; } -} diff --git a/src/api/metadata/file.cpp b/src/api/metadata/file.cpp index c199ac3c..c872aff5 100644 --- a/src/api/metadata/file.cpp +++ b/src/api/metadata/file.cpp @@ -30,10 +30,10 @@ File::File(std::string_view name, std::string_view condition, const std::vector& detail, std::string_view constraint) : - ConditionalMetadata(condition), name_(Filename(name)), display_(display), detail_(detail), + condition_(condition), constraint_(constraint) {} Filename File::GetName() const { return name_; } @@ -42,6 +42,8 @@ std::string File::GetDisplayName() const { return display_; } std::vector File::GetDetail() const { return detail_; } +std::string File::GetCondition() const { return condition_; } + std::string File::GetConstraint() const { return constraint_; } bool operator==(const File& lhs, const File& rhs) { diff --git a/src/api/metadata/message.cpp b/src/api/metadata/message.cpp index c3dec404..d1a7ed73 100644 --- a/src/api/metadata/message.cpp +++ b/src/api/metadata/message.cpp @@ -30,14 +30,15 @@ namespace loot { Message::Message(const MessageType type, std::string_view content, std::string_view condition) : - ConditionalMetadata(condition), type_(type), - content_({MessageContent(content)}) {} + content_({MessageContent(content)}), condition_(condition) {} Message::Message(const MessageType type, const std::vector& content, std::string_view condition) : - ConditionalMetadata(condition), type_(type), content_(content) { + type_(type), + content_(content), + condition_(condition) { if (content.size() > 1) { bool englishStringExists = false; for (const auto& mc : content) { @@ -55,6 +56,8 @@ MessageType Message::GetType() const { return type_; } std::vector Message::GetContent() const { return content_; } +std::string Message::GetCondition() const { return condition_; } + bool operator==(const Message& lhs, const Message& rhs) { return lhs.GetType() == rhs.GetType() && lhs.GetCondition() == rhs.GetCondition() && diff --git a/src/api/metadata/tag.cpp b/src/api/metadata/tag.cpp index 80640d0b..359ad39e 100644 --- a/src/api/metadata/tag.cpp +++ b/src/api/metadata/tag.cpp @@ -28,12 +28,16 @@ namespace loot { Tag::Tag(std::string_view tag, const bool isAddition, std::string_view condition) : - ConditionalMetadata(condition), name_(tag), addTag_(isAddition) {} + name_(tag), + addTag_(isAddition), + condition_(condition) {} bool Tag::IsAddition() const { return addTag_; } std::string Tag::GetName() const { return name_; } +std::string Tag::GetCondition() const { return condition_; } + bool operator==(const Tag& lhs, const Tag& rhs) { return lhs.IsAddition() == rhs.IsAddition() && lhs.GetName() == rhs.GetName() && diff --git a/src/api/metadata/yaml/file.h b/src/api/metadata/yaml/file.h index 50bcb014..de050d05 100644 --- a/src/api/metadata/yaml/file.h +++ b/src/api/metadata/yaml/file.h @@ -37,7 +37,7 @@ namespace loot { inline bool emitAsScalar(const File& file) { - return !file.IsConditional() && file.GetDetail().empty() && + return file.GetCondition().empty() && file.GetDetail().empty() && file.GetDisplayName().empty() && file.GetConstraint().empty(); } } @@ -49,7 +49,7 @@ struct convert { Node node; node["name"] = std::string(rhs.GetName()); - if (rhs.IsConditional()) { + if (!rhs.GetCondition().empty()) { node["condition"] = rhs.GetCondition(); } @@ -147,7 +147,7 @@ inline Emitter& operator<<(Emitter& out, const loot::File& rhs) { out << BeginMap << Key << "name" << Value << YAML::SingleQuoted << std::string(rhs.GetName()); - if (rhs.IsConditional()) { + if (!rhs.GetCondition().empty()) { out << Key << "condition" << Value << YAML::SingleQuoted << rhs.GetCondition(); } diff --git a/src/api/metadata/yaml/message.h b/src/api/metadata/yaml/message.h index cb82cae1..eb5a3a3e 100644 --- a/src/api/metadata/yaml/message.h +++ b/src/api/metadata/yaml/message.h @@ -49,7 +49,7 @@ struct convert { else node["type"] = "error"; - if (rhs.IsConditional()) + if (!rhs.GetCondition().empty()) node["condition"] = rhs.GetCondition(); return node; @@ -157,7 +157,7 @@ inline Emitter& operator<<(Emitter& out, const loot::Message& rhs) { else out << Key << "content" << Value << rhs.GetContent(); - if (rhs.IsConditional()) + if (!rhs.GetCondition().empty()) out << Key << "condition" << Value << YAML::SingleQuoted << rhs.GetCondition(); diff --git a/src/api/metadata/yaml/tag.h b/src/api/metadata/yaml/tag.h index 72b3084c..ffbdcc24 100644 --- a/src/api/metadata/yaml/tag.h +++ b/src/api/metadata/yaml/tag.h @@ -34,7 +34,7 @@ #include "loot/metadata/tag.h" namespace loot { -inline bool emitAsScalar(const Tag& tag) { return !tag.IsConditional(); } +inline bool emitAsScalar(const Tag& tag) { return tag.GetCondition().empty(); } } namespace YAML { @@ -42,7 +42,7 @@ template<> struct convert { static Node encode(const loot::Tag& rhs) { Node node; - if (rhs.IsConditional()) + if (!rhs.GetCondition().empty()) node["condition"] = rhs.GetCondition(); if (rhs.IsAddition()) node["name"] = rhs.GetName(); diff --git a/src/tests/api/interface/main.cpp b/src/tests/api/interface/main.cpp index 7f0796cc..700c5af2 100644 --- a/src/tests/api/interface/main.cpp +++ b/src/tests/api/interface/main.cpp @@ -25,7 +25,6 @@ #include #include "loot/api.h" -#include "tests/api/interface/metadata/conditional_metadata_test.h" #include "tests/api/interface/metadata/file_test.h" #include "tests/api/interface/metadata/group_test.h" #include "tests/api/interface/metadata/location_test.h" diff --git a/src/tests/api/interface/metadata/conditional_metadata_test.h b/src/tests/api/interface/metadata/conditional_metadata_test.h deleted file mode 100644 index 6f8b4804..00000000 --- a/src/tests/api/interface/metadata/conditional_metadata_test.h +++ /dev/null @@ -1,72 +0,0 @@ -/* LOOT - -A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and -Fallout: New Vegas. - -Copyright (C) 2014-2016 WrinklyNinja - -This file is part of LOOT. - -LOOT is free software: you can redistribute -it and/or modify it under the terms of the GNU General Public License -as published by the Free Software Foundation, either version 3 of -the License, or (at your option) any later version. - -LOOT is distributed in the hope that it will -be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with LOOT. If not, see -. -*/ - -#ifndef LOOT_TESTS_API_INTERFACE_METADATA_CONDITIONAL_METADATA_TEST -#define LOOT_TESTS_API_INTERFACE_METADATA_CONDITIONAL_METADATA_TEST - -#include "loot/metadata/conditional_metadata.h" -#include "tests/common_game_test_fixture.h" - -namespace loot { -namespace test { -class ConditionalMetadataTest : public CommonGameTestFixture, - public testing::WithParamInterface { -protected: - ConditionalMetadataTest() : CommonGameTestFixture(GetParam()) {} - ConditionalMetadata conditionalMetadata_; -}; - -// Pass an empty first argument, as it's a prefix for the test instantation, -// but we only have the one so no prefix is necessary. -INSTANTIATE_TEST_SUITE_P(, - ConditionalMetadataTest, - ::testing::ValuesIn(ALL_GAME_TYPES)); - -TEST_P(ConditionalMetadataTest, - defaultConstructorShouldSetEmptyConditionString) { - EXPECT_TRUE(conditionalMetadata_.GetCondition().empty()); -} - -TEST_P(ConditionalMetadataTest, - stringConstructorShouldSetConditionToGivenString) { - std::string condition("condition"); - conditionalMetadata_ = ConditionalMetadata(condition); - - EXPECT_EQ(condition, conditionalMetadata_.GetCondition()); -} - -TEST_P(ConditionalMetadataTest, - isConditionalShouldBeFalseForAnEmptyConditionString) { - EXPECT_FALSE(conditionalMetadata_.IsConditional()); -} - -TEST_P(ConditionalMetadataTest, - isConditionalShouldBeTrueForANonEmptyConditionString) { - conditionalMetadata_ = ConditionalMetadata("condition"); - EXPECT_TRUE(conditionalMetadata_.IsConditional()); -} -} -} - -#endif