CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/L1Trigger/RPCTechnicalTrigger/interface/LogicFactory.h

Go to the documentation of this file.
00001 // $Id: LogicFactory.h,v 1.1 2009/05/16 19:43:30 aosorio Exp $
00002 #ifndef LOGICFACTORY_H 
00003 #define LOGICFACTORY_H 1
00004 
00005 // Include files
00006 #include <stdlib.h>
00007 #include <string>
00008 #include <map>
00009 
00020 template <class Ilogic, typename Identifier, typename LogicCreator = Ilogic * (*)()> 
00021 class LogicFactory {
00022 public: 
00023   
00024   bool Register( const Identifier & id, LogicCreator creator)
00025   {
00026     return m_associations.insert(typename std::map<Identifier, LogicCreator>::value_type(id,creator)).second;
00027   }
00028   
00029   bool Unregister( const Identifier & id )
00030   {
00031     typename std::map<Identifier, LogicCreator>::const_iterator itr;
00032     itr = m_associations.find(id);
00033     if( itr != m_associations.end() ) {
00034       delete ( itr->second )() ;
00035     }
00036     return m_associations.erase(id) == 1;
00037   }
00038   
00039   Ilogic* CreateObject( const Identifier & id )
00040   {
00041     typename std::map<Identifier, LogicCreator>::const_iterator itr;
00042     itr = m_associations.find( id );
00043     
00044     if ( itr != m_associations.end() )  {
00045       return ( itr->second )();
00046     } else return NULL; // handle error
00047   }
00048   
00049 protected:
00050   
00051 private:
00052   
00053   typename std::map<Identifier, LogicCreator> m_associations;
00054   
00055 };
00056 #endif // LOGICFACTORY_H