factory_impl.h
Go to the documentation of this file.
1 
11 #ifndef FACTORY_IMPL_H
12 #define FACTORY_IMPL_H
13 
14 /****************************************/
15 /****************************************/
16 
17 template<typename TYPE>
19  static typename CFactory<TYPE>::TTypeMap tTypeMap;
20  return tTypeMap;
21 }
22 
23 /****************************************/
24 /****************************************/
25 
26 template<typename TYPE>
27 void CFactory<TYPE>::Register(const std::string& str_label,
28  const std::string& str_author,
29  const std::string& str_version,
30  const std::string& str_brief_desc,
31  const std::string& str_long_desc,
32  const std::string& str_status,
33  TCreator* pc_creator) {
34  typename CFactory<TYPE>::STypeInfo* psTypeInfo = new typename CFactory<TYPE>::STypeInfo;
35  psTypeInfo->Author = str_author;
36  psTypeInfo->Version = str_version;
37  psTypeInfo->BriefDescription = str_brief_desc;
38  psTypeInfo->LongDescription = str_long_desc;
39  psTypeInfo->Status = str_status;
40  psTypeInfo->Creator = pc_creator;
41  GetTypeMap()[str_label] = psTypeInfo;
42 }
43 
44 /****************************************/
45 /****************************************/
46 
47 template<typename TYPE>
48 TYPE* CFactory<TYPE>::New(const std::string& str_label) {
49  typename TTypeMap::iterator it = GetTypeMap().find(str_label);
50  if(it != GetTypeMap().end()) {
51  return it->second->Creator();
52  }
53  else {
54  THROW_ARGOSEXCEPTION("Symbol \"" << str_label << "\" not found");
55  }
56 }
57 
58 /****************************************/
59 /****************************************/
60 
61 template<typename TYPE>
62 bool CFactory<TYPE>::Exists(const std::string& str_label) {
63  typename TTypeMap::iterator it = GetTypeMap().find(str_label);
64  return(it != GetTypeMap().end());
65 }
66 
67 /****************************************/
68 /****************************************/
69 
70 template<typename TYPE>
71 void CFactory<TYPE>::Print(std::ostream& c_os) {
72  typename TTypeMap::iterator it;
73  c_os << "Symbols:" << std::endl;
74  for(it = GetTypeMap().begin();
75  it != GetTypeMap().end();
76  ++it) {
77  c_os << it->first << " (" << it->second->BriefDescription << ")" << std::endl;
78  }
79 }
80 
81 /****************************************/
82 /****************************************/
83 
84 template<typename TYPE>
86  typename TTypeMap::iterator it;
87  for(it = GetTypeMap().begin();
88  it != GetTypeMap().end();
89  ++it) {
90  delete it->second;
91  }
92  GetTypeMap().clear();
93 }
94 
95 /****************************************/
96 /****************************************/
97 
98 #endif
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
std::string LongDescription
Definition: factory.h:75
Basic factory template.
Definition: factory.h:59
std::string BriefDescription
Definition: factory.h:74
std::map< std::string, STypeInfo * > TTypeMap
The map of registered TYPEs.
Definition: factory.h:82
A struct containing the information about the registered types.
Definition: factory.h:70