Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::DeviceFactory Class Reference

Object used for creating devices. More...

#include <DeviceFactory.h>

List of all members.

Public Methods

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

InputloadDevice (jccl::ConfigElementPtr element)
 Loads the specified device. More...


Detailed Description

Object used for creating devices.

Note:
Singleton

Definition at line 53 of file DeviceFactory.h.


Member Function Documentation

void gadget::DeviceFactory::registerDevice DeviceConstructorBase   constructor
 

Definition at line 152 of file DeviceFactory.cpp.

References gadgetDBG_INPUT_MGR.

00153 {
00154    vprASSERT(constructor != NULL);
00155    mConstructors.push_back(constructor);     // Add the constructor to the list
00156    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00157       << "gadget::DeviceFactory: Registered: "
00158       << std::setiosflags(std::ios::right) << std::setw(25)
00159       << std::setfill(' ') << constructor->getElementType()
00160       << std::setiosflags(std::ios::right)
00161       //<< "   :" << (void*)constructor
00162       << "  type: " << typeid(*constructor).name() << std::endl
00163       << vprDEBUG_FLUSH;
00164 }

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 168 of file DeviceFactory.cpp.

Referenced by loadDevice.

00169 {
00170    return ! (findConstructor(element) == -1);
00171 }

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 176 of file DeviceFactory.cpp.

References gadgetDBG_INPUT_MGR, and recognizeDevice.

00177 {
00178    vprASSERT(recognizeDevice(element));
00179 
00180    int index(findConstructor(element));
00181 
00182    Input* new_dev;
00183    DeviceConstructorBase* constructor = mConstructors[index];
00184 
00185    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00186       << "gadget::DeviceFactory::loadDevice: Loading device: "
00187       << element->getID() << "  with: " << typeid(*constructor).name()
00188       << std::endl << vprDEBUG_FLUSH;
00189 
00190    new_dev = constructor->createDevice(element);
00191    return new_dev;
00192 }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:26:55 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002