template class Poco::DynamicFactory

Overview

A factory that creates objects by class name. More…

#include <DynamicFactory.h>

template <class Base>
class DynamicFactory
{
public:
    // typedefs

    typedef AbstractInstantiator<Base> AbstractFactory;

    // methods

    Base*
    createInstance(const std::string& className) const;

    template <class C>
    void
    registerClass(const std::string& className);

    void
    registerClass(
        const std::string& className,
        AbstractFactory* pAbstractFactory
        );

    void
    unregisterClass(const std::string& className);

    bool
    isClass(const std::string& className) const;
};

Detailed Documentation

A factory that creates objects by class name.

Construction

~DynamicFactory()

Destroys the DynamicFactory and deletes the instantiators for all registered classes.

Methods

Base*
createInstance(const std::string& className) const

Creates a new instance of the class with the given name.

The class must have been registered with registerClass. If the class name is unknown, a NotFoundException is thrown.

template <class C>
void
registerClass(const std::string& className)

Registers the instantiator for the given class with the DynamicFactory.

The DynamicFactory takes ownership of the instantiator and deletes it when it’s no longer used. If the class has already been registered, an ExistsException is thrown and the instantiator is deleted.

void
registerClass(
    const std::string& className,
    AbstractFactory* pAbstractFactory
    )

Registers the instantiator for the given class with the DynamicFactory.

The DynamicFactory takes ownership of the instantiator and deletes it when it’s no longer used. If the class has already been registered, an ExistsException is thrown and the instantiator is deleted.

void
unregisterClass(const std::string& className)

Unregisters the given class and deletes the instantiator for the class.

Throws a NotFoundException if the class has not been registered.

bool
isClass(const std::string& className) const

Returns true iff the given class has been registered.