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 
35 namespace 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 
83  void loadPlugin( char const * const plugname, int nofail = 0);
84  bool havePlugin(std::string plugname);
85  void requirePlugin(std::string plugname, int nofail = 0);
86 }
87 
98  friend void Gyoto::Register::list();
99 protected:
100  std::string name_;
106  const std::string plugin_;
108 public:
112  Entry(std::string name,
114  Entry* next);
115  ~Entry();
116 
137  getSubcontractor(std::string name, std::string &plugin, int errmode=0);
138 
139 };
140 
141 #define GYOTO_GETSUBCONTRACTOR(space) \
142  Gyoto::space::Subcontractor_t* \
143  Gyoto::space::getSubcontractor(std::string name, std::vector<std::string> &plugin, int errmode) { \
144  for (size_t i=0; i<plugin.size(); ++i) { \
145  GYOTO_DEBUG_EXPR(plugin[i]); \
146  Gyoto::requirePlugin(plugin[i]); \
147  } \
148  if (!Gyoto::space::Register_) throwError("No " GYOTO_STRINGIFY(space) " kind registered!"); \
149  Subcontractor_t* sctr= NULL; \
150  std::string plg(""); \
151  if (!plugin.size()) { \
152  sctr = \
153  (Subcontractor_t*)Gyoto::space::Register_ \
154  -> getSubcontractor(name, plg, errmode); \
155  plugin.push_back(plg); \
156  } \
157  for (size_t i=plugin.size()-1; i>=0 && sctr == NULL; --i) { \
158  sctr= \
159  (Subcontractor_t*)Gyoto::space::Register_ \
160  -> getSubcontractor(name, plugin[i], 1); \
161  } \
162  if (!errmode && !sctr) throwError ("Kind not found in the specified plug-ins: "+name); \
163  return sctr; \
164 }
165 
166 #endif
Entry(std::string name, Gyoto::SmartPointee::Subcontractor_t *subcontractor, Entry *next)
Constructor.
Gyoto::SmartPointee::Subcontractor_t * getSubcontractor(std::string name, std::string &plugin, int errmode=0)
Get subcontractor for a given name.
std::string name_
Kind name for the entry, as found in the "kind" XML attribute.
Definition: GyotoRegister.h:100
Reference-counting pointers.
void Register(std::string name, Gyoto::Astrobj::Subcontractor_t *scp)
Make an Astrobj kind known to the Factory.
void init(char const *pluglist=NULL)
Initialise the various registers.
void list()
List the various registers.
void loadPlugin(char const *const plugname, int nofail=0)
Load a plugin by name.
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
Register::Entry * next_
Next entry in the register, or NULL.
Definition: GyotoRegister.h:104
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:43
~Entry()
Destructor.
const std::string plugin_
Plug-in from which this Entry was loaded.
Definition: GyotoRegister.h:106
Gyoto::SmartPointee::Subcontractor_t * subcontractor_
Pointer to the Gyoto::SmartPointee::Subcontractor_t function that produces an object of this kind...
Definition: GyotoRegister.h:102
Entry in a register (or a full register)
Definition: GyotoRegister.h:94