From 2408a7b3baf9b92e5cbea2b840eb4c6104b12ba2 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 12 Sep 2023 19:53:44 +0100 Subject: [PATCH] Remove SimpleMessage It's no longer used by LOOT. --- CMakeLists.txt | 1 - docs/api/changelog.rst | 7 +++ docs/api/reference.rst | 10 ---- include/loot/database_interface.h | 1 - include/loot/metadata/message.h | 37 -------------- include/loot/struct/simple_message.h | 50 ------------------- src/api/metadata/message.cpp | 37 -------------- .../api/internals/metadata/message_test.h | 33 ------------ 8 files changed, 7 insertions(+), 169 deletions(-) delete mode 100644 include/loot/struct/simple_message.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 04c53271..534ba8d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,7 +238,6 @@ set(LIBLOOT_INCLUDE_H_FILES "${CMAKE_SOURCE_DIR}/include/loot/metadata/plugin_metadata.h" "${CMAKE_SOURCE_DIR}/include/loot/metadata/tag.h" "${CMAKE_SOURCE_DIR}/include/loot/plugin_interface.h" - "${CMAKE_SOURCE_DIR}/include/loot/struct/simple_message.h" "${CMAKE_SOURCE_DIR}/include/loot/vertex.h") set(LIBLOOT_SRC_API_H_FILES diff --git a/docs/api/changelog.rst b/docs/api/changelog.rst index 875b3bee..db714902 100644 --- a/docs/api/changelog.rst +++ b/docs/api/changelog.rst @@ -41,6 +41,13 @@ Fixed wrong parameter name. - Cross-compiling from Linux to Windows using MinGW-w64. +Removed +------- + +- The ``loot::SimpleMessage`` struct. +- The ``loot::ToSimpleMessage()`` function. +- The ``loot::ToSimpleMessages()`` function. + 0.19.4 - 2023-05-06 =================== diff --git a/docs/api/reference.rst b/docs/api/reference.rst index 2a58589e..81fec085 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -24,12 +24,6 @@ Enumerations .. doxygenenum:: loot::MessageType -Public-Field Data Structures -============================ - -.. doxygenstruct:: loot::SimpleMessage - :members: - Functions ========= @@ -45,10 +39,6 @@ Functions .. doxygenfunction:: loot::SelectMessageContent -.. doxygenfunction:: loot::ToSimpleMessage - -.. doxygenfunction:: loot::ToSimpleMessages - Interfaces ========== diff --git a/include/loot/database_interface.h b/include/loot/database_interface.h index 2cbc7f27..229abfde 100644 --- a/include/loot/database_interface.h +++ b/include/loot/database_interface.h @@ -33,7 +33,6 @@ #include "loot/metadata/group.h" #include "loot/metadata/message.h" #include "loot/metadata/plugin_metadata.h" -#include "loot/struct/simple_message.h" namespace loot { /** @brief The interface provided by API's database handle. */ diff --git a/include/loot/metadata/message.h b/include/loot/metadata/message.h index 645fd72f..735d59b1 100644 --- a/include/loot/metadata/message.h +++ b/include/loot/metadata/message.h @@ -31,7 +31,6 @@ #include "loot/enum/message_type.h" #include "loot/metadata/conditional_metadata.h" #include "loot/metadata/message_content.h" -#include "loot/struct/simple_message.h" namespace loot { /** @@ -76,14 +75,6 @@ public: const std::vector& content, const std::string& condition = ""); - /** - * Construct a Message object from a SimpleMessage object. - * @param message - * The SimpleMessage object. - * @return A Message object. - */ - LOOT_API explicit Message(const SimpleMessage& message); - /** * Get the message type. * @return The message type. @@ -143,34 +134,6 @@ LOOT_API bool operator<=(const Message& lhs, const Message& rhs); * Message object, false otherwise. */ LOOT_API bool operator>=(const Message& lhs, const Message& rhs); - -/** - * Get a given Message as a SimpleMessage given a language. - * @param message - * The message to convert. - * @param language - * The preferred language for the message content. - * @return A SimpleMessage object for the preferred language, or for English - * if message text is not available for the given language. - */ -LOOT_API std::optional ToSimpleMessage( - const Message& message, - const std::string& language); - -/** - * Get the given messages as simple messages given a language. - * @param messages - * The messages to convert. - * @param language - * The preferred language for the message content. - * @return A vector of SimpleMessage objects for the preferred language, or for - * English if message text is not available for the given language. The - * order of the input Message objects is preserved, though any messages - * without the preferred language or English content will be omitted. - */ -LOOT_API std::vector ToSimpleMessages( - const std::vector& messages, - const std::string& language); } #endif diff --git a/include/loot/struct/simple_message.h b/include/loot/struct/simple_message.h deleted file mode 100644 index aac3e5ba..00000000 --- a/include/loot/struct/simple_message.h +++ /dev/null @@ -1,50 +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_SIMPLE_MESSAGE -#define LOOT_SIMPLE_MESSAGE - -#include - -#include "loot/enum/message_type.h" - -namespace loot { -/** - * A structure that holds the type of a message and the message string itself. - */ -struct SimpleMessage { - /** The type of the message. */ - MessageType type{MessageType::say}; - - /** The language the message string is written in. */ - std::string language; - - /** The message string, which may be formatted using CommonMark. */ - std::string text; - - /** The message's condition string. */ - std::string condition; -}; -} - -#endif diff --git a/src/api/metadata/message.cpp b/src/api/metadata/message.cpp index fca27e5d..f43abfd3 100644 --- a/src/api/metadata/message.cpp +++ b/src/api/metadata/message.cpp @@ -53,11 +53,6 @@ Message::Message(const MessageType type, } } -Message::Message(const SimpleMessage& message) : - ConditionalMetadata(message.condition), - type_(message.type), - content_({MessageContent(message.text, message.language)}) {} - MessageType Message::GetType() const { return type_; } std::vector Message::GetContent() const { return content_; } @@ -97,36 +92,4 @@ bool operator>(const Message& lhs, const Message& rhs) { return rhs < lhs; } bool operator<=(const Message& lhs, const Message& rhs) { return !(lhs > rhs); } bool operator>=(const Message& lhs, const Message& rhs) { return !(lhs < rhs); } - -std::optional ToSimpleMessage(const Message& message, - const std::string& language) { - auto content = SelectMessageContent(message.GetContent(), language); - if (!content.has_value()) { - return std::nullopt; - } - - SimpleMessage simpleMessage; - - simpleMessage.type = message.GetType(); - simpleMessage.language = content.value().GetLanguage(); - simpleMessage.text = content.value().GetText(); - simpleMessage.condition = message.GetCondition(); - - return simpleMessage; -} - -std::vector ToSimpleMessages( - const std::vector& messages, - const std::string& language) { - std::vector simpleMessages; - - for (const auto& message : messages) { - auto simpleMessage = ToSimpleMessage(message, language); - if (simpleMessage.has_value()) { - simpleMessages.push_back(simpleMessage.value()); - } - } - - return simpleMessages; -} } diff --git a/src/tests/api/internals/metadata/message_test.h b/src/tests/api/internals/metadata/message_test.h index b531264e..4f1c2d12 100644 --- a/src/tests/api/internals/metadata/message_test.h +++ b/src/tests/api/internals/metadata/message_test.h @@ -81,22 +81,6 @@ TEST_P( std::invalid_argument); } -TEST_P(MessageTest, - simpleMessageConstructorShouldCreateAMessageWithASingleContentString) { - SimpleMessage simple; - simple.type = MessageType::error; - simple.text = "ERROR"; - simple.language = "fr"; - simple.condition = "condition"; - - Message message(simple); - - EXPECT_EQ(MessageType::error, message.GetType()); - EXPECT_EQ(MessageContents({MessageContent(simple.text, simple.language)}), - message.GetContent()); - EXPECT_EQ("condition", message.GetCondition()); -} - TEST_P(MessageTest, equalityShouldRequireEqualMessageTypes) { Message message1(MessageType::say, "content"); Message message2(MessageType::say, "content"); @@ -363,23 +347,6 @@ TEST_P( EXPECT_TRUE(message2 >= message1); } -TEST(ToSimpleMessage, shouldSelectTextAndLanguageUsingGetContent) { - Message message(MessageType::warn, - std::vector({ - MessageContent("content1", "de"), - MessageContent("content2"), - MessageContent("content3", "fr"), - }), - "condition1"); - - SimpleMessage simpleMessage = ToSimpleMessage(message, "fr").value(); - - EXPECT_EQ(MessageType::warn, simpleMessage.type); - EXPECT_EQ("content3", simpleMessage.text); - EXPECT_EQ("fr", simpleMessage.language); - EXPECT_EQ("condition1", simpleMessage.condition); -} - TEST_P(MessageTest, emittingAsYamlShouldOutputNoteMessageTypeCorrectly) { Message message(MessageType::say, "content1"); YAML::Emitter emitter;