00001 /*************************************************************************** 00002 LOW_deviceFactory.cpp - description 00003 ------------------- 00004 begin : Mon Aug 5 2002 00005 copyright : (C) 2002 by Harald Roelle, Helmut Reiser 00006 email : roelle@informatik.uni-muenchen.de, reiser@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 // static methods 00026 // 00027 00028 LOW_device* LOW_deviceFactory::new_SpecificDevice( LOW_netSegment &inSegment, const LOW_deviceID &inDevID) 00029 { 00030 ctorFktMap_t::iterator foundCnstr = deviceCtorsSingleton->find( inDevID.getFamilyCode()); 00031 00032 if ( foundCnstr == deviceCtorsSingleton->end() ) 00033 throw deviceFactory_error( "Family type unknown. Family code: "+inDevID.getFamilyCode(), __FILE__, __LINE__); 00034 00035 return foundCnstr->second( inSegment, inDevID); 00036 } 00037 00038 00039 void LOW_deviceFactory::registerSpecificCtor( LOW_deviceIDRaw::devFamCode_t inFamCode, newInstanceFkt_t inPseudoCnstr) 00040 { 00041 // singleton design pattern 00042 if ( deviceCtorsSingleton == 0 ) 00043 deviceCtorsSingleton = new ctorFktMap_t(); 00044 00045 if ( inFamCode == LOW_device::anyDev_famCode ) 00046 throw deviceFactory_error( "Cannot register for anyDev_famCode.", __FILE__, __LINE__); 00047 00048 if ( (*deviceCtorsSingleton)[inFamCode] != 0 ) 00049 throw deviceFactory_error( "Familiy type already registered. Family code: "+ 00050 inFamCode, __FILE__, __LINE__); 00051 00052 (*deviceCtorsSingleton)[inFamCode] = inPseudoCnstr; 00053 } 00054 00055 00056 00057 //===================================================================================== 00058 // 00059 // static attributes 00060 // 00061 00062 // Do not really initialize here! Must use singleton pattern! 00063 LOW_deviceFactory::ctorFktMap_t* LOW_deviceFactory::deviceCtorsSingleton = 0; 00064