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

C++ wrapper for plumed. More...

#include <Plumed.h>

Classes

class  add_buffer_to
 
class  CString
 
class  Exception
 Base class used to rethrow PLUMED exceptions. More...
 
class  ExceptionDebug
 Used to rethrow a PLMD::ExceptionDebug. More...
 
class  ExceptionError
 Used to rethrow a PLMD::ExceptionError. More...
 
class  ExceptionTypeError
 Thrown when a wrong pointer is passed to the PLUMED interface. More...
 
class  finalize_plumed_error
 Internal class to simplify plumed_error finalization. More...
 
class  Invalid
 Thrown when trying to access an invalid plumed object. More...
 
class  LeptonException
 Class used to rethrow Lepton exceptions. More...
 
class  rethrow_nested
 Internal class used by exception_dispatch. More...
 
class  rethrow_not_nested
 Internal class used by exception_dispatch. More...
 
class  SafePtr
 Small class that wraps plumed_safeptr in order to make its initialization easier. More...
 
struct  SizeLike
 Small structure used to pass elements of a shape initializer_list. More...
 

Public Member Functions

 Plumed () noexcept
 Constructor. More...
 
 Plumed (const char *c) noexcept
 Clone a Plumed object from a FORTRAN char* handler. More...
 
 Plumed (const Plumed &p) noexcept
 Copy constructor. More...
 
 Plumed (Plumed &&p) noexcept
 Move constructor. More...
 
 Plumed (plumed p) noexcept
 Clone a Plumed object from a C plumed structure. More...
 
 Plumed (void *v) noexcept
 Create a reference from a void* pointer. More...
 
virtual ~Plumed () noexcept
 Destructor. More...
 
template<typename Key >
void cmd (Key &&key)
 Send a command to this plumed object. More...
 
template<typename Key , typename T >
void cmd (Key &&key, T &&val)
 Send a command to this plumed object. More...
 
template<typename Key , typename T >
void cmd (Key &&key, T *val, __PLUMED_WRAPPER_STD size_t *shape)
 Send a command to this plumed object. More...
 
template<typename Key , typename T , typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void cmd (Key &&key, T *val, I nelem)
 Send a command to this plumed object. More...
 
template<typename Key , typename T >
void cmd (Key &&key, T *val, std::initializer_list< SizeLike > shape)
 Send a command to this plumed object. More...
 
Plumeddecref () noexcept
 Decrease reference counter. More...
 
Plumedincref () noexcept
 Increase reference counter. More...
 
 operator bool () const noexcept
 Same as valid(). More...
 
 operator plumed () const noexcept
 Retrieve the C plumed structure for this object. More...
 
Plumedoperator= (const Plumed &p) noexcept
 Assignment operator. More...
 
Plumedoperator= (Plumed &&p) noexcept
 Move assignment. More...
 
void toFortran (char *c) const noexcept
 Retrieve a FORTRAN handler for this object. More...
 
void * toVoid () const noexcept
 Retrieve a void* handler for this object. More...
 
int useCount () const noexcept
 Returns the number of references to this object. More...
 
bool valid () const noexcept
 Check if Plumed object is valid. More...
 

Static Public Member Functions

static Plumed dlopen (const char *path) noexcept
 Create a PLUMED object loading a specific kernel. More...
 
static Plumed dlopen (const char *path, int mode) noexcept
 Create a PLUMED object loading a specific kernel. More...
 
static Plumed dlsym (void *dlhandle) noexcept
 Create a PLUMED object loading from an already opened shared library. More...
 
static void gcmd (const char *key)
 Send a command to global-plumed. More...
 
template<typename T >
static void gcmd (const char *key, T &&val)
 Send a command to global-plumed. More...
 
template<typename T , typename M >
static void gcmd (const char *key, T *val, M &&more)
 Send a command to global-plumed. More...
 
template<typename T >
static void gcmd (const char *key, T *val, std::initializer_list< SizeLike > shape)
 Send a command to global-plumed. More...
 
static void gcreate () noexcept
 Initialize global-plumed. More...
 
static void gfinalize () noexcept
 Finalize global-plumed. More...
 
static bool ginitialized () noexcept
 Check if global-plumed has been initialized. More...
 
static Plumed global () noexcept
 Returns the Plumed global object. More...
 
static bool gvalid () noexcept
 Check if global-plumed is valid. More...
 
static bool installed () noexcept
 Check if plumed is installed (for runtime binding) More...
 
static Plumed makeInvalid () noexcept
 Invalid constructor. More...
 
static Plumed makeValid () noexcept
 Create a valid PLMD::Plumed object. More...
 
static void plumed_cmd_cxx (plumed p, const char *key, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
template<typename T >
static void plumed_cmd_cxx (plumed p, const char *key, T *val, __PLUMED_WRAPPER_STD size_t nelem, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
template<typename T >
static void plumed_cmd_cxx (plumed p, const char *key, T *val, const __PLUMED_WRAPPER_STD size_t *shape, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
template<typename T >
static void plumed_cmd_cxx (plumed p, const char *key, T *val, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
template<typename T >
static void plumed_cmd_cxx (plumed p, const char *key, T val, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
static __PLUMED_WRAPPER_CXX_NORETURN void plumed_error_rethrow_cxx (plumed_error h)
 
template<typename T >
static void plumed_gcmd_cxx (const char *key, T val, __PLUMED_WRAPPER_STD size_t nelem, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
template<typename T >
static void plumed_gcmd_cxx (const char *key, T val, const __PLUMED_WRAPPER_STD size_t *shape, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 
template<typename T >
static void plumed_gcmd_cxx (const char *key, T val, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 

Private Member Functions

std::array< std::size_t, 5 > append_size (std::size_t *shape, std::size_t newindex)
 Internal utility to append a shape. More...
 
template<typename Key , typename T , typename std::enable_if< wrapper::is_custom_array< typename std::remove_reference< T >::type >::value, int >::type = 0>
void cmd_helper (Key &&key, T &&val)
 Helper functions for interpreting commands. More...
 
template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< typename std::remove_reference< T >::type >::value &&wrapper::has_size_and_data< T >::value, int >::type = 0>
void cmd_helper (Key &&key, T &&val)
 cmd_helper with size/data val (typically, std::vector, std::string, small_vector, etc) temporaries are detected and the information is propragated More...
 
template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< typename std::remove_reference< T >::type >::value &&!wrapper::has_size_and_data< T >::value &&std::is_pointer< typename std::remove_reference< T >::type >::value, int >::type = 0>
void cmd_helper (Key &&key, T &&val)
 cmd_helper with raw pointer val temporaries are not detected. More...
 
template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< typename std::remove_reference< T >::type >::value &&!wrapper::has_size_and_data< T >::value &&!std::is_pointer< typename std::remove_reference< T >::type >::value, int >::type = 0>
void cmd_helper (Key &&key, T &&val)
 cmd_helper in remaining cases, that is when val is passed by value temporaries are not detected. More...
 
template<typename Key , typename T , typename std::enable_if< wrapper::is_custom_array< T >::value, int >::type = 0>
void cmd_helper_with_shape (Key &&key, T *val, __PLUMED_WRAPPER_STD size_t *shape, bool nocopy=false)
 cmd_helper_with_shape with custom array val (includes std::array and C arrays) nocopy information is propagated More...
 
template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< T >::value, int >::type = 0>
void cmd_helper_with_shape (Key &&key, T *val, __PLUMED_WRAPPER_STD size_t *shape, bool nocopy=false)
 cmd_helper_with_shape with pointer to simple type val. More...
 
template<typename Key , typename T , typename std::enable_if< wrapper::is_custom_array< T >::value, int >::type = 0>
void cmd_with_nelem (Key &&key, T *val, __PLUMED_WRAPPER_STD size_t nelem)
 cmd_helper_with_nelem with custom array val (includes std::array) this helper is only used for backward compatibility, so it does not need to take into account the copyability of the pointer More...
 
template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< T >::value, int >::type = 0>
void cmd_with_nelem (Key &&key, T *val, __PLUMED_WRAPPER_STD size_t nelem)
 cmd_helper_with_nelem with pointer to simple type val. More...
 
std::array< std::size_t, 5 > make_shape (std::initializer_list< SizeLike > shape)
 Internal tool to convert initializer_list to shape This is just taking an initializer list and making a std::array. More...
 

Static Private Member Functions

static void cmd_priv (plumed main, const char *key, SafePtr &safe, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 Private version of cmd. More...
 
template<typename F >
static __PLUMED_WRAPPER_CXX_NORETURN void exception_dispatch (plumed_error &h, F f)
 This is an internal utility to dispatch exceptions based on the plumed_error object. More...
 
static __PLUMED_WRAPPER_CXX_NORETURN void rethrow ()
 Rethrow the current exception. More...
 
static __PLUMED_WRAPPER_CXX_NORETURN void rethrow (plumed_error &h)
 Recursive function that rethrows an exception with all the nested ones. More...
 

Private Attributes

plumed main
 C structure. More...
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const Plumed &a, const Plumed &b) noexcept
 
bool operator< (const Plumed &a, const Plumed &b) noexcept
 
bool operator<= (const Plumed &a, const Plumed &b) noexcept
 
bool operator== (const Plumed &a, const Plumed &b) noexcept
 
bool operator> (const Plumed &a, const Plumed &b) noexcept
 
bool operator>= (const Plumed &a, const Plumed &b) noexcept
 
static void plumed_gcmd_cxx (const char *key, plumed_error *error=__PLUMED_WRAPPER_CXX_NULLPTR)
 These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception. More...
 

Detailed Description

C++ wrapper for plumed.

This class provides a C++ interface to PLUMED. It only containts a plumed object, but wraps it with a number of useful methods. All methods are inlined so as to avoid the compilation of an extra c++ file.

Constructor & Destructor Documentation

◆ Plumed() [1/6]

PLMD::Plumed::Plumed ( )
inlinenoexcept

Constructor.

Notice that when using runtime binding the constructed object might be invalid. One might check it using the valid() method.

Note
Performs the same task a plumed_create()

◆ Plumed() [2/6]

PLMD::Plumed::Plumed ( const char *  c)
inlineexplicitnoexcept

Clone a Plumed object from a FORTRAN char* handler.

Parameters
cThe FORTRAN handler (a char[32]).

The reference counter for the corresponding object will be increased to make sure that the object will be available after plumed_f_finalize is called if the created object is still in scope.

◆ Plumed() [3/6]

PLMD::Plumed::Plumed ( void *  v)
inlineexplicitnoexcept

Create a reference from a void* pointer.

Available as of PLUMED 2.5.

◆ Plumed() [4/6]

PLMD::Plumed::Plumed ( plumed  p)
inlineexplicitnoexcept

Clone a Plumed object from a C plumed structure.

Parameters
pThe C plumed structure.

The reference counter for the corresponding object will be increased to make sure that the object will be available after plumed_finalize is called if the created object is still in scope.

◆ Plumed() [5/6]

PLMD::Plumed::Plumed ( const Plumed p)
inlinenoexcept

Copy constructor.

Takes a reference, incrementing the reference counter of the corresponding object.

◆ Plumed() [6/6]

PLMD::Plumed::Plumed ( Plumed &&  p)
inlinenoexcept

Move constructor.

Available as of PLUMED 2.5. Only if move semantics is enabled.

◆ ~Plumed()

virtual PLMD::Plumed::~Plumed ( )
inlinevirtualnoexcept

Destructor.

It calls plumed_finalize(). Notice that this is done also if the constructor failed (that is, if it returned an invalid object). This allows declaring Plumed objects also if PLUMED is actually not available, provided one does not use the cmd method.

Destructor is virtual so as to allow correct inheritance from Plumed object.

Member Function Documentation

◆ append_size()

std::array<std::size_t,5> PLMD::Plumed::append_size ( std::size_t *  shape,
std::size_t  newindex 
)
inlineprivate

Internal utility to append a shape.

Create a new shape where newindex has been appended to the last non zero element.

◆ cmd() [1/5]

template<typename Key >
void PLMD::Plumed::cmd ( Key &&  key)
inline

Send a command to this plumed object.

Parameters
keyThe name of the command to be executed
Note
Similar to plumed_cmd(). It actually called plumed_cmd_nothrow() and rethrow any exception raised within PLUMED.

◆ cmd() [2/5]

template<typename Key , typename T >
void PLMD::Plumed::cmd ( Key &&  key,
T &&  val 
)
inline

Send a command to this plumed object.

Parameters
keyThe name of the command to be executed
valThe argument.

◆ cmd() [3/5]

template<typename Key , typename T >
void PLMD::Plumed::cmd ( Key &&  key,
T *  val,
__PLUMED_WRAPPER_STD size_t *  shape 
)
inline

Send a command to this plumed object.

Parameters
keyThe name of the command to be executed
valThe argument.
Note
This overload accepts a pointer and corresponding shape information. Shape is passed a size_t pointer, but the overload accepting an initializer_list has a more friendly syntax.

◆ cmd() [4/5]

template<typename Key , typename T , typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void PLMD::Plumed::cmd ( Key &&  key,
T *  val,
nelem 
)
inline

Send a command to this plumed object.

Parameters
keyThe name of the command to be executed
valThe argument.
Note
This overload accepts a pointer and corresponding size information. It's usage is discouraged: the overload accepting shape information should be preferred.

◆ cmd() [5/5]

template<typename Key , typename T >
void PLMD::Plumed::cmd ( Key &&  key,
T *  val,
std::initializer_list< SizeLike shape 
)
inline

Send a command to this plumed object.

Parameters
keyThe name of the command to be executed
valThe argument.
Note
This overload accepts a pointer and corresponding shape information. Shape is passed a size_t pointer, but the overload accepting an initializer_list has a more friendly syntax.

◆ cmd_helper() [1/4]

template<typename Key , typename T , typename std::enable_if< wrapper::is_custom_array< typename std::remove_reference< T >::type >::value, int >::type = 0>
void PLMD::Plumed::cmd_helper ( Key &&  key,
T &&  val 
)
inlineprivate

Helper functions for interpreting commands.

They are all internals. cmd_helper is called when we have no shape information associated. cmd_helper_with_shape is called when we have shape information associated. cmd_helper_with_nelem is called when we have size information associated. The nocopy bool tells us if this pointer is pointing to a temporary variable, it is propagated by the cmd_helper_with_shape version It makes sure PLUMED will not keep a copy. The variants below change for the type of the val argument There is a chain of SFINAE conditions. This would be better implement with if constexpr, but we avoid doing so to keep this compatible with C++11. cmd_helper with custom array val (includes std::array) temporaries are detected and the information is propragated

◆ cmd_helper() [2/4]

template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< typename std::remove_reference< T >::type >::value &&wrapper::has_size_and_data< T >::value, int >::type = 0>
void PLMD::Plumed::cmd_helper ( Key &&  key,
T &&  val 
)
inlineprivate

cmd_helper with size/data val (typically, std::vector, std::string, small_vector, etc) temporaries are detected and the information is propragated

◆ cmd_helper() [3/4]

template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< typename std::remove_reference< T >::type >::value &&!wrapper::has_size_and_data< T >::value &&std::is_pointer< typename std::remove_reference< T >::type >::value, int >::type = 0>
void PLMD::Plumed::cmd_helper ( Key &&  key,
T &&  val 
)
inlineprivate

cmd_helper with raw pointer val temporaries are not detected.

We can indeed save the pointer, even if it's a temporary as it is in the case cmd("a",&a) here we use std::remove_reference to detect properly pointers to arrays

◆ cmd_helper() [4/4]

template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< typename std::remove_reference< T >::type >::value &&!wrapper::has_size_and_data< T >::value &&!std::is_pointer< typename std::remove_reference< T >::type >::value, int >::type = 0>
void PLMD::Plumed::cmd_helper ( Key &&  key,
T &&  val 
)
inlineprivate

cmd_helper in remaining cases, that is when val is passed by value temporaries are not detected.

However, the argument is passed by value and its address is not copyable anyway

◆ cmd_helper_with_shape() [1/2]

template<typename Key , typename T , typename std::enable_if< wrapper::is_custom_array< T >::value, int >::type = 0>
void PLMD::Plumed::cmd_helper_with_shape ( Key &&  key,
T *  val,
__PLUMED_WRAPPER_STD size_t *  shape,
bool  nocopy = false 
)
inlineprivate

cmd_helper_with_shape with custom array val (includes std::array and C arrays) nocopy information is propagated

◆ cmd_helper_with_shape() [2/2]

template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< T >::value, int >::type = 0>
void PLMD::Plumed::cmd_helper_with_shape ( Key &&  key,
T *  val,
__PLUMED_WRAPPER_STD size_t *  shape,
bool  nocopy = false 
)
inlineprivate

cmd_helper_with_shape with pointer to simple type val.

nocopy information is used to pass the proper flags to plumed

◆ cmd_priv()

static void PLMD::Plumed::cmd_priv ( plumed  main,
const char *  key,
SafePtr safe,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestaticprivate

Private version of cmd.

It is used here to avoid duplication of code between typesafe and not-typesafe versions

◆ cmd_with_nelem() [1/2]

template<typename Key , typename T , typename std::enable_if< wrapper::is_custom_array< T >::value, int >::type = 0>
void PLMD::Plumed::cmd_with_nelem ( Key &&  key,
T *  val,
__PLUMED_WRAPPER_STD size_t  nelem 
)
inlineprivate

cmd_helper_with_nelem with custom array val (includes std::array) this helper is only used for backward compatibility, so it does not need to take into account the copyability of the pointer

◆ cmd_with_nelem() [2/2]

template<typename Key , typename T , typename std::enable_if<!wrapper::is_custom_array< T >::value, int >::type = 0>
void PLMD::Plumed::cmd_with_nelem ( Key &&  key,
T *  val,
__PLUMED_WRAPPER_STD size_t  nelem 
)
inlineprivate

cmd_helper_with_nelem with pointer to simple type val.

this helper is only used for backward compatibility, so it does not need to take into account the copyability of the pointer

◆ decref()

Plumed& PLMD::Plumed::decref ( )
inlinenoexcept

Decrease reference counter.

Available as of PLUMED 2.5.

Using this method improperly might interfere with correct object construction and destruction. If you want to play with this, also try to compile using -D__PLUMED_WRAPPER_DEBUG_REFCOUNT=1 and see what happens.

◆ dlopen() [1/2]

static Plumed PLMD::Plumed::dlopen ( const char *  path)
inlinestaticnoexcept

Create a PLUMED object loading a specific kernel.

Available as of PLUMED 2.5.

It returns an object created with plumed_create_dlopen. The object is owned and is then finalized in the destructor. It can be used as follows:

  PLMD::Plumed p = PLMD::Plumed::dlopen("/path/to/libplumedKernel.so");
// or, equivalenty:
//    PLMD::Plumed p(PLMD::Plumed::dlopen("/path/to/libplumedKernel.so"));
  p.cmd("init");

or, equivalently, as

  auto p = PLMD::Plumed::dlopen("/path/to/libplumedKernel.so");
  p.cmd("init");

◆ dlopen() [2/2]

static Plumed PLMD::Plumed::dlopen ( const char *  path,
int  mode 
)
inlinestaticnoexcept

Create a PLUMED object loading a specific kernel.

Available as of PLUMED 2.5.

Same as dlopen(const char* path), but allows a dlopen mode to be chosen explicitly.

◆ dlsym()

static Plumed PLMD::Plumed::dlsym ( void *  dlhandle)
inlinestaticnoexcept

Create a PLUMED object loading from an already opened shared library.

Available as of PLUMED 2.8.

Same as dlopen(const char* path), but searches functions in an already loaded library. See plumed_create_dlsym.

◆ exception_dispatch()

template<typename F >
static __PLUMED_WRAPPER_CXX_NORETURN void PLMD::Plumed::exception_dispatch ( plumed_error h,
f 
)
inlinestaticprivate

This is an internal utility to dispatch exceptions based on the plumed_error object.

It takes information about the exception to be thrown by the passed h object and use it to call function f() on the resulting exception. Notice that:

  • this function does not consider if the error is nested.
  • f should be a callable object, so that it can store information
  • f operator() should be a template function so as to act based on the type of its argument

New exceptions added here should be kept in sync with core/PlumedMainInitializer.cpp

Notice that this function also finalizes in place plumed_error h, so as to avoid memory leaks.

◆ gcmd() [1/4]

static void PLMD::Plumed::gcmd ( const char *  key)
inlinestatic

Send a command to global-plumed.

Parameters
keyThe name of the command to be executed
Note
Equivalent to plumed_gcmd()

◆ gcmd() [2/4]

template<typename T >
static void PLMD::Plumed::gcmd ( const char *  key,
T &&  val 
)
inlinestatic

Send a command to global-plumed.

◆ gcmd() [3/4]

template<typename T , typename M >
static void PLMD::Plumed::gcmd ( const char *  key,
T *  val,
M &&  more 
)
inlinestatic

Send a command to global-plumed.

This version detects passing size or shape as a pointer.

◆ gcmd() [4/4]

template<typename T >
static void PLMD::Plumed::gcmd ( const char *  key,
T *  val,
std::initializer_list< SizeLike shape 
)
inlinestatic

Send a command to global-plumed.

This version detects passing shape as an initializer_list.

◆ gcreate()

static void PLMD::Plumed::gcreate ( )
inlinestaticnoexcept

Initialize global-plumed.

Warning
Using the global objects in C++ is not recommended since they are difficult to use in an exception safe manner. In particular, one should explicitly catch exceptions to properly call gfinalize()
Note
Equivalent to plumed_gcreate()

◆ gfinalize()

static void PLMD::Plumed::gfinalize ( )
inlinestaticnoexcept

Finalize global-plumed.

◆ ginitialized()

static bool PLMD::Plumed::ginitialized ( )
inlinestaticnoexcept

Check if global-plumed has been initialized.

Returns
true if global plumed object (see global()) is initialized (i.e. if gcreate() has been called), false otherwise.
Note
Equivalent to plumed_ginitialized() but returns a bool

◆ global()

static Plumed PLMD::Plumed::global ( )
inlinestaticnoexcept

Returns the Plumed global object.

Notice that the object is copied, thus increasing the reference counter of the global object. In this manner, the global object will survive after a call to gfinalize() if the resulting object is still in scope.

Returns
The Plumed global object

◆ gvalid()

static bool PLMD::Plumed::gvalid ( )
inlinestaticnoexcept

Check if global-plumed is valid.

Returns
true if global plumed object (see global()) is valid.
Note
Equivalent to plumed_gvalid() but returns a bool

◆ incref()

Plumed& PLMD::Plumed::incref ( )
inlinenoexcept

Increase reference counter.

Available as of PLUMED 2.5.

Using this method improperly might interfere with correct object construction and destruction. If you want to play with this, also try to compile using -D__PLUMED_WRAPPER_DEBUG_REFCOUNT=1 and see what happens.

A possible usage is to transfer the ownership of a temporary object when it is converted

plumed p=Plumed::dlopen(path).incref()
// without incref(), the just constructed object will be destroyed
// when the temporary object is deleted.
... do stuff ...
plumed_finalize(p);

◆ installed()

static bool PLMD::Plumed::installed ( )
inlinestaticnoexcept

Check if plumed is installed (for runtime binding)

Returns
true if plumed is installed, false otherwise
Note
Equivalent to plumed_installed() but returns a bool

◆ make_shape()

std::array<std::size_t,5> PLMD::Plumed::make_shape ( std::initializer_list< SizeLike shape)
inlineprivate

Internal tool to convert initializer_list to shape This is just taking an initializer list and making a std::array.

◆ makeInvalid()

static Plumed PLMD::Plumed::makeInvalid ( )
inlinestaticnoexcept

Invalid constructor.

Available as of PLUMED 2.5.

Can be used to initialize an invalid object. It might be useful to postpone the initialization of a Plumed object. Consider the following case

  Plumed p;
  setenv("PLUMED_KERNEL","/path/to/kernel/libplumedKernel.so",1);
  p.cmd("init")

Here the p object will be initialized before the PLUMED_KERNEL env var has been set. This can be particularly problematic if p is stored in some high level class. The following case would do the job

  Plumed p;
  setenv("PLUMED_KERNEL","/path/to/kernel/libplumedKernel.so",1);
  p=Plumed();
  p.cmd("init")

However, there will be some error reported related to the attempt to load the kernel when p is initialized. The following solution is the optimal one:

  Plumed p(Plumed::makeInvalid());
  setenv("PLUMED_KERNEL","/path/to/kernel/libplumedKernel.so",1);
  p=Plumed();
  p.cmd("init")

◆ makeValid()

static Plumed PLMD::Plumed::makeValid ( )
inlinestaticnoexcept

Create a valid PLMD::Plumed object.

Can be used to create a valid object e.g. when Plumed.h was compiled with -D__PLUMED_WRAPPER_CXX_DEFAULT_INVALID. For internal usage.

◆ operator bool()

PLMD::Plumed::operator bool ( ) const
inlineexplicitnoexcept

Same as valid().

Available as of PLUMED 2.5.

Allow code such as

Plumed p;
if(!p) raise_error();
p.cmd("init");

In order to avoid ambiguous conversions, this is only allowed when compiling with C++11 where it is marked as explicit.

◆ operator plumed()

PLMD::Plumed::operator plumed ( ) const
inlinenoexcept

Retrieve the C plumed structure for this object.

Notice that the resulting plumed structure is a weak reference and should NOT be finalized, unless a new reference is explicitly added

Plumed p;
plumed c=p;
plumed_finalize(c); // <- this is wrong
Plumed p;
plumed c=plumed_create_reference(p);
plumed_finalize(c); // <- this is right

◆ operator=() [1/2]

Plumed& PLMD::Plumed::operator= ( const Plumed p)
inlinenoexcept

Assignment operator.

Available as of PLUMED 2.5.

Takes a reference,incrementing the reference counter of the corresponding object.

◆ operator=() [2/2]

Plumed& PLMD::Plumed::operator= ( Plumed &&  p)
inlinenoexcept

Move assignment.

Available as of PLUMED 2.5. Only if move semantics is enabled.

◆ plumed_cmd_cxx() [1/5]

static void PLMD::Plumed::plumed_cmd_cxx ( plumed  p,
const char *  key,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_cmd_cxx() [2/5]

template<typename T >
static void PLMD::Plumed::plumed_cmd_cxx ( plumed  p,
const char *  key,
T *  val,
__PLUMED_WRAPPER_STD size_t  nelem,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_cmd_cxx() [3/5]

template<typename T >
static void PLMD::Plumed::plumed_cmd_cxx ( plumed  p,
const char *  key,
T *  val,
const __PLUMED_WRAPPER_STD size_t *  shape,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_cmd_cxx() [4/5]

template<typename T >
static void PLMD::Plumed::plumed_cmd_cxx ( plumed  p,
const char *  key,
T *  val,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_cmd_cxx() [5/5]

template<typename T >
static void PLMD::Plumed::plumed_cmd_cxx ( plumed  p,
const char *  key,
val,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_error_rethrow_cxx()

static __PLUMED_WRAPPER_CXX_NORETURN void PLMD::Plumed::plumed_error_rethrow_cxx ( plumed_error  h)
inlinestatic
This is a tool to rethrow an error as an exception and finalize the error.

In practice, this makes it possible to write a code like this:
```
Plumed p;
plumed_error e;

store error in e if something wrong happes notice that Plumed (C++) is implicitly converted to plumed (C) when calling plumed_cmd plumed_cmd(p,"init",&e); do other things here then throw the exception if(e.code) plumed_error_rethrow(e);

It should be used through the macro plumed_error_rethrow. ```

◆ plumed_gcmd_cxx() [1/3]

template<typename T >
static void PLMD::Plumed::plumed_gcmd_cxx ( const char *  key,
val,
__PLUMED_WRAPPER_STD size_t  nelem,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_gcmd_cxx() [2/3]

template<typename T >
static void PLMD::Plumed::plumed_gcmd_cxx ( const char *  key,
val,
const __PLUMED_WRAPPER_STD size_t *  shape,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ plumed_gcmd_cxx() [3/3]

template<typename T >
static void PLMD::Plumed::plumed_gcmd_cxx ( const char *  key,
val,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
inlinestatic

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

◆ rethrow() [1/2]

static __PLUMED_WRAPPER_CXX_NORETURN void PLMD::Plumed::rethrow ( )
inlinestaticprivate

Rethrow the current exception.

This is useful in order to handle an exception thrown by a kernel <=2.4. Only std exceptions are handled, though some of them are thrown as special Plumed exceptions in order to be attached a message.

◆ rethrow() [2/2]

static __PLUMED_WRAPPER_CXX_NORETURN void PLMD::Plumed::rethrow ( plumed_error h)
inlinestaticprivate

Recursive function that rethrows an exception with all the nested ones.

In order to do so, we start throwing from the first exception that was originally thrown and recursively throw the others using throw_with_nested.

plumed_error h is finalized at exit by the exception_dispatch function, to avoid memory leaks

◆ toFortran()

void PLMD::Plumed::toFortran ( char *  c) const
inlinenoexcept

Retrieve a FORTRAN handler for this object.

Parameters
cThe FORTRAN handler (a char[32]). Notice that the resulting plumed structure is a weak reference and should NOT be finalized, unless a new reference is explicitly added.

◆ toVoid()

void* PLMD::Plumed::toVoid ( ) const
inlinenoexcept

Retrieve a void* handler for this object.

Available as of PLUMED 2.5. Notice that the resulting plumed structure is a weak reference and should NOT be finalized, unless a new reference is explicitly added.

◆ useCount()

int PLMD::Plumed::useCount ( ) const
inlinenoexcept

Returns the number of references to this object.

Available as of PLUMED 2.5.

Note
Equivalent to plumed_use_count()

◆ valid()

bool PLMD::Plumed::valid ( ) const
inlinenoexcept

Check if Plumed object is valid.

Available as of PLUMED 2.5

Returns
true if plumed is valid, false otherwise
Note
Equivalent to plumed_valid() but returns a bool

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const Plumed a,
const Plumed b 
)
related

Comparison operator. Available as of PLUMED 2.5.

◆ operator<()

bool operator< ( const Plumed a,
const Plumed b 
)
related

Comparison operator. Available as of PLUMED 2.5.

◆ operator<=()

bool operator<= ( const Plumed a,
const Plumed b 
)
related

Comparison operator. Available as of PLUMED 2.5.

◆ operator==()

bool operator== ( const Plumed a,
const Plumed b 
)
related

Comparison operator. Available as of PLUMED 2.5.

◆ operator>()

bool operator> ( const Plumed a,
const Plumed b 
)
related

Comparison operator. Available as of PLUMED 2.5.

◆ operator>=()

bool operator>= ( const Plumed a,
const Plumed b 
)
related

Comparison operator. Available as of PLUMED 2.5.

◆ plumed_gcmd_cxx()

static void plumed_gcmd_cxx ( const char *  key,
plumed_error error = __PLUMED_WRAPPER_CXX_NULLPTR 
)
related

These functions can be used to make plumed_cmd behave as the C++ wrapper PLMD::Plumed::cmd, namely implement typechecks and rethrowing exception.

This function can be used to make plumed_gcmd behave as the C++ wrapper PLMD::Plumed::gcmd, namely implement typechecks and rethrowing exception. To be used through the macro plumed_gcmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). Available as of PLUMED 2.8. To be used through the macro plumed_cmd (defined when __PLUMED_WRAPPER_CXX_BIND_C==1). They are also used by the Plumed::cmd functions to avoid code duplication. Available as of PLUMED 2.8.

Member Data Documentation

◆ main

plumed PLMD::Plumed::main
private

C structure.


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