6 #include <Poco/SharedPtr.h>
20 typedef Poco::SharedPtr<DIFactory> Ptr;
31 const std::string &name,
44 const std::string &name,
47 auto wrapper =
create(name, detach);
48 if (wrapper ==
nullptr)
51 return cast<T>(*wrapper);
69 Poco::SharedPtr<T>
find(
const std::string &name)
72 if (wrapper ==
nullptr)
75 return cast<T>(*wrapper);
86 Poco::SharedPtr<T> instance;
87 castImpl(
typeid(T), wrapper, reinterpret_cast<void *>(&instance));
104 const std::string &name,
113 const std::type_info &type,
virtual DIWrapper * createImpl(const std::string &name, bool detach)=0
Poco::SharedPtr< T > create(const std::string &name, bool detach=false)
Create a new instance by name and perform runtime cast to the target type if possible.
Definition: DIFactory.h:43
DIWrapper * find(const std::string &name)
Find an existing instance and return it.
Definition: DIFactory.h:58
Poco::SharedPtr< T > find(const std::string &name)
Find an existing instance and cast it to the target type if possible.
Definition: DIFactory.h:69
Definition: DIWrapper.h:386
Implementation of DIFactory can manage and create instances by name and automatically (usually based ...
Definition: DIFactory.h:18
DIWrapper * create(const std::string &name, bool detach=false)
Create a new instance by name. If detached is true, the memory of the returned DIWrapper pointer MUST...
Definition: DIFactory.h:30
Poco::SharedPtr< T > cast(DIWrapper &wrapper)
Cast the wrapped instance to the target type. If the cast is not possible, throw an exception...
Definition: DIFactory.h:84
virtual void castImpl(const std::type_info &type, const DIWrapper &wrapper, void *target)=0
Perform cast of the given wrapper to the target of the given type. The target points to the Poco::Sha...
virtual DIWrapper * findImpl(const std::string &name)=0