20 #ifndef __GyotoRegister_H_ 21 #define __GyotoRegister_H_ 65 void init(
char const * pluglist = NULL );
92 void *
loadPlugin(
char const *
const plugname,
int nofail = 0);
122 void pluginPath(
const std::vector<std::string> &v);
247 #define GYOTO_GETSUBCONTRACTOR(space) \ 248 Gyoto::space::Subcontractor_t* \ 249 Gyoto::space::getSubcontractor(std::string name, \ 250 std::vector<std::string> &plugin, \ 252 std::vector<std::string> mandatory; \ 253 std::vector<std::string> fallback; \ 254 std::vector<std::string> plug_path(Gyoto::pluginPath()); \ 255 GYOTO_DEBUG << "loading non-fallback plug-ins..." << std::endl; \ 256 for (const auto &plg : plugin) { \ 257 GYOTO_DEBUG_EXPR(plg); \ 258 if (plg.rfind("fallback:", 0) != 0) { \ 259 Gyoto::requirePlugin(plg); \ 260 mandatory.emplace_back(plg); \ 262 else fallback.emplace_back(plg.substr(9)); \ 264 GYOTO_DEBUG << "found " << mandatory.size() \ 265 << " mandatory plg-ins and "<< fallback.size() \ 266 << " fallback plug-ins" << std::endl; \ 268 "loading fallback plug-ins until the Register is not empty" \ 270 for (const auto plg : fallback) { \ 271 if (Gyoto::space::Register_) break; \ 272 GYOTO_DEBUG_EXPR(plg); \ 273 Gyoto::requirePlugin(plg, 2); \ 275 for (const auto &plg : fallback) { \ 276 if (Gyoto::space::Register_) break; \ 277 GYOTO_DEBUG_EXPR(plg); \ 278 for (const auto &path : plug_path) { \ 279 std::string pattern = (path + "libgyoto-" + plg) \ 280 + "." GYOTO_PLUGIN_SFX; \ 281 std::vector<std::string> files = \ 282 Gyoto::glob(pattern); \ 283 for (const auto &file : files) { \ 284 GYOTO_DEBUG << "Trying " << file << std::endl; \ 285 Gyoto::requirePlugin(file, 2); \ 289 if (!Gyoto::space::Register_) \ 290 throwError("No " GYOTO_STRINGIFY(space) " kind registered!"); \ 291 Gyoto::space::Subcontractor_t* sctr= NULL; \ 292 GYOTO_DEBUG << "looking for " << name \ 293 << " in non-fallback plug-ins..." << std::endl; \ 294 for (auto & plg : mandatory) { \ 295 GYOTO_DEBUG_EXPR(plg); \ 296 sctr=(Gyoto::space::Subcontractor_t*)Gyoto::space::Register_ \ 297 -> getSubcontractor(name, plg, 2); \ 299 GYOTO_DEBUG << "found " << name << " in plug-in " \ 300 << plg << std::endl; \ 304 if (!mandatory.size()) { \ 305 GYOTO_DEBUG << "looking for " << name \ 306 << " in registered plug-ins..." << std::endl; \ 307 std::string plg(""); \ 308 sctr = (Gyoto::space::Subcontractor_t*)Gyoto::space::Register_ \ 309 -> getSubcontractor(name, plg, 2); \ 311 GYOTO_DEBUG << "found " << name << " in plug-in " \ 312 << plg << std::endl; \ 313 plugin.emplace(plugin.begin(), plg); \ 314 GYOTO_DEBUG << "added '" << plugin[0] \ 315 << "' as item 0 of pluglist" << std::endl; \ 317 } else if (!fallback.size() && !errmode) \ 318 throwError ("Kind not found in any plug-in: "+name); \ 320 GYOTO_DEBUG << "looking for " << name \ 321 << " in fallback plug-ins..." << std::endl; \ 323 for (auto &plg : fallback) { \ 324 GYOTO_DEBUG_EXPR(plg); \ 325 Gyoto::requirePlugin(plg, 2); \ 326 sctr = (Gyoto::space::Subcontractor_t*)Gyoto::space::Register_ \ 327 -> getSubcontractor(name, plg, 2); \ 329 GYOTO_DEBUG << "found " << name << " in plug-in " \ 330 << plg << std::endl; \ 334 GYOTO_DEBUG << "looking for " << name \ 335 << " in fallback plug-ins, " \ 336 << "allowing for glob expansion..." << std::endl; \ 337 for (const auto &plg : fallback) { \ 340 GYOTO_DEBUG_EXPR(plg); \ 341 std::vector<std::string> files = Gyoto::glob(plg); \ 342 for (auto &file : files) { \ 343 GYOTO_DEBUG << "Trying " << file << std::endl; \ 344 if (!std::filesystem::exists(file)) continue; \ 345 Gyoto::requirePlugin(file, 2); \ 346 sctr = (Gyoto::space::Subcontractor_t*)Gyoto::space::Register_ \ 347 -> getSubcontractor(name, file, 2); \ 349 GYOTO_DEBUG << "found " << name << " in plug-in " \ 350 << file << std::endl; \ 356 for (const auto &path : plug_path) { \ 357 std::string pattern = (path + "libgyoto-" + plg) \ 358 + "." GYOTO_PLUGIN_SFX; \ 359 files = Gyoto::glob(pattern); \ 360 for (auto &file : files) { \ 361 GYOTO_DEBUG << "Trying " << file << std::endl; \ 362 if (!std::filesystem::exists(file)) continue; \ 363 Gyoto::requirePlugin(file, 2); \ 364 sctr=(Gyoto::space::Subcontractor_t*)Gyoto::space::Register_ \ 365 -> getSubcontractor(name, file, 2); \ 367 GYOTO_DEBUG << "found " << name << " in plug-in " \ 368 << file << std::endl; \ 374 GYOTO_DEBUG << name << " not found anywhere, error?" \ 377 throwError("Kind not found in the specified plug-ins: "+name); \ void * loadPlugin(char const *const plugname, int nofail=0)
Load a plugin by name.
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:138
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.
std::string plugin()
Get plugin.
void list()
List the various registers.
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:115
Register::Entry * next_
Next entry in the register, or NULL.
Definition: GyotoRegister.h:142
Namespace for the Gyoto library.
Definition: GyotoAstrobj.h:46
std::string name()
Get name.
const std::string plugin_
Plug-in from which this Entry was loaded.
Definition: GyotoRegister.h:144
std::vector< std::string > pluginPath()
Get a copy of the plug-in path.
Gyoto::SmartPointee::Subcontractor_t * subcontractor_
Pointer to the Gyoto::SmartPointee::Subcontractor_t function that produces an object of this kind...
Definition: GyotoRegister.h:140
bool havePlugin(std::string plugname)
Check whether a given plug-in has already been loaded.
void requirePlugin(std::string plugname, int nofail=0)
Load a plugin by name, only if not loaded yet.
Register::Entry * next()
Get next.
Entry in a register (or a full register)
Definition: GyotoRegister.h:132