Gyoto
GyotoRegister.h
Go to the documentation of this file.
1/*
2 Copyright 2011-2016 Thibaut Paumard
3
4 This file is part of Gyoto.
5
6 Gyoto is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Gyoto is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __GyotoRegister_H_
21#define __GyotoRegister_H_
22
23#include <string>
24#include "GyotoSmartPointer.h"
25
35namespace Gyoto {
44 namespace Register {
45
46 /* Documented below */
47 class Entry;
48
61 void init( char const * pluglist = NULL );
62
66 void list();
67 }
68
88 void * loadPlugin( char const * const plugname, int nofail = 0);
89
95 bool havePlugin(std::string plugname);
96
108 void requirePlugin(std::string plugname, int nofail = 0);
109}
110
122protected:
123 std::string name_;
129 const std::string plugin_;
131public:
135 Entry(std::string name,
137 Entry* next);
139
160 getSubcontractor(std::string name, std::string &plugin, int errmode=0);
161
162};
163
164#define GYOTO_GETSUBCONTRACTOR(space) \
165 Gyoto::space::Subcontractor_t* \
166 Gyoto::space::getSubcontractor(std::string name, std::vector<std::string> &plugin, int errmode) { \
167 for (size_t i=0; i<plugin.size(); ++i) { \
168 GYOTO_DEBUG_EXPR(plugin[i]); \
169 Gyoto::requirePlugin(plugin[i]); \
170 } \
171 if (!Gyoto::space::Register_) throwError("No " GYOTO_STRINGIFY(space) " kind registered!"); \
172 Subcontractor_t* sctr= NULL; \
173 std::string plg(""); \
174 if (!plugin.size()) { \
175 sctr = \
176 (Subcontractor_t*)Gyoto::space::Register_ \
177 -> getSubcontractor(name, plg, errmode); \
178 plugin.push_back(plg); \
179 } \
180 for (size_t i=plugin.size()-1; i>=0 && sctr == NULL; --i) { \
181 sctr= \
182 (Subcontractor_t*)Gyoto::space::Register_ \
183 -> getSubcontractor(name, plugin[i], 1); \
184 } \
185 if (!errmode && !sctr) throwError ("Kind not found in the specified plug-ins: "+name); \
186 return sctr; \
187}
188
189#endif
Reference-counting pointers.
Entry in a register (or a full register)
Definition: GyotoRegister.h:117
const std::string plugin_
Plug-in from which this Entry was loaded.
Definition: GyotoRegister.h:129
std::string name_
Kind name for the entry, as found in the "kind" XML attribute.
Definition: GyotoRegister.h:123
Register::Entry * next_
Next entry in the register, or NULL.
Definition: GyotoRegister.h:127
~Entry()
Destructor.
Gyoto::SmartPointee::Subcontractor_t * getSubcontractor(std::string name, std::string &plugin, int errmode=0)
Get subcontractor for a given name.
Gyoto::SmartPointee::Subcontractor_t * subcontractor_
Pointer to the Gyoto::SmartPointee::Subcontractor_t function that produces an object of this kind.
Definition: GyotoRegister.h:125
Entry(std::string name, Gyoto::SmartPointee::Subcontractor_t *subcontractor, Entry *next)
Constructor.
Gyoto::SmartPointer< Gyoto::SmartPointee > Subcontractor_t(Gyoto::FactoryMessenger *, std::vector< std::string > const &)
A subcontractor builds an object upon order from the Factory.
Definition: GyotoSmartPointer.h:114
void Register(std::string name, Gyoto::Astrobj::Subcontractor_t *scp)
Make an Astrobj kind known to the Factory.
void list()
List the various registers.
void init(char const *pluglist=NULL)
Initialise the various registers.
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:43
void * loadPlugin(char const *const plugname, int nofail=0)
Load a plugin by name.
void requirePlugin(std::string plugname, int nofail=0)
Load a plugin by name, only if not loaded yet.
bool havePlugin(std::string plugname)
Check whether a given plug-in has already been loaded.