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>

Inheritance diagram for PLMD::PlumedHandle:
Inheritance graph
[legend]

Public Member Functions

 PlumedHandle ()
 Default constructor. More...
 
 PlumedHandle (PlumedHandle &&other) noexcept
 Move constructor. More...
 
virtual ~PlumedHandle ()
 Destructor. More...
 
void cmd (const std::string &key, const TypesafePtr &ptr=nullptr)
 Execute cmd. More...
 
void cmd (const std::string &key, const TypesafePtr &val, const std::size_t *shape)
 
void cmd (const std::string &key, const TypesafePtr &val, const std::size_t *shape)
 Bring in the possibility to pass shape/nelem. More...
 
void cmd (const std::string &key, const TypesafePtr &val, std::size_t nelem, const std::size_t *shape=nullptr)
 
void cmd (const std::string &key, const TypesafePtr &val, std::size_t nelem, const std::size_t *shape=nullptr)
 Bring in the possibility to pass shape/nelem. More...
 
virtual void cmd (const std::string &key, const TypesafePtr &val=nullptr)=0
 Bring in the possibility to pass shape/nelem. More...
 
PlumedHandleoperator= (PlumedHandle &&other) noexcept
 Move assignment. 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

void * loaded =nullptr
 Pointer to loaded Plumed object;. More...
 
std::unique_ptr< PlumedMainlocal
 Pointer to PlumedMain. 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 provides a wrapper around the official interface located at wrapper/Plumed.h, with some changes. Differences are:

In its implementation, this class uses the PLMD::Plumed class in wrapper/Plumed.h and thus has the same capability to load PLUMED kernels of any version (starting with 2.0). 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 &&  other)
noexcept

Move constructor.

Member Function Documentation

◆ cmd() [1/6]

void PLMD::PlumedHandle::cmd ( const std::string &  key,
const TypesafePtr ptr = nullptr 
)
virtual

Execute cmd.

Implements PLMD::WithCmd.

◆ cmd() [2/6]

void PLMD::WithCmd::cmd ( const std::string &  key,
const TypesafePtr val,
const std::size_t *  shape 
)
inlineinherited

◆ cmd() [3/6]

void PLMD::WithCmd::cmd
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [4/6]

void PLMD::WithCmd::cmd ( const std::string &  key,
const TypesafePtr val,
std::size_t  nelem,
const std::size_t *  shape = nullptr 
)
inlineinherited

◆ cmd() [5/6]

void PLMD::WithCmd::cmd
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [6/6]

virtual void PLMD::WithCmd::cmd

Bring in the possibility to pass shape/nelem.

◆ 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).

◆ operator=()

PlumedHandle & PLMD::PlumedHandle::operator= ( PlumedHandle &&  other)
noexcept

Move assignment.

Member Data Documentation

◆ loaded

void* PLMD::PlumedHandle::loaded =nullptr
private

Pointer to loaded Plumed object;.

◆ local

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

Pointer to PlumedMain.

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


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