GyotoRegister.h
Go to the documentation of this file.
/*
Copyright 2011-2016 Thibaut Paumard
This file is part of Gyoto.
Gyoto is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gyoto is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GyotoRegister_H_
#define __GyotoRegister_H_
#include <string>
#include "GyotoSmartPointer.h"
namespace Gyoto {
namespace Register {
/* Documented below */
class Entry;
void init( char const * pluglist = NULL );
void list();
}
void * loadPlugin( char const * const plugname, int nofail = 0);
bool havePlugin(std::string plugname);
void requirePlugin(std::string plugname, int nofail = 0);
}
class Gyoto::Register::Entry {
friend void Gyoto::Register::list();
protected:
std::string name_;
Gyoto::SmartPointee::Subcontractor_t* subcontractor_;
Register::Entry* next_;
const std::string plugin_;
public:
Entry(std::string name,
Gyoto::SmartPointee::Subcontractor_t* subcontractor,
Entry* next);
~Entry();
Gyoto::SmartPointee::Subcontractor_t*
getSubcontractor(std::string name, std::string &plugin, int errmode=0);
};
#define GYOTO_GETSUBCONTRACTOR(space) \
Gyoto::space::Subcontractor_t* \
Gyoto::space::getSubcontractor(std::string name, std::vector<std::string> &plugin, int errmode) { \
for (size_t i=0; i<plugin.size(); ++i) { \
GYOTO_DEBUG_EXPR(plugin[i]); \
Gyoto::requirePlugin(plugin[i]); \
} \
if (!Gyoto::space::Register_) throwError("No " GYOTO_STRINGIFY(space) " kind registered!"); \
Subcontractor_t* sctr= NULL; \
std::string plg(""); \
if (!plugin.size()) { \
sctr = \
(Subcontractor_t*)Gyoto::space::Register_ \
-> getSubcontractor(name, plg, errmode); \
plugin.push_back(plg); \
} \
for (size_t i=plugin.size()-1; i>=0 && sctr == NULL; --i) { \
sctr= \
(Subcontractor_t*)Gyoto::space::Register_ \
-> getSubcontractor(name, plugin[i], 1); \
} \
if (!errmode && !sctr) throwError ("Kind not found in the specified plug-ins: "+name); \
return sctr; \
}
#endif
GyotoSmartPointer.h
Reference-counting pointers.
Gyoto::Register::Entry
Entry in a register (or a full register).
Definition GyotoRegister.h:117
Gyoto::Register::Entry::plugin_
const std::string plugin_
Plug-in from which this Entry was loaded.
Definition GyotoRegister.h:129
Gyoto::Register::Entry::name_
std::string name_
Kind name for the entry, as found in the "kind" XML attribute.
Definition GyotoRegister.h:123
Gyoto::Register::Entry::next_
Register::Entry * next_
Next entry in the register, or NULL.
Definition GyotoRegister.h:127
Gyoto::Register::Entry::~Entry
~Entry()
Destructor.
Gyoto::Register::Entry::getSubcontractor
Gyoto::SmartPointee::Subcontractor_t * getSubcontractor(std::string name, std::string &plugin, int errmode=0)
Get subcontractor for a given name.
Gyoto::Register::Entry::subcontractor_
Gyoto::SmartPointee::Subcontractor_t * subcontractor_
Pointer to the Gyoto::SmartPointee::Subcontractor_t function that produces an object of this kind.
Definition GyotoRegister.h:125
Gyoto::Register::Entry::Entry
Entry(std::string name, Gyoto::SmartPointee::Subcontractor_t *subcontractor, Entry *next)
Constructor.
Gyoto::SmartPointee::Subcontractor_t
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
Gyoto::Register
Gyoto registers.
Definition GyotoAstrobj.h:46
Gyoto::Register::list
void list()
List the various registers.
Gyoto::Register::init
void init(char const *pluglist=NULL)
Initialise the various registers.
Gyoto
Namespace for the Gyoto library.
Definition GyotoAstrobj.h:44
Gyoto::loadPlugin
void * loadPlugin(char const *const plugname, int nofail=0)
Load a plugin by name.
Gyoto::requirePlugin
void requirePlugin(std::string plugname, int nofail=0)
Load a plugin by name, only if not loaded yet.
Gyoto::havePlugin
bool havePlugin(std::string plugname)
Check whether a given plug-in has already been loaded.