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     throw deviceFactory_error( "Family type unknown. Family code: "+inDevID.getFamilyCode(), __FILE__, __LINE__);
00049   
00050   return foundCnstr->second( inSegment, inDevID);
00051 }
00052 
00053 
00054 void LOW_deviceFactory::registerSpecificCtor( LOW_deviceIDRaw::devFamCode_t inFamCode, newInstanceFkt_t inPseudoCnstr)
00055 {
00056   // singleton design pattern
00057   if ( deviceCtorsSingleton == 0 )
00058     deviceCtorsSingleton = new ctorFktMap_t();
00059 
00060   if ( inFamCode == LOW_device::anyDev_famCode )
00061     throw deviceFactory_error( "Cannot register for anyDev_famCode.", __FILE__, __LINE__);  
00062 
00063   if ( (*deviceCtorsSingleton)[inFamCode] != 0 )
00064     throw deviceFactory_error( "Familiy type already registered. Family code: "+
00065                                inFamCode, __FILE__, __LINE__);
00066                     
00067   (*deviceCtorsSingleton)[inFamCode] = inPseudoCnstr;
00068 }
00069 
00070 
00071 
00072 //=====================================================================================
00073 //
00074 // static attributes
00075 //
00076 
00077 // Do not really initialize here! Must use singleton pattern!
00078 LOW_deviceFactory::ctorFktMap_t*  LOW_deviceFactory::deviceCtorsSingleton = 0;
00079 

Generated on Mon Oct 27 22:56:08 2003 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001