#include <basicdevicefactory.h>
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 Device * | createDevice (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) |
|
Pointer to a function that will create a device. (New since simthetic-0.7, Feb 2004)
|
|
The map containing typenames and respective factory functions. (New since simthetic-0.7, Feb 2004) |
|
Default constructor. Does nothing. |
|
Default destructor. Does nothing. |
|
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
|
|
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. |
|
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>)); } |