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

LOW_deviceFactory.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_deviceFactory.cpp  -  description
00003                              -------------------
00004     begin                : Mon Aug 5 2002
00005     copyright            : (C) 2002 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include "LOW_deviceFactory.h"
00020 
00021 
00022 
00023 //=====================================================================================
00024 //
00025 // constructors
00026 //
00027 
00028 LOW_deviceFactory::LOW_deviceFactory()
00029 {
00030 }
00031 
00032 
00033 LOW_deviceFactory::~LOW_deviceFactory()
00034 {
00035 }
00036 
00037 
00038 //=====================================================================================
00039 //
00040 // static methods
00041 //
00042 
00043 LOW_device* LOW_deviceFactory::new_SpecificDevice( LOW_netSegment &inSegment, const LOW_deviceID &inDevID)
00044 {
00045   ctorFktMap_t::iterator foundCnstr = deviceCtorsSingleton->find( inDevID.getFamilyCode());
00046   
00047   if ( foundCnstr == deviceCtorsSingleton->end() )
00048     if ( unknownDevCtor == 0 )
00049       throw deviceFactory_error( "Family code unknown and no constructor for unknown devices registered.", __FILE__, __LINE__);
00050     else
00051       return unknownDevCtor( inSegment, inDevID);
00052   else
00053     return foundCnstr->second( inSegment, inDevID);
00054 }
00055 
00056 
00057 void LOW_deviceFactory::registerSpecificCtor( LOW_deviceIDRaw::devFamCode_t inFamCode, newInstanceFkt_t inPseudoCnstr)
00058 {
00059   // singleton design pattern
00060   if ( deviceCtorsSingleton == 0 )
00061     deviceCtorsSingleton = new ctorFktMap_t();
00062 
00063   if ( inFamCode == LOW_device::anyDev_famCode )
00064     throw deviceFactory_error( "Cannot register for anyDev_famCode.", __FILE__, __LINE__);
00065 
00066   if ( inFamCode == LOW_device::unknownDev_famCode ) {
00067     if ( unknownDevCtor != 0 )
00068       throw deviceFactory_error( "Constructor for unknown devices already registered.", __FILE__, __LINE__);
00069     unknownDevCtor = inPseudoCnstr;
00070   }
00071   else {
00072     if ( (*deviceCtorsSingleton)[inFamCode] != 0 )
00073       throw deviceFactory_error( "Familiy type already registered. Family code: "+
00074                                  inFamCode, __FILE__, __LINE__);
00075     (*deviceCtorsSingleton)[inFamCode] = inPseudoCnstr;
00076   }
00077 }
00078 
00079 
00080 
00081 //=====================================================================================
00082 //
00083 // static attributes
00084 //
00085 
00086 // Do not really initialize here! Must use singleton pattern!
00087 LOW_deviceFactory::ctorFktMap_t*  LOW_deviceFactory::deviceCtorsSingleton = 0;
00088 
00089 LOW_deviceFactory::newInstanceFkt_t LOW_deviceFactory::unknownDevCtor = 0;
00090 

Generated on Tue Feb 3 11:30:25 2004 for OneWireLibrary++ by doxygen 1.3.2