Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

simth::DeviceFactory Class Reference

Abstract base class of classes used to create devices. More...

#include <basicdevicefactory.h>

List of all members.

Public Types

typedef simth::Device *(* FactoryFunc )(int id, simth::DeviceSystemIntf *sysPtr, const simth::PropertyList &pl, const std::string &cpptype)
typedef std::map< std::string,
FactoryFunc
FactoryMap

Public Member Functions

 DeviceFactory ()
virtual ~DeviceFactory ()=0
Old factory function
virtual DevicecreateDevice (const std::string &fileName, DeviceSystemIntf *sysPtr, int ID, const std::string blockQualifier="")=0
New factory function mechanism since simthetic-0.7
virtual FactoryMap allDevices ()
void addFunction (const std::string &cppname, FactoryFunc func)


Detailed Description

Abstract base class of classes used to create devices.

See also:
Device basicdevicefactory.h


Member Typedef Documentation

typedef simth::Device*(* simth::DeviceFactory::FactoryFunc)(int id, simth::DeviceSystemIntf *sysPtr, const simth::PropertyList &pl, const std::string &cpptype)
 

Pointer to a function that will create a device. (New since simthetic-0.7, Feb 2004)

Parameters:
id index of the device in the simulation system
sysPtr pointer to the simulation system
pl The propertylist of this device
cpptype Fully qualified C++ type name; it is up to this function's implementation whether this is checked or not. For template classes this might be used to choose the actual template instance. Also, this can be used so that one single factory function will create a variety of different classes, distinguished by this type name parameter.
Returns:
pointer to the newly created device

typedef std::map<std::string, FactoryFunc> simth::DeviceFactory::FactoryMap
 

The map containing typenames and respective factory functions. (New since simthetic-0.7, Feb 2004)


Constructor & Destructor Documentation

simth::DeviceFactory::DeviceFactory  ) 
 

Default constructor. Does nothing.

virtual simth::DeviceFactory::~DeviceFactory  )  [pure virtual]
 

Default destructor. Does nothing.


Member Function Documentation

virtual Device* simth::DeviceFactory::createDevice const std::string &  fileName,
DeviceSystemIntf sysPtr,
int  ID,
const std::string  blockQualifier = ""
[pure virtual]
 

Creates a Device.

This is the old, version-1, not-so-recommended way of creating a device. Your implementation of this function will have to open the file filename yourself, and you have to deal with the whole issue of file format and so on. Instead, the new recommended way of creating a device consists of a big map of FactoryFunc's, so that your implementation of the DeviceFactory and of the Device does not have to deal with the actual parameter file format anymore.

Parameters:
fileName name of the parameter file
sysPtr pointer to the simulation system
ID index of the device in the simulation system
blockQualifier String that qualifies the block's parameter region in the old parameter file format.
Returns:
pointer to the new device allocated on the heap

virtual FactoryMap simth::DeviceFactory::allDevices  )  [virtual]
 

Returns a map of all available C++ typenames and their factory functions in this library. (New since simthetic-0.7, Feb 2004)

This function returns the FactoryMap as created by calls to the addFunction() function.

This is the new, recommended mechanism to create devices. To implement this in your own device class, you either reimplement this function, or you only need call the function addFunction() for each available factory function (see addFunction() ).

The big advantage here is that you don't have to deal with the actual parameter files *at all* in your device library anymore -- neither in your DeviceFactory class nor in your actual Device class. Also, it is totally up to you where you define the actual factory function, as long as it conforms to the FactoryFunc signature. You can decide whether you have one single FactoryFunc for a variety of classes, or whether you have many FactoryFunc's, one for each of your classes.

We definitely recommend using this technique for new device classes.

This default implementation simply returns an empty map. Therefor other libraries can safely either override this or they leave it alone for now.

void simth::DeviceFactory::addFunction const std::string &  cppname,
FactoryFunc  func
 

Register one factory function to the FactoryMap of this DeviceFactory.

To use it, you use the factory_template template function (below) in the constructor of your derived DeviceFactory class as follows:

     MyLibFactory::MyLibFactory() : DeviceFactory() {
       addFunction("mylib::MyDeviceClass", factory_template<MyDeviceClass>));
     }
     


Generated on Mon Aug 15 13:54:32 2005 for simthetic by  doxygen 1.4.1