Tiny local class to load a PLUMED kernel. More...
#include <PlumedHandle.h>
Classes | |
class | DlHandle |
Automatically dlclosing auxiliary class. More... | |
Public Member Functions | |
PlumedHandle () | |
Default constructor. More... | |
PlumedHandle (PlumedHandle &&)=default | |
Move constructor. More... | |
virtual | ~PlumedHandle () |
Destructor. More... | |
void | cmd (const char *key, const void *ptr=nullptr) |
Execute cmd. More... | |
Static Public Member Functions | |
static PlumedHandle | dlopen (const char *path) |
Construct a PlumedHandle given the path to a kernel. More... | |
Private Member Functions | |
PlumedHandle (const char *path) | |
Constructor using the path to a kernel. More... | |
Private Attributes | |
const plumed_cmd_pointer | cmd_ =nullptr |
Pointer to cmd function. More... | |
const plumed_create_pointer | create_ =nullptr |
Pointer to create function. More... | |
const plumed_finalize_pointer | finalize_ =nullptr |
Pointer to finalize function. More... | |
DlHandle | handle |
Pointer to dlsym handle used to open the kernel. More... | |
std::unique_ptr< PlumedMain > | local |
Pointer to PlumedMain. More... | |
void *const | p =nullptr |
Pointer to the plumed object. More... | |
plumed_symbol_table_type *const | symbol_ =nullptr |
Pointer to symbol table. More... | |
Tiny local class to load a PLUMED kernel.
Maps command to either a loaded PLUMED kernel or to the present one. It is a simplified version of the interface located at wrapper/Plumed.h. Differences are:
PLUMED_KERNEL
env var. Indeed, it would not make sense to use it, since this class is meant to load different kernels.The mechanism for loading the kernel is anyway very similar to the one in wrapper/Plumed.c. In particular, it can load both kernels from PLUMED <=2.4 and >=2.5, and it tries to load the libplumed.so
object if the libplumedKernel.so
object does not load correctly. It can also be created without passing any kernel path. In that case it refers to the current one (the one to which this class belongs).
The following syntax creates a handle referring to the current kernel
PlumedHandle p; // Alternatively: // auto p=PlumedHandle(); p.cmd("init");
The following syntax instead creates a handle referring to a loaded kernel
PlumedHandle p(PlumedHandle::dlopen("/path/to/libplumedkernel.so"); // Alternatively: // auto p=PlumedHandle::dlopen("/path/to/libplumedkernel.so"); p.cmd("init");
Notice that if there are problems loading the kernel an exception is thrown. Thus, once constructed the object is guaranteed to be functional.
|
explicitprivate |
Constructor using the path to a kernel.
I keep it private to avoid confusion wrt the similar constructor of PLMD::Plumed that accepts a string (conversion from FORTRAN).
PLMD::PlumedHandle::PlumedHandle | ( | ) |
Default constructor.
Maps following commands to the current kernel.
|
virtual |
Destructor.
In case a kernel was dlopened, it dlcloses it. I make it virtual for future extensibility, though this is not necessary now.
|
default |
Move constructor.
void PLMD::PlumedHandle::cmd | ( | const char * | key, |
const void * | ptr = nullptr |
||
) |
Execute cmd.
|
static |
Construct a PlumedHandle given the path to a kernel.
It just uses the private constructor PlumedHandle(const char* path).
|
private |
Pointer to cmd function.
Used when kernel is dlopened.
|
private |
Pointer to create function.
Used when kernel is dlopened.
|
private |
Pointer to finalize function.
Used when kernel is dlopened.
|
private |
Pointer to dlsym handle used to open the kernel.
Null when using current kernel.
|
private |
Pointer to PlumedMain.
Used when using the current kernel in order to avoid unneeded indirections.
|
private |
Pointer to the plumed object.
Used when kernel is dlopened.
|
private |
Pointer to symbol table.
Used for kernels>=2.5. We store it here since it is needed in constructor to initialize create_/cmd_/finalize_. Later on we might use the additional version information that it carries.
Hosted by GitHub | 1.8.17 |