Classes | Public Member Functions | Static Public 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  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...
 
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 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
 

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

◆ cmd()

void PLMD::Plumed::cmd ( const char *  key,
const void *  val = NULL 
)
inline

Send a command to this plumed object.

Parameters
keyThe name of the command to be executed
valThe 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
Note
Similar to plumed_cmd(). It actually called plumed_cmd_nothrow() and rethrow any exception raised within PLUMED.

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

◆ gcmd()

static void PLMD::Plumed::gcmd ( const char *  key,
const void *  val = NULL 
)
inlinestatic

Send a command to global-plumed.

Parameters
keyThe name of the command to be executed
valThe argument. It is declared as const to allow calls like gcmd("A","B"), but for some choice of key it can change the content
Note
Equivalent to plumed_gcmd()

◆ gcreate()

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

Initialize global-plumed.

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

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

◆ nothrow_handler()

static void PLMD::Plumed::nothrow_handler ( void *  ptr,
int  code,
const char *  what,
const void *  opt 
)
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.

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

◆ rethrow() [1/2]

static void PLMD::Plumed::rethrow ( const NothrowHandler h)
inlinestaticprivate

Rethrow the exception based on the information saved in the NothrowHandler.

◆ rethrow() [2/2]

static 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.

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

Member Data Documentation

◆ main

plumed PLMD::Plumed::main
private

C structure.


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