Replace const std::string& with std::string_view in the public API

This means clients don't need to construct a std::string if they don't already have one.
This commit is contained in:
Oliver Hamlet
2025-04-04 19:11:07 +01:00
parent 8c3aea946e
commit fac057490d
34 changed files with 90 additions and 76 deletions
+6 -5
View File
@@ -27,6 +27,7 @@
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "loot/exception/cyclic_interaction_error.h"
@@ -175,8 +176,8 @@ public:
* exists.
*/
virtual std::vector<Vertex> GetGroupsPath(
const std::string& fromGroupName,
const std::string& toGroupName) const = 0;
std::string_view fromGroupName,
std::string_view toGroupName) const = 0;
/**
* @}
@@ -200,7 +201,7 @@ public:
* otherwise an optional containing no value.
*/
virtual std::optional<PluginMetadata> GetPluginMetadata(
const std::string& plugin,
std::string_view plugin,
bool includeUserMetadata = true,
bool evaluateConditions = false) const = 0;
@@ -216,7 +217,7 @@ public:
* that metadata, otherwise an optional containing no value.
*/
virtual std::optional<PluginMetadata> GetPluginUserMetadata(
const std::string& plugin,
std::string_view plugin,
bool evaluateConditions = false) const = 0;
/**
@@ -235,7 +236,7 @@ public:
* The filename of the plugin for which all user-added metadata
* should be deleted.
*/
virtual void DiscardPluginUserMetadata(const std::string& plugin) = 0;
virtual void DiscardPluginUserMetadata(std::string_view plugin) = 0;
/**
* @brief Discards all loaded user metadata for all plugins, and any
@@ -26,6 +26,7 @@
#define LOOT_EXCEPTION_UNDEFINED_GROUP_ERROR
#include <stdexcept>
#include <string_view>
#include "loot/api_decorator.h"
@@ -39,7 +40,7 @@ public:
* @brief Construct an exception for an undefined group.
* @param groupName The name of the group that is undefined.
*/
LOOT_API UndefinedGroupError(const std::string& groupName);
LOOT_API UndefinedGroupError(std::string_view groupName);
/**
* Get the name of the undefined group.
+1 -1
View File
@@ -142,7 +142,7 @@ public:
* a case-insensitively equal filename is loaded.
*/
virtual std::shared_ptr<const PluginInterface> GetPlugin(
const std::string& pluginName) const = 0;
std::string_view pluginName) const = 0;
/**
* @brief Get a set of const references to all loaded plugins' PluginInterface
+2 -1
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_CONDITIONAL_METADATA
#include <string>
#include <string_view>
#include "loot/api_decorator.h"
@@ -48,7 +49,7 @@ public:
* documentation.
* @return A ConditionalMetadata object.
*/
LOOT_API explicit ConditionalMetadata(const std::string& condition);
LOOT_API explicit ConditionalMetadata(std::string_view condition);
/**
* Check if the condition string is non-empty.
+4 -3
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_FILE
#include <string>
#include <string_view>
#include "loot/api_decorator.h"
#include "loot/metadata/conditional_metadata.h"
@@ -58,9 +59,9 @@ public:
* English.
* @return A File object.
*/
LOOT_API explicit File(const std::string& name,
const std::string& display = "",
const std::string& condition = "",
LOOT_API explicit File(std::string_view name,
std::string_view display = "",
std::string_view condition = "",
const std::vector<MessageContent>& detail = {});
/**
+2 -1
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_FILENAME
#include <string>
#include <string_view>
#include "loot/api_decorator.h"
@@ -44,7 +45,7 @@ public:
* Construct a Filename using the given string.
* @return A Filename object.
*/
LOOT_API explicit Filename(const std::string& filename);
LOOT_API explicit Filename(std::string_view filename);
/**
* Get this Filename as a string.
+3 -2
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_GROUP
#include <string>
#include <string_view>
#include <vector>
#include "loot/api_decorator.h"
@@ -58,9 +59,9 @@ public:
* A description of the group.
* @return A Group object.
*/
LOOT_API explicit Group(const std::string& name,
LOOT_API explicit Group(std::string_view name,
const std::vector<std::string>& afterGroups = {},
const std::string& description = "");
std::string_view description = "");
/**
* Get the name of the group.
+3 -2
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_LOCATION
#include <string>
#include <string_view>
#include <vector>
#include "loot/api_decorator.h"
@@ -49,8 +50,8 @@ public:
* A name for the URL, eg. the page or site name.
* @return A Location object.
*/
LOOT_API explicit Location(const std::string& url,
const std::string& name = "");
LOOT_API explicit Location(std::string_view url,
std::string_view name = "");
/**
* Get the object's URL.
+4 -3
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_MESSAGE
#include <string>
#include <string_view>
#include <vector>
#include "loot/api_decorator.h"
@@ -57,8 +58,8 @@ public:
* @return A Message object.
*/
LOOT_API explicit Message(const MessageType type,
const std::string& content,
const std::string& condition = "");
std::string_view content,
std::string_view condition = "");
/**
* Construct a Message object with the given type, content and condition
@@ -73,7 +74,7 @@ public:
*/
LOOT_API explicit Message(const MessageType type,
const std::vector<MessageContent>& content,
const std::string& condition = "");
std::string_view condition = "");
/**
* Get the message type.
+4 -3
View File
@@ -26,6 +26,7 @@
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "loot/api_decorator.h"
@@ -57,8 +58,8 @@ public:
* @return A MessageContent object.
*/
LOOT_API explicit MessageContent(
const std::string& text,
const std::string& language = DEFAULT_LANGUAGE);
std::string_view text,
std::string_view language = DEFAULT_LANGUAGE);
/**
* Get the message text.
@@ -144,7 +145,7 @@ LOOT_API bool operator>=(const MessageContent& lhs, const MessageContent& rhs);
*/
LOOT_API std::optional<MessageContent> SelectMessageContent(
const std::vector<MessageContent> content,
const std::string& language);
std::string_view language);
}
#endif
+3 -2
View File
@@ -27,6 +27,7 @@
#include <cstdint>
#include <string>
#include <string_view>
#include "loot/api_decorator.h"
#include "loot/metadata/message.h"
@@ -57,7 +58,7 @@ public:
* @return A PluginCleaningData object.
*/
LOOT_API explicit PluginCleaningData(uint32_t crc,
const std::string& utility);
std::string_view utility);
/**
* Construct a PluginCleaningData object with the given values.
@@ -78,7 +79,7 @@ public:
*/
LOOT_API explicit PluginCleaningData(
uint32_t crc,
const std::string& utility,
std::string_view utility,
const std::vector<MessageContent>& detail,
unsigned int itm,
unsigned int ref,
+4 -3
View File
@@ -30,6 +30,7 @@
#include <regex>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "loot/api_decorator.h"
@@ -58,7 +59,7 @@ public:
* The filename of the plugin that the object is constructed for.
* @return A PluginMetadata object.
*/
LOOT_API explicit PluginMetadata(const std::string& name);
LOOT_API explicit PluginMetadata(std::string_view name);
/**
* Merge metadata from the given PluginMetadata object into this object.
@@ -138,7 +139,7 @@ public:
* @param group
* The name of the group this plugin belongs to.
*/
LOOT_API void SetGroup(const std::string& group);
LOOT_API void SetGroup(std::string_view group);
/**
* Unsets the plugin's group.
@@ -227,7 +228,7 @@ public:
* @returns True if the given plugin name matches this metadata's plugin
* name, false otherwise.
*/
LOOT_API bool NameMatches(const std::string& pluginName) const;
LOOT_API bool NameMatches(std::string_view pluginName) const;
/**
* @brief Serialises the plugin metadata as YAML.
+3 -2
View File
@@ -25,6 +25,7 @@
#define LOOT_METADATA_TAG
#include <string>
#include <string_view>
#include "loot/api_decorator.h"
#include "loot/metadata/conditional_metadata.h"
@@ -53,9 +54,9 @@ public:
* A condition string.
* @return A Tag object.
*/
LOOT_API explicit Tag(const std::string& tag,
LOOT_API explicit Tag(std::string_view tag,
const bool isAddition = true,
const std::string& condition = "");
std::string_view condition = "");
/**
* Check if the tag should be added.
+1
View File
@@ -28,6 +28,7 @@
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "loot/metadata/message.h"
+3 -2
View File
@@ -27,6 +27,7 @@ along with LOOT. If not, see
#include <optional>
#include <string>
#include <string_view>
#include "loot/api_decorator.h"
#include "loot/enum/edge_type.h"
@@ -42,14 +43,14 @@ public:
* @brief Construct a Vertex with the given name and no out edge.
* @param name The name of the plugin or group that this vertex represents.
*/
LOOT_API explicit Vertex(std::string name);
LOOT_API explicit Vertex(std::string_view name);
/**
* @brief Construct a Vertex with the given name and out edge type.
* @param name The name of the plugin or group that this vertex represents.
* @param outEdgeType The type of the edge going out from this vertex.
*/
LOOT_API explicit Vertex(std::string name, EdgeType outEdgeType);
LOOT_API explicit Vertex(std::string_view name, EdgeType outEdgeType);
/**
* @brief Get the name of the plugin or group.
+5 -5
View File
@@ -203,8 +203,8 @@ void ApiDatabase::SetUserGroups(const std::vector<Group>& groups) {
}
std::vector<Vertex> ApiDatabase::GetGroupsPath(
const std::string& fromGroupName,
const std::string& toGroupName) const {
std::string_view fromGroupName,
std::string_view toGroupName) const {
auto masterlistGroups = GetGroups(false);
auto userGroups = GetUserGroups();
@@ -214,7 +214,7 @@ std::vector<Vertex> ApiDatabase::GetGroupsPath(
}
std::optional<PluginMetadata> ApiDatabase::GetPluginMetadata(
const std::string& plugin,
std::string_view plugin,
bool includeUserMetadata,
bool evaluateConditions) const {
auto metadata = masterlist_.FindPlugin(plugin);
@@ -237,7 +237,7 @@ std::optional<PluginMetadata> ApiDatabase::GetPluginMetadata(
}
std::optional<PluginMetadata> ApiDatabase::GetPluginUserMetadata(
const std::string& plugin,
std::string_view plugin,
bool evaluateConditions) const {
auto metadata = userlist_.FindPlugin(plugin);
@@ -253,7 +253,7 @@ void ApiDatabase::SetPluginUserMetadata(const PluginMetadata& pluginMetadata) {
userlist_.AddPlugin(pluginMetadata);
}
void ApiDatabase::DiscardPluginUserMetadata(const std::string& plugin) {
void ApiDatabase::DiscardPluginUserMetadata(std::string_view plugin) {
userlist_.ErasePlugin(plugin);
}
+5 -5
View File
@@ -64,21 +64,21 @@ struct ApiDatabase final : public DatabaseInterface {
std::vector<Group> GetUserGroups() const override;
void SetUserGroups(const std::vector<Group>& groups) override;
std::vector<Vertex> GetGroupsPath(
const std::string& fromGroupName,
const std::string& toGroupName) const override;
std::string_view fromGroupName,
std::string_view toGroupName) const override;
std::optional<PluginMetadata> GetPluginMetadata(
const std::string& plugin,
std::string_view plugin,
bool includeUserMetadata = true,
bool evaluateConditions = false) const override;
std::optional<PluginMetadata> GetPluginUserMetadata(
const std::string& plugin,
std::string_view plugin,
bool evaluateConditions = false) const override;
void SetPluginUserMetadata(const PluginMetadata& pluginMetadata) override;
void DiscardPluginUserMetadata(const std::string& plugin) override;
void DiscardPluginUserMetadata(std::string_view plugin) override;
void DiscardAllUserMetadata() override;
+2 -2
View File
@@ -312,7 +312,7 @@ void Game::LoadPlugins(const std::vector<std::filesystem::path>& pluginPaths,
void Game::ClearLoadedPlugins() { cache_.ClearCachedPlugins(); }
std::shared_ptr<const PluginInterface> Game::GetPlugin(
const std::string& pluginName) const {
std::string_view pluginName) const {
return cache_.GetPlugin(pluginName);
}
@@ -380,7 +380,7 @@ std::filesystem::path Game::GetActivePluginsFilePath() const {
}
bool Game::IsPluginActive(const std::string& pluginName) const {
return loadOrderHandler_.IsPluginActive(pluginName);
return loadOrderHandler_.IsPluginActive(std::string(pluginName));
}
std::vector<std::string> Game::GetLoadOrder() const {
+1 -1
View File
@@ -73,7 +73,7 @@ public:
void ClearLoadedPlugins() override;
std::shared_ptr<const PluginInterface> GetPlugin(
const std::string& pluginName) const override;
std::string_view pluginName) const override;
std::vector<std::shared_ptr<const PluginInterface>> GetLoadedPlugins()
const override;
+2 -2
View File
@@ -203,7 +203,7 @@ std::filesystem::path LoadOrderHandler::GetActivePluginsFilePath() const {
HandleError("get active plugins file path", ret);
const auto filePath = std::filesystem::u8path(std::string(filePathCString));
const auto filePath = std::filesystem::u8path(std::string_view(filePathCString));
lo_free_string(filePathCString);
@@ -227,7 +227,7 @@ std::vector<std::filesystem::path> LoadOrderHandler::GetAdditionalDataPaths()
std::vector<std::filesystem::path> loadOrder;
for (size_t i = 0; i < pathArrSize; i += 1) {
loadOrder.push_back(std::filesystem::u8path(std::string(pathArr[i])));
loadOrder.push_back(std::filesystem::u8path(std::string_view(pathArr[i])));
}
lo_free_string_array(pathArr, pathArrSize);

Some files were not shown because too many files have changed in this diff Show More