Make MessageContent::Choose() return an optional

And propagate this through the File, Message and PluginCleaningData APIs
that call it.
This commit is contained in:
Oliver Hamlet
2021-05-22 22:15:32 +01:00
parent caee647d86
commit 4faab46069
13 changed files with 76 additions and 59 deletions
+2 -1
View File
@@ -105,7 +105,8 @@ public:
* @return The MessageContent object for the preferred language, or if one
* does not exist, the English-language MessageContent object.
*/
LOOT_API MessageContent ChooseDetail(const std::string& language) const;
LOOT_API std::optional<MessageContent> ChooseDetail(
const std::string& language) const;
private:
Filename name_;
+5 -5
View File
@@ -109,7 +109,7 @@ public:
* @return A MessageContent object for the preferred language, or for English
* if a MessageContent object is not available for the given language.
*/
LOOT_API MessageContent GetContent(const std::string& language) const;
LOOT_API std::optional<MessageContent> GetContent(const std::string& language) const;
/**
* Get the message as a SimpleMessage given a language.
@@ -118,7 +118,7 @@ public:
* @return A SimpleMessage object for the preferred language, or for English
* if message text is not available for the given language.
*/
LOOT_API SimpleMessage ToSimpleMessage(const std::string& language) const;
LOOT_API std::optional<SimpleMessage> ToSimpleMessage(const std::string& language) const;
private:
MessageType type_;
@@ -133,7 +133,7 @@ LOOT_API bool operator!=(const Message& lhs, const Message& rhs);
/**
* Check if the first Message object is greater than the second Message object.
* @returns True if the second Message object is less than the first Message
* @returns True if the second Message object is less than the first Message
* object, false otherwise.
*/
LOOT_API bool operator>(const Message& lhs, const Message& rhs);
@@ -141,13 +141,13 @@ LOOT_API bool operator>(const Message& lhs, const Message& rhs);
/**
* Check if the first Message object is less than or equal to the second
* Message object.
* @returns True if the first Message object is not greater than the second
* @returns True if the first Message object is not greater than the second
* Message object, false otherwise.
*/
LOOT_API bool operator<=(const Message& lhs, const Message& rhs);
/**
* Check if the first Message object is greater than or equal to the second
* Check if the first Message object is greater than or equal to the second
* Message object.
* @returns True if the first Message object is not less than the second
* Message object, false otherwise.
+3 -2
View File
@@ -26,6 +26,7 @@
#include <string>
#include <vector>
#include <optional>
#include "loot/api_decorator.h"
@@ -108,9 +109,9 @@ public:
* If no locale or language code matches are found and content in the
* default language is present, that content is returned.
*
* Otherwise, a default-constructed MessageContent is returned.
* Otherwise, an empty optional is returned.
*/
LOOT_API static MessageContent Choose(
LOOT_API static std::optional<MessageContent> Choose(
const std::vector<MessageContent> content,
const std::string& language);
+1 -1
View File
@@ -144,7 +144,7 @@ public:
* @return The MessageContent object for the preferred language, or if one
* does not exist, the English-language MessageContent object.
*/
LOOT_API MessageContent ChooseDetail(const std::string& language) const;
LOOT_API std::optional<MessageContent> ChooseDetail(const std::string& language) const;
private:
uint32_t crc_;