Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_deviceFactory Class Reference

Factory class for creating instances of classes derived from LOW_device. More...

#include <LOW_deviceFactory.h>

List of all members.

Public Types

typedef LOW_device *(* newInstanceFkt_t )(LOW_netSegment &, const LOW_deviceID &)
 Function type for static pseudo constructors.


Public Member Functions

 class_DERIVE_FROM_EXCEPTION (deviceFactory_error, LOW_exception)
 Exception base class for all exceptions thrown by LOW_deviceFactory.


Static Public Member Functions

LOW_devicenew_SpecificDevice (LOW_netSegment &inSegment, const LOW_deviceID &inDevID)
 Create new dynamic instance of specific device class.

void registerSpecificCtor (const LOW_deviceIDRaw::devFamCode_t inFamCode, newInstanceFkt_t inPseudoCnstr)
 Register a static pseudo constructor.


Private Types

typedef std::map< LOW_deviceIDRaw::devFamCode_t,
newInstanceFkt_t
ctorFktMap_t
 Map type for registered family types and constructors.


Private Member Functions

 LOW_deviceFactory ()
 Constructor.

virtual ~LOW_deviceFactory ()
 Destructor.


Static Private Attributes

ctorFktMap_tdeviceCtorsSingleton = 0
 Map holding registered family types and associated constructors.

newInstanceFkt_t unknownDevCtor = 0
 Pseudo constructor for unknown device types.


Detailed Description

Factory class for creating instances of classes derived from LOW_device.

Any class derived from LOW_device must register with this factory. After that, this factory can create "the right" instance of LOW_device subclasses on the fly.

To learn how to statically register at program initialization, see an already implemented subclass, e.g. LOW_devDS1820.

Author:
Harald Roelle

Definition at line 38 of file LOW_deviceFactory.h.


Member Typedef Documentation

typedef std::map< LOW_deviceIDRaw::devFamCode_t, newInstanceFkt_t> LOW_deviceFactory::ctorFktMap_t [private]
 

Map type for registered family types and constructors.

Definition at line 96 of file LOW_deviceFactory.h.

Referenced by registerSpecificCtor().

typedef LOW_device*(* LOW_deviceFactory::newInstanceFkt_t)( LOW_netSegment&, const LOW_deviceID&)
 

Function type for static pseudo constructors.

Definition at line 58 of file LOW_deviceFactory.h.


Constructor & Destructor Documentation

LOW_deviceFactory::LOW_deviceFactory  )  [private]
 

Constructor.

Private to prevent instaciation as this is a static factory.

Definition at line 28 of file LOW_deviceFactory.cpp.

LOW_deviceFactory::~LOW_deviceFactory  )  [private, virtual]
 

Destructor.

Private to prevent instaciation as this is a static factory.

Definition at line 33 of file LOW_deviceFactory.cpp.


Member Function Documentation

LOW_deviceFactory::class_DERIVE_FROM_EXCEPTION deviceFactory_error  ,
LOW_exception 
 

Exception base class for all exceptions thrown by LOW_deviceFactory.

LOW_device * LOW_deviceFactory::new_SpecificDevice LOW_netSegment inSegment,
const LOW_deviceID inDevID
[static]
 

Create new dynamic instance of specific device class.

The created instance is disposable with the "delete" operator.

Parameters:
inSegment Reference to network segment the device is on.
inDevID Reference to device's ID.
Returns:
New dynamic instance of specific device class.
Exceptions:
deviceFactory_error Thrown when device type is not registered.

Definition at line 43 of file LOW_deviceFactory.cpp.

References deviceCtorsSingleton, LOW_deviceIDRaw::getFamilyCode(), and unknownDevCtor.

Referenced by LOW_netSegment::addDevice().

void LOW_deviceFactory::registerSpecificCtor const LOW_deviceIDRaw::devFamCode_t  inFamCode,
newInstanceFkt_t  inPseudoCnstr
[static]
 

Register a static pseudo constructor.

Parameters:
inFamCode Family code of the specific class.
inPseudoCnstr Static pseudo constructor to register.
Exceptions:
deviceFactory_error Thrown when family type is already registered.

Definition at line 57 of file LOW_deviceFactory.cpp.

References LOW_device::anyDev_famCode, ctorFktMap_t, deviceCtorsSingleton, LOW_device::unknownDev_famCode, and unknownDevCtor.

Referenced by LOW_devUnknown::initialize(), LOW_devDS2890::initialize(), LOW_devDS2406::initialize(), LOW_devDS2405::initialize(), LOW_devDS2401::initialize(), and LOW_devDS1820::initialize().


Member Data Documentation

LOW_deviceFactory::ctorFktMap_t * LOW_deviceFactory::deviceCtorsSingleton = 0 [static, private]
 

Map holding registered family types and associated constructors.

Note: Singleton design pattern is important here, because order of static initialization produced by the compiler cannot be assured.

Definition at line 87 of file LOW_deviceFactory.cpp.

Referenced by new_SpecificDevice(), and registerSpecificCtor().

LOW_deviceFactory::newInstanceFkt_t LOW_deviceFactory::unknownDevCtor = 0 [static, private]
 

Pseudo constructor for unknown device types.

This constructor is used when no specific constructor is found.

Definition at line 89 of file LOW_deviceFactory.cpp.

Referenced by new_SpecificDevice(), and registerSpecificCtor().


The documentation for this class was generated from the following files:
Generated on Tue Feb 3 11:30:55 2004 for OneWireLibrary++ by doxygen 1.3.2