PetaVision  Alpha
 All Data Structures Namespaces Functions Variables
PV::Factory Class Reference

#include <Factory.hpp>

Static Public Member Functions

static BaseObjectcreateNull (char const *name, HyPerCol *hc)
 

Private Member Functions

 Factory ()
 
 Factory (Factory const &orig)
 
virtual ~Factory ()
 
int clearKeywordHandlerList ()
 
int copyKeywordHandlerList (std::vector< KeywordHandler * > const &orig)
 
BaseObjectcreate (char const *keyword, char const *name, HyPerCol *hc) const
 
KeywordHandler const * getKeywordHandler (char const *keyword) const
 
Factoryoperator= (Factory const &orig)
 
int registerCoreKeywords ()
 
int registerKeyword (char const *keyword, ObjectCreateFn creator)
 

Private Attributes

std::vector< KeywordHandler * > keywordHandlerList
 

Friends

class PV_Init
 

Detailed Description

The class to manage adding layers, connections, etc. to a HyPerCol. The function build() in buildandrun.cpp (which is the basis of all the functions in buildandrun.cpp) uses Factory to build the HyPerCol.

This class is accessible only by the PV_Init class, which has the factory member variable.

The standard Factory constructor already registers the objects in the PetaVision core. For example, calling the Factory::create() method with keyword "ANNLayer" calls the createANNLayer() object creator function in layers/ANNLayer.cpp. In practice, the Factory::create() method is called by the PV_Init::create() method, which passes the arguments to the Factory:

PV_Init pv_init(&argc, &argv, false); // 3rd argument is whether to allow command-line arguments that PV doesn't recognize HyPerCol * hc = new HyPerCol("column", pv_init); pv_init.create("ANNLayer", "layer", hc);

(note that the functions in buildandrun.cpp and the PV_Init::build() method automate the task of calling the create() method for the groups in the params file).

If you have a custom object, you need to register it with the Factory object by associating its keyword with a function pointer that takes two arguments: a C-style string giving the name of the individual layer, and pointer to a HyPerCol. This function should instantiate the new object with the new operator, and return it as a pointer of type BaseObject the base class for layers, connections, etc.) In practice, the Factory::registerKeyword() method is called by the PV_registerKeyword() method, which again passes its arguments to the Factory. For example:

class CustomLayerType : public HyPerLayer { ... }; ... BaseObject * createCustomLayerType(char const * name, HyPerCol * hc) { return new CustomLayerType(name, hc); } ... PV_Init pv_init(&argc, &argv, false); HyPerCol * hc = new HyPerCol("column", &pv_init); pv_init.registerKeyword("customLayerType", createCustomLayerType); pv_init.create("customLayerType", hc) ...

Again, the functions in buildandrun.cpp automate the task of calling the create() method; in practice, you only need define the creator function createCustomLayerType, and call the registerKeyword method calling before one of the buildandrun functions.

Definition at line 70 of file Factory.hpp.

Constructor & Destructor Documentation

PV::Factory::Factory ( )
private

The constructor for Factory. It initializes the list of known keywords to the core PetaVision keywords.

Definition at line 103 of file Factory.cpp.

PV::Factory::Factory ( Factory const &  orig)
private

The copy constructor for Factory

Definition at line 107 of file Factory.cpp.

PV::Factory::~Factory ( )
privatevirtual

The destructor for Factory

Definition at line 256 of file Factory.cpp.

Member Function Documentation

int PV::Factory::clearKeywordHandlerList ( )
private

A method used internally by the copy assignment operator and destructor, to deallocate and clear the keyword handler list.

Definition at line 247 of file Factory.cpp.

int PV::Factory::copyKeywordHandlerList ( std::vector< KeywordHandler * > const &  orig)
private

A method used internally by the copy assignment operator and copy constructor, to copy a keyword handler list into the Factory.

Definition at line 214 of file Factory.cpp.

BaseObject * PV::Factory::create ( char const *  keyword,
char const *  name,
HyPerCol hc 
) const
private

The method to create an object of the type specified by keyword, with the given name and parent HyPerCol. It calls the function associated with the keyword by the registerKeyword pointer.

Definition at line 232 of file Factory.cpp.

static BaseObject* PV::Factory::createNull ( char const *  name,
HyPerCol hc 
)
inlinestatic

A function pointer that can be used in a registerKeyword call, that always returns the null object. The "normalizeGroup", "none", and "" keywords all use the createNull function pointer.

Definition at line 78 of file Factory.hpp.

KeywordHandler const * PV::Factory::getKeywordHandler ( char const *  keyword) const
private

A method used internally to retrieve the keyword handler corresponding to a given keyword.

Definition at line 237 of file Factory.cpp.

Factory & PV::Factory::operator= ( Factory const &  orig)
private

The copy assignment operator for Factory

Definition at line 111 of file Factory.cpp.

int PV::Factory::registerCoreKeywords ( )
private

The function called by the default constructor, to add the core PetaVision keywords.

Definition at line 118 of file Factory.cpp.

int PV::Factory::registerKeyword ( char const *  keyword,
ObjectCreateFn  creator 
)
private

The method to add a new object type to the Factory. keyword is the string that labels the object type, matching the keyword used in params files. creator is a pointer to a function that takes a name and a HyPerCol pointer, and creates an object of the corresponding keyword, with the given name and parent HyPerCol. The function should return a pointer of type BaseObject, created with the new operator.

Definition at line 222 of file Factory.cpp.


The documentation for this class was generated from the following files: