C++ wrapper for plumed. More...
#include <Plumed.h>
Classes | |
class | add_buffer_to |
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... | |
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... | |
void | cmd (const char *key) |
Send a command to this plumed object. More... | |
template<typename T > | |
void | cmd (const char *key, T *val, __PLUMED_WRAPPER_STD size_t nelem) |
Send a command to this plumed object. More... | |
template<typename T > | |
void | cmd (const char *key, T *val, const __PLUMED_WRAPPER_STD size_t *shape) |
Send a command to this plumed object. More... | |
template<typename T > | |
void | cmd (const char *key, T *val, std::initializer_list< std::size_t > shape) |
Send a command to this plumed object. More... | |
template<typename T > | |
void | cmd (const char *key, T val) |
Send a command to this plumed object. More... | |
Plumed & | decref () noexcept |
Decrease reference counter. More... | |
Plumed & | incref () 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... | |
Plumed & | operator= (const Plumed &p) noexcept |
Assignment operator. More... | |
Plumed & | operator= (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, __PLUMED_WRAPPER_STD size_t nelem) |
Send a command to global-plumed. More... | |
template<typename T > | |
static void | gcmd (const char *key, T *val, const __PLUMED_WRAPPER_STD size_t *shape) |
Send a command to global-plumed. More... | |
template<typename T > | |
static void | gcmd (const char *key, T *val, std::initializer_list< std::size_t > shape) |
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... | |
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... | |
Static Private Member Functions | |
static void | cmd_priv (plumed main, const char *key, SafePtr *safe=__PLUMED_WRAPPER_CXX_NULLPTR, const void *unsafe=__PLUMED_WRAPPER_CXX_NULLPTR, 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... | |
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.
|
inlinenoexcept |
Constructor.
Notice that when using runtime binding the constructed object might be invalid. One might check it using the valid() method.
|
inlineexplicitnoexcept |
Clone a Plumed object from a FORTRAN char* handler.
c | The 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.
|
inlineexplicitnoexcept |
Create a reference from a void* pointer.
Available as of PLUMED 2.5.
|
inlineexplicitnoexcept |
Clone a Plumed object from a C plumed structure.
p | The 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.
|
inlinenoexcept |
Copy constructor.
Takes a reference, incrementing the reference counter of the corresponding object.
|
inlinenoexcept |
Move constructor.
Available as of PLUMED 2.5. Only if move semantics is enabled.
|
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.
|
inline |
Send a command to this plumed object.
key | The name of the command to be executed |
|
inline |
Send a command to this plumed object.
key | The name of the command to be executed |
val | The argument, passed by pointer. |
nelem | The number of elements passed. |
|
inline |
Send a command to this plumed object.
key | The name of the command to be executed |
val | The argument, passed by pointer. |
shape | A zero-terminated array containing the shape of the data. |
|
inline |
Send a command to this plumed object.
key | The name of the command to be executed |
val | The argument, passed by pointer. |
shape | The shape of the argument, in the form of an initialier_list (e.g., {10,3}). |
|
inline |
Send a command to this plumed object.
key | The name of the command to be executed |
val | The argument, passed by value. |
|
inlinestaticprivate |
Private version of cmd.
It is used here to avoid duplication of code between typesafe and not-typesafe versions
|
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.
|
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");
|
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.
|
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.
|
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:
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.
|
inlinestatic |
Send a command to global-plumed.
key | The name of the command to be executed |
|
inlinestatic |
Send a command to global-plumed.
key | The name of the command to be executed |
val | The argument. |
nelem | Number of elements in the passed array, for typechecking. |
|
inlinestatic |
Send a command to global-plumed.
key | The name of the command to be executed |
val | The argument. |
shape | The shape of the argument. |
|
inlinestatic |
Send a command to global-plumed.
key | The name of the command to be executed |
val | The argument. |
shape | The shape of the argument, in the form of an initialier_list (e.g., {10,3}). |
|
inlinestatic |
Send a command to global-plumed.
key | The name of the command to be executed |
val | The argument. |
|
inlinestaticnoexcept |
Initialize global-plumed.
|
inlinestaticnoexcept |
Finalize global-plumed.
|
inlinestaticnoexcept |
Check if global-plumed has been initialized.
|
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.
|
inlinestaticnoexcept |
Check if global-plumed is valid.
|
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);
|
inlinestaticnoexcept |
Check if plumed is installed (for runtime binding)
|
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")
|
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.
|
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.
|
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
Assignment operator.
Available as of PLUMED 2.5.
Takes a reference,incrementing the reference counter of the corresponding object.
Move assignment.
Available as of PLUMED 2.5. Only if move semantics is enabled.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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. ```
|
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.
|
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.
|
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.
|
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.
|
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
|
inlinenoexcept |
Retrieve a FORTRAN handler for this object.
c | The 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. |
|
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.
|
inlinenoexcept |
Returns the number of references to this object.
Available as of PLUMED 2.5.
|
inlinenoexcept |
Check if Plumed object is valid.
Available as of PLUMED 2.5
Comparison operator. Available as of PLUMED 2.5.
Comparison operator. Available as of PLUMED 2.5.
Comparison operator. Available as of PLUMED 2.5.
Comparison operator. Available as of PLUMED 2.5.
Comparison operator. Available as of PLUMED 2.5.
Comparison operator. Available as of PLUMED 2.5.
|
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.
|
private |
C structure.
Hosted by GitHub | 1.8.17 |