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 char *key, const TypesafePtr &val=nullptr)
 This is needed to avoid ambiguities. More...
 
void cmd (const char *key, const TypesafePtr &val=nullptr)
 Bring in the possibility to pass shape/nelem. More...
 
virtual void cmd (const std::string &key, const TypesafePtr &val=nullptr)
 This is the legacy method we used in older plumed versions, so it is still possible. More...
 
virtual void cmd (const std::string &key, const TypesafePtr &val=nullptr)
 Bring in the possibility to pass shape/nelem. More...
 
void cmd (std::string_view key, const TypesafePtr &ptr) override
 Execute cmd. More...
 
void cmd (std::string_view key, const TypesafePtr &val, const std::size_t *shape)
 
void cmd (std::string_view key, const TypesafePtr &val, const std::size_t *shape)
 Bring in the possibility to pass shape/nelem. More...
 
template<typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void cmd (std::string_view key, const TypesafePtr &val, I nelem, const std::size_t *shape=nullptr)
 
template<typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void cmd (std::string_view key, const TypesafePtr &val, I nelem, const std::size_t *shape=nullptr)
 Bring in the possibility to pass shape/nelem. More...
 
void cmd (std::string_view key, const TypesafePtr &val, std::initializer_list< SizeLike > shape)
 
void cmd (std::string_view key, const TypesafePtr &val, std::initializer_list< SizeLike > shape)
 Bring in the possibility to pass shape/nelem. More...
 
virtual void cmd (std::string_view key, const TypesafePtr &val=nullptr)
 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/12]

void PLMD::WithCmd::cmd ( const char *  key,
const TypesafePtr val = nullptr 
)
inlineinherited

This is needed to avoid ambiguities.

◆ cmd() [2/12]

void PLMD::WithCmd::cmd
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [3/12]

virtual void PLMD::WithCmd::cmd ( const std::string &  key,
const TypesafePtr val = nullptr 
)
inlinevirtualinherited

This is the legacy method we used in older plumed versions, so it is still possible.

If this is not overridden, it will call the preferred method

◆ cmd() [4/12]

virtual void PLMD::WithCmd::cmd
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [5/12]

void PLMD::PlumedHandle::cmd ( std::string_view  key,
const TypesafePtr ptr 
)
overridevirtual

Execute cmd.

Reimplemented from PLMD::WithCmd.

◆ cmd() [6/12]

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

◆ cmd() [7/12]

void PLMD::WithCmd::cmd
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [8/12]

template<typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void PLMD::WithCmd::cmd ( std::string_view  key,
const TypesafePtr val,
nelem,
const std::size_t *  shape = nullptr 
)
inlineinherited

◆ cmd() [9/12]

template<typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void PLMD::WithCmd::cmd ( typename I  ,
typename std::enable_if< std::is_integral< I >::value, int >::type  = 0 
)
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [10/12]

void PLMD::WithCmd::cmd ( std::string_view  key,
const TypesafePtr val,
std::initializer_list< SizeLike shape 
)
inlineinherited

◆ cmd() [11/12]

void PLMD::WithCmd::cmd
inline

Bring in the possibility to pass shape/nelem.

◆ cmd() [12/12]

virtual void PLMD::WithCmd::cmd
inline

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: