8#include "Arp/System/Commons/Exceptions/ArgumentException.hpp"
12namespace Arp {
namespace System {
namespace Commons {
namespace Extensibility
18template<
typename TModuleInterface>
23 using ModuleInterfacePtr = std::unique_ptr<TModuleInterface>;
24 using FactoryFunction = std::function<ModuleInterfacePtr()>;
25 using FactoryFunctions = std::vector<std::pair<String, FactoryFunction>>;
44 ModuleInterfacePtr
Create(
const String& moduleName)
const;
57 typename FactoryFunctions::const_iterator FindByName(
const String& moduleName)
const;
60 FactoryFunctions factoryFunctions;
64template<
typename TModuleInterface>
67 auto it = this->FindByName(moduleName);
68 if (it == this->factoryFunctions.end())
70 return ModuleInterfacePtr{};
78template<
typename TModuleInterface>
81 std::vector<String> result;
82 result.reserve(this->factoryFunctions.size());
83 std::transform(this->factoryFunctions.begin(), this->factoryFunctions.end(),
84 std::back_inserter(result), [](
const typename FactoryFunctions::value_type & each)
91template<
typename TModuleInterface>
93 const String& moduleName, FactoryFunction function)
100 if (function ==
nullptr)
105 auto it = this->FindByName(moduleName);
106 if (it == this->factoryFunctions.end())
108 this->factoryFunctions.emplace_back(moduleName, function);
116template<
typename TModuleInterface>
118 const String& moduleName)
const
120 return std::find_if(this->factoryFunctions.begin(), this->factoryFunctions.end(),
121 [&moduleName](
const typename FactoryFunctions::value_type & each)
123 return each.first == moduleName;
static ArgumentException Create(const char *paramName, const T ¶mValue)
Creates an ArgumentException instance using a default message text.
Definition: ArgumentException.hpp:112
Factory class for extension modules
Definition: ModuleFactory.hxx:20
ModuleFactory & operator=(ModuleFactory &&arg) noexcept=default
Move-assignment operator.
void AddFactoryFunction(const String &moduleName, FactoryFunction function)
Adds a factory function
Definition: ModuleFactory.hxx:92
ModuleFactory(const ModuleFactory &arg)=default
Copy constructor.
ModuleFactory(void)=default
Constructs an ModuleFactory instance.
ModuleInterfacePtr Create(const String &moduleName) const
Creates a module instance
Definition: ModuleFactory.hxx:65
virtual ~ModuleFactory(void) noexcept=default
Destructs this instance and frees all resources.
std::vector< String > GetModuleNames() const
Returns all known module names
Definition: ModuleFactory.hxx:79
ModuleFactory & operator=(const ModuleFactory &arg)=default
Copy-assignment operator.
ModuleFactory(ModuleFactory &&arg) noexcept=default
Move constructor.
bool IsEmpty() const
Determines if this string is empty.
Definition: BasicString.hxx:1086
Root namespace for the PLCnext API