ARGoS 3
A parallel, multi-engine simulator for swarm robotics
factory.h
Go to the documentation of this file.
1
44#ifndef FACTORY_H
45#define FACTORY_H
46
47#include <argos3/core/utility/configuration/argos_exception.h>
48#include <map>
49#include <iostream>
50#include <string>
51#include <cstdlib>
52
53namespace argos {
54
58 template<typename TYPE>
59 class CFactory {
60
61 public:
65 typedef TYPE* TCreator();
66
70 struct STypeInfo {
72 std::string Author;
73 std::string Version;
74 std::string BriefDescription;
75 std::string LongDescription;
76 std::string Status;
77 };
78
82 typedef std::map<std::string, STypeInfo*> TTypeMap;
83
84 public:
89 static TTypeMap& GetTypeMap();
90
101 static void Register(const std::string& str_label,
102 const std::string& str_author,
103 const std::string& str_version,
104 const std::string& str_brief_desc,
105 const std::string& str_long_desc,
106 const std::string& str_status,
107 TCreator* pc_creator);
113 static TYPE* New(const std::string& str_label);
114
119 static bool Exists(const std::string& str_label);
120
125 static void Print(std::ostream& c_os);
126
130 static void Destroy();
131 };
132
133/*
134 * Include the actual template implementation
135 */
136#include <argos3/core/utility/plugins/factory_impl.h>
137
149#define REGISTER_SYMBOL(BASECLASS, \
150 CLASSNAME, \
151 LABEL, \
152 AUTHOR, \
153 VERSION, \
154 BRIEF_DESCRIPTION, \
155 LONG_DESCRIPTION, \
156 STATUS) \
157 namespace argos { \
158 extern "C" { \
159 BASECLASS* BASECLASS ## CLASSNAME ## Creator() { \
160 return new CLASSNAME; \
161 } \
162 } \
163 class C ## BASECLASS ## CLASSNAME ## Proxy { \
164 public: \
165 C ## BASECLASS ## CLASSNAME ## Proxy() { \
166 CFactory<BASECLASS>:: \
167 Register(LABEL, \
168 AUTHOR, \
169 VERSION, \
170 BRIEF_DESCRIPTION, \
171 LONG_DESCRIPTION, \
172 STATUS, \
173 BASECLASS ## CLASSNAME ## Creator); \
174 } \
175 }; \
176 C ## BASECLASS ## CLASSNAME ## Proxy BASECLASS ## CLASSNAME ## _p; \
177 }
178
179}
180
181#endif
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
Basic factory template.
Definition factory.h:59
static void Print(std::ostream &c_os)
Prints the list of registered labels.
static TYPE * New(const std::string &str_label)
Creates a new object of type TYPE
std::map< std::string, STypeInfo * > TTypeMap
The map of registered TYPEs.
Definition factory.h:82
TYPE * TCreator()
Pointer to the function that creates objects of type TYPE
Definition factory.h:65
static bool Exists(const std::string &str_label)
Returns true if the given label exists in the TYPE map.
static TTypeMap & GetTypeMap()
Creates and returns the TYPE map.
static void Destroy()
Frees up all used memory.
static void Register(const std::string &str_label, const std::string &str_author, const std::string &str_version, const std::string &str_brief_desc, const std::string &str_long_desc, const std::string &str_status, TCreator *pc_creator)
Registers a new TYPE creator in the factory.
A struct containing the information about the registered types.
Definition factory.h:70
std::string BriefDescription
Definition factory.h:74
std::string LongDescription
Definition factory.h:75