mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Share std::shared_ptr<PluginInterface> instead of PluginInterface*
This commit is contained in:
@@ -141,7 +141,7 @@ public:
|
||||
* is called, this GameInterface is destroyed, or until a plugin with
|
||||
* a case-insensitively equal filename is loaded.
|
||||
*/
|
||||
virtual const PluginInterface* GetPlugin(
|
||||
virtual std::shared_ptr<const PluginInterface> GetPlugin(
|
||||
const std::string& pluginName) const = 0;
|
||||
|
||||
/**
|
||||
@@ -152,7 +152,8 @@ public:
|
||||
* this GameInterface is destroyed, or until a plugin with a
|
||||
* case-insensitively equal filename is loaded.
|
||||
*/
|
||||
virtual std::vector<const PluginInterface*> GetLoadedPlugins() const = 0;
|
||||
virtual std::vector<std::shared_ptr<const PluginInterface>> GetLoadedPlugins()
|
||||
const = 0;
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -311,12 +311,14 @@ void Game::LoadPlugins(const std::vector<std::filesystem::path>& pluginPaths,
|
||||
|
||||
void Game::ClearLoadedPlugins() { cache_.ClearCachedPlugins(); }
|
||||
|
||||
const PluginInterface* Game::GetPlugin(const std::string& pluginName) const {
|
||||
std::shared_ptr<const PluginInterface> Game::GetPlugin(
|
||||
const std::string& pluginName) const {
|
||||
return cache_.GetPlugin(pluginName);
|
||||
}
|
||||
|
||||
std::vector<const PluginInterface*> Game::GetLoadedPlugins() const {
|
||||
std::vector<const PluginInterface*> interfacePointers;
|
||||
std::vector<std::shared_ptr<const PluginInterface>> Game::GetLoadedPlugins()
|
||||
const {
|
||||
std::vector<std::shared_ptr<const PluginInterface>> interfacePointers;
|
||||
for (const auto plugin : cache_.GetPlugins()) {
|
||||
interfacePointers.push_back(plugin);
|
||||
}
|
||||
@@ -334,7 +336,7 @@ std::vector<std::string> Game::SortPlugins(
|
||||
"\" has not been loaded.");
|
||||
}
|
||||
|
||||
plugins.push_back(plugin);
|
||||
plugins.push_back(plugin.get());
|
||||
}
|
||||
|
||||
auto pluginsSortingData = GetPluginsSortingData(database_, plugins);
|
||||
|
||||
+3
-2
@@ -72,10 +72,11 @@ public:
|
||||
|
||||
void ClearLoadedPlugins() override;
|
||||
|
||||
const PluginInterface* GetPlugin(
|
||||
std::shared_ptr<const PluginInterface> GetPlugin(
|
||||
const std::string& pluginName) const override;
|
||||
|
||||
std::vector<const PluginInterface*> GetLoadedPlugins() const override;
|
||||
std::vector<std::shared_ptr<const PluginInterface>> GetLoadedPlugins()
|
||||
const override;
|
||||
|
||||
std::vector<std::string> SortPlugins(
|
||||
const std::vector<std::string>& pluginFilenames) override;
|
||||
|
||||
@@ -27,19 +27,20 @@
|
||||
#include "api/helpers/text.h"
|
||||
|
||||
namespace loot {
|
||||
std::vector<const Plugin*> GameCache::GetPlugins() const {
|
||||
std::vector<const Plugin*> output(plugins_.size());
|
||||
std::vector<std::shared_ptr<const Plugin>> GameCache::GetPlugins() const {
|
||||
std::vector<std::shared_ptr<const Plugin>> output(plugins_.size());
|
||||
std::transform(
|
||||
begin(plugins_), end(plugins_), begin(output), [](const auto& pair) {
|
||||
return pair.second.get();
|
||||
return pair.second;
|
||||
});
|
||||
return output;
|
||||
}
|
||||
|
||||
const Plugin* GameCache::GetPlugin(std::string_view pluginName) const {
|
||||
std::shared_ptr<const Plugin> GameCache::GetPlugin(
|
||||
std::string_view pluginName) const {
|
||||
const auto it = plugins_.find(NormalizeFilename(pluginName));
|
||||
if (it != end(plugins_))
|
||||
return it->second.get();
|
||||
return it->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
namespace loot {
|
||||
class GameCache {
|
||||
public:
|
||||
std::vector<const Plugin*> GetPlugins() const;
|
||||
const Plugin* GetPlugin(std::string_view pluginName) const;
|
||||
std::vector<std::shared_ptr<const Plugin>> GetPlugins() const;
|
||||
std::shared_ptr<const Plugin> GetPlugin(std::string_view pluginName) const;
|
||||
void AddPlugin(Plugin&& plugin);
|
||||
|
||||
std::vector<const Plugin*> GetPluginsWithReplacements(
|
||||
|
||||
@@ -203,7 +203,7 @@ void ConditionEvaluator::RefreshActivePluginsState(
|
||||
}
|
||||
|
||||
void ConditionEvaluator::RefreshLoadedPluginsState(
|
||||
const std::vector<const PluginInterface*>& plugins) {
|
||||
const std::vector<std::shared_ptr<const PluginInterface>>& plugins) {
|
||||
ClearConditionCache();
|
||||
|
||||
std::vector<std::string> pluginNames;
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
void RefreshActivePluginsState(
|
||||
const std::vector<std::string>& activePluginNames);
|
||||
void RefreshLoadedPluginsState(
|
||||
const std::vector<const PluginInterface*>& plugins);
|
||||
const std::vector<std::shared_ptr<const PluginInterface>>& plugins);
|
||||
|
||||
void SetAdditionalDataPaths(
|
||||
const std::vector<std::filesystem::path>& dataPaths);
|
||||
|
||||
+2
-1
@@ -594,7 +594,8 @@ std::string Plugin::GetDescription() const {
|
||||
}
|
||||
|
||||
std::unique_ptr<Vec_PluginMetadata, decltype(&esp_plugins_metadata_free)>
|
||||
Plugin::GetPluginsMetadata(const std::vector<const Plugin*>& plugins) {
|
||||
Plugin::GetPluginsMetadata(
|
||||
const std::vector<const Plugin*>& plugins) {
|
||||
if (plugins.empty()) {
|
||||
return std::unique_ptr<Vec_PluginMetadata,
|
||||
decltype(&esp_plugins_metadata_free)>(
|
||||
|
||||
Reference in New Issue
Block a user