Poco

template < class Base >

class DynamicFactory

File Information

Library: Foundation
Package: Core
Header: Poco/DynamicFactory.h

Description

A factory that creates objects by class name.

Member Summary

Member Functions: createInstance, isClass, registerClass, unregisterClass

Types

AbstractFactory

typedef AbstractInstantiator < Base > AbstractFactory;

Constructors

DynamicFactory inline

DynamicFactory();

Creates the DynamicFactory.

Destructor

~DynamicFactory inline

~DynamicFactory();

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

Member Functions

createInstance inline

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.

isClass inline

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

Returns true if and only if the given class has been registered.

registerClass inline

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.

registerClass inline

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.

unregisterClass inline

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.