mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
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.
This commit is contained in:
@@ -70,7 +70,6 @@ set(LIBLOOT_SRC_API_CPP_FILES
|
||||
"${CMAKE_SOURCE_DIR}/src/api/exception/cyclic_interaction_error.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/exception/exception.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/exception/undefined_group_error.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"
|
||||
@@ -97,7 +96,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"
|
||||
|
||||
@@ -47,7 +47,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"
|
||||
|
||||
@@ -56,9 +56,6 @@ Interfaces
|
||||
Classes
|
||||
=======
|
||||
|
||||
.. doxygenclass:: loot::ConditionalMetadata
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::Filename
|
||||
:members:
|
||||
|
||||
|
||||
@@ -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
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef LOOT_METADATA_CONDITIONAL_METADATA
|
||||
#define LOOT_METADATA_CONDITIONAL_METADATA
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#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
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <string_view>
|
||||
|
||||
#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<MessageContent> 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<MessageContent> detail_;
|
||||
std::string condition_;
|
||||
std::string constraint_;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<MessageContent> 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<MessageContent> content_;
|
||||
std::string condition_;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,13 +28,12 @@
|
||||
#include <string_view>
|
||||
|
||||
#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_;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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_; }
|
||||
}
|
||||
@@ -30,10 +30,10 @@ File::File(std::string_view name,
|
||||
std::string_view condition,
|
||||
const std::vector<MessageContent>& 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<MessageContent> 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) {
|
||||
|
||||
@@ -30,14 +30,12 @@ namespace loot {
|
||||
Message::Message(const MessageType type,
|
||||
std::string_view content,
|
||||
std::string_view condition) :
|
||||
ConditionalMetadata(condition),
|
||||
type_(type),
|
||||
content_({MessageContent(content)}) {}
|
||||
type_(type), content_({MessageContent(content)}), condition_(condition) {}
|
||||
|
||||
Message::Message(const MessageType type,
|
||||
const std::vector<MessageContent>& 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 +53,8 @@ MessageType Message::GetType() const { return type_; }
|
||||
|
||||
std::vector<MessageContent> 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() &&
|
||||
|
||||
@@ -28,12 +28,14 @@ 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() &&
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#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"
|
||||
|
||||
@@ -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
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<GameType> {
|
||||
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
|
||||
Reference in New Issue
Block a user