PaCO++  0.05
FabriqueManagerTpl.h
Go to the documentation of this file.
00001 #ifndef PACO_FABRIQUE_IS_DEFINED
00002 #define PACO_FABRIQUE_IS_DEFINED
00003 
00004 #include <iostream>
00005 #include <cstdlib>
00006 #include <string>
00007 #include <map>
00008 #include <vector>
00009 
00010 // Concrete fabrique must inherit from this type
00011 template<class T> class paco_fabrique_manager_tpl {
00012 protected:
00013   // Store the association name <-> fabrique
00014   typedef typename std::map<std::string, T*> fab_map_t;
00015   fab_map_t _fab_map;
00016 
00017 public:
00018 
00019   paco_fabrique_manager_tpl() { _fab_map.clear(); }
00020 
00021   virtual ~paco_fabrique_manager_tpl() {};
00022 
00023   void paco_register(const ::std::string& fabname, T* pf)
00024   {    
00025     typename fab_map_t::iterator it = _fab_map.find(fabname);
00026     
00027     if (it == _fab_map.end() )
00028       {
00029    // Debug
00030    // cout << "Adding fab " << fabname << endl;
00031    _fab_map[fabname] = pf;
00032       }
00033     else
00034       {
00035    // Debug
00036    // cout << "Ignoring: already register fab " << fabname << endl;
00037       }
00038   }
00039 
00040   T* paco_get(const ::std::string& fabname) 
00041   {
00042     typename fab_map_t::iterator it = _fab_map.find(fabname);
00043     
00044     if (it == _fab_map.end() )
00045       {
00046    // Debug
00047    std::cerr << "Error: fab not found -- " << fabname << std::endl;
00048    std::abort();
00049       }
00050     else
00051       {
00052    return  it->second;
00053       }
00054    
00055   }
00056   
00057 };
00058 
00059 #endif