Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
PLMD::PlumedHandle Class Reference


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< PlumedMainlocal
 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...
 

Detailed Description


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:

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.

Constructor & Destructor Documentation

◆ PlumedHandle() [1/3]

PLMD::PlumedHandle::PlumedHandle ( const char *  path)
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).

◆ PlumedHandle() [2/3]

PLMD::PlumedHandle::PlumedHandle ( )

Default constructor.

Maps following commands to the current kernel.

◆ ~PlumedHandle()

PLMD::PlumedHandle::~PlumedHandle ( )
virtual

Destructor.

In case a kernel was dlopened, it dlcloses it. I make it virtual for future extensibility, though this is not necessary now.

◆ PlumedHandle() [3/3]

PLMD::PlumedHandle::PlumedHandle ( PlumedHandle &&  )
default

Move constructor.

Member Function Documentation

◆ cmd()

void PLMD::PlumedHandle::cmd ( const char *  key,
const void *  ptr = nullptr 
)

Execute cmd.

◆ dlopen()

PlumedHandle PLMD::PlumedHandle::dlopen ( const char *  path)
static

Construct a PlumedHandle given the path to a kernel.

It just uses the private constructor PlumedHandle(const char* path).

Member Data Documentation

◆ cmd_

const plumed_cmd_pointer PLMD::PlumedHandle::cmd_ =nullptr
private

Pointer to cmd function.

Used when kernel is dlopened.

◆ create_

const plumed_create_pointer PLMD::PlumedHandle::create_ =nullptr
private

Pointer to create function.

Used when kernel is dlopened.

◆ finalize_

const plumed_finalize_pointer PLMD::PlumedHandle::finalize_ =nullptr
private

Pointer to finalize function.

Used when kernel is dlopened.

◆ handle

DlHandle PLMD::PlumedHandle::handle
private

Pointer to dlsym handle used to open the kernel.

Null when using current kernel.

◆ local

std::unique_ptr<PlumedMain> PLMD::PlumedHandle::local
private

Pointer to PlumedMain.

Used when using the current kernel in order to avoid unneeded indirections.

◆ p

void* const PLMD::PlumedHandle::p =nullptr
private

Pointer to the plumed object.

Used when kernel is dlopened.

◆ symbol_

plumed_symbol_table_type* const PLMD::PlumedHandle::symbol_ =nullptr
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.


The documentation for this class was generated from the following files: