PaCO++  0.05
FabriqueManagerTpl.h
Go to the documentation of this file.
1 #ifndef PACO_FABRIQUE_IS_DEFINED
2 #define PACO_FABRIQUE_IS_DEFINED
3 
4 #include <iostream>
5 #include <cstdlib>
6 #include <string>
7 #include <map>
8 #include <vector>
9 
10 // Concrete fabrique must inherit from this type
11 template<class T> class paco_fabrique_manager_tpl {
12 protected:
13  // Store the association name <-> fabrique
14  typedef typename std::map<std::string, T*> fab_map_t;
15  fab_map_t _fab_map;
16 
17 public:
18 
19  paco_fabrique_manager_tpl() { _fab_map.clear(); }
20 
22 
23  void paco_register(const ::std::string& fabname, T* pf)
24  {
25  typename fab_map_t::iterator it = _fab_map.find(fabname);
26 
27  if (it == _fab_map.end() )
28  {
29  // Debug
30  // cout << "Adding fab " << fabname << endl;
31  _fab_map[fabname] = pf;
32  }
33  else
34  {
35  // Debug
36  // cout << "Ignoring: already register fab " << fabname << endl;
37  }
38  }
39 
40  T* paco_get(const ::std::string& fabname)
41  {
42  typename fab_map_t::iterator it = _fab_map.find(fabname);
43 
44  if (it == _fab_map.end() )
45  {
46  // Debug
47  std::cerr << "Error: fab not found -- " << fabname << std::endl;
48  std::abort();
49  }
50  else
51  {
52  return it->second;
53  }
54 
55  }
56 
57 };
58 
59 #endif
T * paco_get(const ::std::string &fabname)
std::map< std::string, T * > fab_map_t
void paco_register(const ::std::string &fabname, T *pf)