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>>;
 
   27    ModuleInterfacePtr 
Create(
const String& moduleName) 
const;
 
   32    typename FactoryFunctions::const_iterator FindByName(
const String& moduleName) 
const;
 
   35    FactoryFunctions factoryFunctions;
 
   42template<
typename TModuleInterface>
 
   45    auto it = this->FindByName(moduleName);
 
   46    if (it == this->factoryFunctions.end())
 
   48        return ModuleInterfacePtr{};
 
   57template<
typename TModuleInterface>
 
   60    std::vector<String> result;
 
   61    result.reserve(this->factoryFunctions.size());
 
   62    std::transform(this->factoryFunctions.begin(), this->factoryFunctions.end(),
 
   63                   std::back_inserter(result), [](
const typename FactoryFunctions::value_type & each)
 
   74template<
typename TModuleInterface>
 
   76    const String& moduleName, FactoryFunction function)
 
   83    if (function == 
nullptr)
 
   88    auto it = this->FindByName(moduleName);
 
   89    if (it == this->factoryFunctions.end())
 
   91        this->factoryFunctions.emplace_back(moduleName, function);
 
   99template<
typename TModuleInterface>
 
  101    const String& moduleName)
 const 
  103    return std::find_if(this->factoryFunctions.begin(), this->factoryFunctions.end(),
 
  104                        [&moduleName](
const typename FactoryFunctions::value_type & each)
 
  106        return each.first == moduleName;
 
static ArgumentException Create(const char *paramName, const T ¶mValue)
Creates an ArgumentException using a default message.
Definition: ArgumentException.hpp:92
 
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
 
bool IsEmpty(void) const
Determines if this string is empty.
Definition: String.ipp:991
 
Factory class for extension modules
Definition: ModuleFactory.hxx:20
 
void AddFactoryFunction(const String &moduleName, FactoryFunction function)
Adds a factory function
Definition: ModuleFactory.hxx:75
 
ModuleInterfacePtr Create(const String &moduleName) const
Creates a module instance
Definition: ModuleFactory.hxx:43
 
std::vector< String > GetModuleNames() const
Returns all known module names
Definition: ModuleFactory.hxx:58
 
Root namespace for the PLCnext API