C++ wrapper for plumed. More...
#include <Plumed.h>
Classes | |
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 | Invalid |
Thrown when trying to access an invalid plumed object. More... | |
class | LeptonException |
Class used to rethrow Lepton exceptions. More... | |
struct | NothrowHandler |
Error handler used to rethrow exceptions. More... | |
Public Member Functions | |
Plumed () noexcept | |
Constructor. More... | |
Plumed (const char *c) noexcept | |
Clone a Plumed object from a FORTRAN char* handler. More... | |
Plumed (void *v) noexcept | |
Create a reference from a void* pointer. More... | |
Plumed (plumed p) noexcept | |
Clone a Plumed object from a C plumed structure. More... | |
Plumed (const Plumed &p) noexcept | |
Copy constructor. More... | |
Plumed (Plumed &&p) noexcept | |
Move constructor. More... | |
virtual | ~Plumed () noexcept |
Destructor. More... | |
void | cmd (const char *key, const void *val=NULL) |
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 void | gcmd (const char *key, const void *val=NULL) |
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 Private Member Functions | |
static void | nothrow_handler (void *ptr, int code, const char *what, const void *opt) |
Callback function that sets the error handler. More... | |
static void | rethrow (const NothrowHandler &h) |
Rethrow the exception based on the information saved in the NothrowHandler. More... | |
static void | rethrow () |
Rethrow the current exception. 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 |
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 |
val | The argument. It is declared as const to allow calls like p.cmd("A","B"), but for some choice of key it can change the content |
|
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.
|
inlinestatic |
Send a command to global-plumed.
key | The name of the command to be executed |
val | The argument. It is declared as const to allow calls like gcmd("A","B"), but for some choice of key it can change the content |
|
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.
|
inlinestaticprivate |
Callback function that sets the error handler.
opt argument is interpreted as the pointer to a null terminated array of void*. The number of non-null element is expected to be even, and there should be a null element that follows. Every pair of pointers should point to a char, identifying the type of argument passed, and an arbitrary object. Currently used to (optionally) pass error_code.
|
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.
|
inlinestaticprivate |
Rethrow the exception based on the information saved in the NothrowHandler.
|
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.
|
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.
|
private |
C structure.
Hosted by GitHub | 1.8.14 |