gadget::DeviceFactory Class Reference

Object used for creating devices. More...

#include <gadget/Type/DeviceFactory.h>

List of all members.

Public Member Functions

void registerDevice (DeviceConstructorBase *constructor)
bool recognizeDevice (jccl::ConfigElementPtr element)
 Queries if the factory knows about the given device.
InputloadDevice (jccl::ConfigElementPtr element)
 Loads the specified device.


Detailed Description

Object used for creating devices.

Note:
Singleton

Definition at line 54 of file DeviceFactory.h.


Member Function Documentation

void gadget::DeviceFactory::registerDevice ( DeviceConstructorBase constructor  ) 

Definition at line 161 of file DeviceFactory.cpp.

References gadgetDBG_INPUT_MGR(), and gadget::DeviceConstructorBase::getElementType().

Referenced by gadget::DeviceConstructor< DEV >::DeviceConstructor().

00162 {
00163    vprASSERT(constructor != NULL);
00164    mConstructors.push_back(constructor);     // Add the constructor to the list
00165    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00166       << "gadget::DeviceFactory: Registered: "
00167       << std::setiosflags(std::ios::right) << std::setw(25)
00168       << std::setfill(' ') << constructor->getElementType()
00169       << std::setiosflags(std::ios::right)
00170       //<< "   :" << (void*)constructor
00171       << "  type: " << typeid(*constructor).name() << std::endl
00172       << vprDEBUG_FLUSH;
00173 }

bool gadget::DeviceFactory::recognizeDevice ( jccl::ConfigElementPtr  element  ) 

Queries if the factory knows about the given device.

Precondition:
element != NULL, element is a valid element.
Parameters:
element The element we are requesting about knowledge to create.
Returns:
true if the factory knows how to create the device; false if not.

Definition at line 177 of file DeviceFactory.cpp.

Referenced by loadDevice().

00178 {
00179    return ! (findConstructor(element) == -1);
00180 }

Input * gadget::DeviceFactory::loadDevice ( jccl::ConfigElementPtr  element  ) 

Loads the specified device.

Precondition:
recognizeDevice(element) == true.
Parameters:
element The specification of the device to load.
Returns:
NULL is returned if the device failed to load. Otherwise, a pointer to the loaded device is returned.

Definition at line 185 of file DeviceFactory.cpp.

References gadget::DeviceConstructorBase::createDevice(), gadgetDBG_INPUT_MGR(), and recognizeDevice().

00186 {
00187    vprASSERT(recognizeDevice(element));
00188 
00189    int index(findConstructor(element));
00190 
00191    Input* new_dev;
00192    DeviceConstructorBase* constructor = mConstructors[index];
00193 
00194    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00195       << "gadget::DeviceFactory::loadDevice: Loading device: "
00196       << element->getID() << "  with: " << typeid(*constructor).name()
00197       << std::endl << vprDEBUG_FLUSH;
00198 
00199    new_dev = constructor->createDevice(element);
00200    return new_dev;
00201 }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:44:52 2007 for Gadgeteer by  doxygen 1.5.1