| 1 | #cxx . . $ `<file>/ncrystal_core/include/NCrystal/NCPluginMgmt.hh`/ifndef NCrystal_PluginMgmt_hh |
| 2 | #define NCrystal_PluginMgmt_hhcxx . . $ `ncrystal_core/include/NCrystal/NCPluginMgmt.hh:2:9`! |
| 3 | |
| 4 | //////////////////////////////////////////////////////////////////////////////// |
| 5 | // // |
| 6 | // This file is part of NCrystal (see https://mctools.github.io/ncrystal/) // |
| 7 | // // |
| 8 | // Copyright 2015-2022 NCrystal developers // |
| 9 | // // |
| 10 | // Licensed under the Apache License, Version 2.0 (the "License"); // |
| 11 | // you may not use this file except in compliance with the License. // |
| 12 | // You may obtain a copy of the License at // |
| 13 | // // |
| 14 | // http://www.apache.org/licenses/LICENSE-2.0 // |
| 15 | // // |
| 16 | // Unless required by applicable law or agreed to in writing, software // |
| 17 | // distributed under the License is distributed on an "AS IS" BASIS, // |
| 18 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // |
| 19 | // See the License for the specific language governing permissions and // |
| 20 | // limitations under the License. // |
| 21 | // // |
| 22 | //////////////////////////////////////////////////////////////////////////////// |
| 23 | |
| 24 | #include "NCrystal/NCDefs.hh"cxx . . $ `<file>/ncrystal_core/include/NCrystal/NCDefs.hh`/ |
| 25 | |
| 26 | namespace NCrystalcxx . . $ NCrystal/ { |
| 27 | |
| 28 | namespace Pluginscxx . . $ NCrystal/Plugins/ { |
| 29 | // |
| 30 | // The loadDynamicPlugin function attempts to load a plugin by specifying a path to |
| 31 | // a shared library which defines (with C-mangling) two functions: |
| 32 | // |
| 33 | // void ncplugin_register(); |
| 34 | // const char* ncplugin_getname(); |
| 35 | // |
| 36 | // The ncplugin_getname function should simply provide the plugin name |
| 37 | // whenever called. When ncplugin_register is called, the plugin is expected |
| 38 | // to enable itself by calling global NCrystal functions (usually this means |
| 39 | // calling registerFactory(..), but in principle it could also be functions |
| 40 | // registering i/o managers, in-memory file data, or changing the default |
| 41 | // RNG). |
| 42 | // |
| 43 | // The loadBuiltinPlugin does the same, but directly providing the plugin |
| 44 | // name and registration function to call. |
| 45 | // |
| 46 | // Normally the plugin interface is not accessed. Rather, dynamic plugins |
| 47 | // are enabled by adding them to the NCRYSTAL_PLUGIN_LIST environment |
| 48 | // variable, while the loading of builtin plugins is handled by NCrystal's |
| 49 | // cmake configuration. |
| 50 | |
| 51 | // |
| 52 | enum class PluginTypecxx . . $ NCrystal/Plugins/PluginType# { Dynamiccxx . . $ NCrystal/Plugins/PluginType#Dynamic., Builtincxx . . $ NCrystal/Plugins/PluginType#Builtin., Undefinedcxx . . $ NCrystal/Plugins/PluginType#Undefined. }; |
| 53 | struct NCRYSTAL_APIcxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:51:13`! PluginInfocxx . . $ NCrystal/Plugins/PluginInfo# { |
| 54 | //Simple information about loaded plugin. For now this is just the path to |
| 55 | //the library and the pluginname as returned by ncplugin_getname (see |
| 56 | //below). For builtin plugins the fileName will be empty. |
| 57 | stdcxx . . $ std/::stringcxx . . $ std/string# pluginNamecxx . . $ NCrystal/Plugins/PluginInfo#pluginName.; |
| 58 | stdcxx . . $ std/::stringcxx . . $ std/string# fileNamecxx . . $ NCrystal/Plugins/PluginInfo#fileName.; |
| 59 | PluginTypecxx . . $ NCrystal/Plugins/PluginType# pluginTypecxx . . $ NCrystal/Plugins/PluginInfo#pluginType. = PluginTypecxx . . $ NCrystal/Plugins/PluginType#::Undefinedcxx . . $ NCrystal/Plugins/PluginType#Undefined.; |
| 60 | }; |
| 61 | |
| 62 | //Load plugins (returns the resulting plugin info): |
| 63 | NCRYSTAL_APIcxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:51:13`! PluginInfocxx . . $ NCrystal/Plugins/PluginInfo# loadDynamicPlugincxx . . $ NCrystal/Plugins/loadDynamicPlugin(7709f560aff78085).( stdcxx . . $ std/::stringcxx . . $ std/string# path_to_shared_lib ); |
| 64 | NCRYSTAL_APIcxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:51:13`! PluginInfocxx . . $ NCrystal/Plugins/PluginInfo# loadBuiltinPlugincxx . . $ NCrystal/Plugins/loadBuiltinPlugin(eb18c7d7b59de04d).( stdcxx . . $ std/::stringcxx . . $ std/string# pluginName, |
| 65 | stdcxx . . $ std/::functioncxx . . $ std/function#<void()> regfct ); |
| 66 | |
| 67 | //Query loaded plugins: |
| 68 | NCRYSTAL_APIcxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:51:13`! stdcxx . . $ std/::vectorcxx . . $ std/vector#<PluginInfocxx . . $ NCrystal/Plugins/PluginInfo#> loadedPluginscxx . . $ NCrystal/Plugins/loadedPlugins(4b46222f89e65f31).(); |
| 69 | |
| 70 | //Call this to ensure plugins (both builtin and those in |
| 71 | //NCRYSTAL_PLUGIN_LIST) are loaded. Multiple calls to this function will |
| 72 | //have no effect, and it will be called automatically when users query the |
| 73 | //global createXXX(..) functions from NCFactory.hh: |
| 74 | NCRYSTAL_APIcxx . . $ `ncrystal_core/include/NCrystal/ncapi.h:51:13`! void ensurePluginsLoadedcxx . . $ NCrystal/Plugins/ensurePluginsLoaded(49f6e7a06ebc5aa8).(); |
| 75 | |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #endif |