Classes | Namespaces | Macros | Functions
Plumed.h File Reference
#include <cstddef>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <climits>
#include <exception>
#include <stdexcept>
#include <string>
#include <ios>
#include <new>
#include <typeinfo>
#include <array>
#include <initializer_list>

Classes

class  PLMD::Plumed::Exception
 Base class used to rethrow PLUMED exceptions. More...
 
class  PLMD::Plumed::ExceptionDebug
 Used to rethrow a PLMD::ExceptionDebug. More...
 
class  PLMD::Plumed::ExceptionError
 Used to rethrow a PLMD::ExceptionError. More...
 
class  PLMD::Plumed::ExceptionTypeError
 Thrown when a wrong pointer is passed to the PLUMED interface. More...
 
class  PLMD::Plumed::Invalid
 Thrown when trying to access an invalid plumed object. More...
 
class  PLMD::Plumed::LeptonException
 Class used to rethrow Lepton exceptions. More...
 
struct  PLMD::Plumed::NothrowHandler
 Error handler used to rethrow exceptions. More...
 
class  PLMD::Plumed
 C++ wrapper for plumed. More...
 
struct  plumed
 Main plumed object. More...
 
struct  plumed_error
 Small structure that is only defined locally to retrieve errors. More...
 
struct  plumed_nothrow_handler
 
struct  plumed_safeptr
 Structure holding a typesafe pointer. More...
 
class  PLMD::Plumed::SafePtr
 Small class that wraps plumed_safeptr in order to make its initialization easier. More...
 

Namespaces

 PLMD
 

Macros

#define __PLUMED_WRAPPER_ANONYMOUS_BEGIN
 
#define __PLUMED_WRAPPER_ANONYMOUS_END
 
#define __PLUMED_WRAPPER_C_BEGIN   __PLUMED_WRAPPER_EXTERN_C_BEGIN extern
 
#define __PLUMED_WRAPPER_C_END   __PLUMED_WRAPPER_EXTERN_C_END
 
#define __PLUMED_WRAPPER_C_TYPESAFE   0
 
#define __PLUMED_WRAPPER_CXX   1
 
#define __PLUMED_WRAPPER_CXX_ANONYMOUS_NAMESPACE   0
 
#define __PLUMED_WRAPPER_CXX_BIND_C   1
 
#define __PLUMED_WRAPPER_CXX_DEFAULT_INVALID   0
 
#define __PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER   512
 
#define __PLUMED_WRAPPER_CXX_EXPLICIT   explicit
 
#define __PLUMED_WRAPPER_CXX_LONGLONG   1
 
#define __PLUMED_WRAPPER_CXX_NOEXCEPT   noexcept
 
#define __PLUMED_WRAPPER_CXX_NORETURN   [[ noreturn ]]
 
#define __PLUMED_WRAPPER_CXX_NULLPTR   nullptr
 
#define __PLUMED_WRAPPER_CXX_OVERRIDE   override
 
#define __PLUMED_WRAPPER_CXX_POLYMORPHIC   1
 
#define __PLUMED_WRAPPER_CXX_STD   1
 
#define __PLUMED_WRAPPER_CXX_TYPESAFE   1
 
#define __PLUMED_WRAPPER_ENABLE_RTLD_DEEPBIND   1
 
#define __PLUMED_WRAPPER_EXTERN   1
 
#define __PLUMED_WRAPPER_EXTERN_C_BEGIN   extern "C" {
 
#define __PLUMED_WRAPPER_EXTERN_C_END   }
 
#define __PLUMED_WRAPPER_GLOBAL   1
 
#define __PLUMED_WRAPPER_IMPLEMENTATION_   0
 
#define __PLUMED_WRAPPER_INTERNALS_BEGIN   __PLUMED_WRAPPER_EXTERN_C_BEGIN static
 
#define __PLUMED_WRAPPER_INTERNALS_END   __PLUMED_WRAPPER_EXTERN_C_END
 
#define __PLUMED_WRAPPER_LIBCXX11   0
 
#define __PLUMED_WRAPPER_NOSTRING_EXCEPTION(name)
 
#define __PLUMED_WRAPPER_REDEFINE_CMD   ::PLMD::Plumed::plumed_cmd_cxx
 
#define __PLUMED_WRAPPER_REDEFINE_GCMD   ::PLMD::Plumed::plumed_gcmd_cxx
 
#define __PLUMED_WRAPPER_SAFEPTR(type, code, size)
 Macro that uses __PLUMED_WRAPPER_SAFEPTR_INNER to generate constructors with all possible pointer-const combinations. More...
 
#define __PLUMED_WRAPPER_SAFEPTR_EMPTY(type, code)   __PLUMED_WRAPPER_SAFEPTR(type,code,0)
 Macro that generates the constructors from empy types (those of which sizeof cannot be computed) More...
 
#define __PLUMED_WRAPPER_SAFEPTR_INNER(type_, flags_)
 Macro that generate a constructor with given type and flags. More...
 
#define __PLUMED_WRAPPER_SAFEPTR_SIZED(type, code)
 Macro that generates the constructors from sized types (those of which sizeof can be computed). More...
 
#define __PLUMED_WRAPPER_STATIC_INLINE   static inline
 
#define __PLUMED_WRAPPER_STD   ::std::
 

Functions

void plumed_cmd_safe (plumed p, const char *key, plumed_safeptr)
 
void plumed_cmd_safe_nothrow (plumed p, const char *key, plumed_safeptr, plumed_nothrow_handler nothrow)
 
plumed plumed_create_dlopen2 (const char *path, int mode)
 Constructor from path. More...
 
plumed plumed_create_dlsym (void *dlhandle)
 Constructor from dlopen handle. More...
 
__PLUMED_WRAPPER_STATIC_INLINE void plumed_error_finalize (plumed_error error) noexcept
 Finalize error - should be called when an error is raised to avoid leaks. More...
 
__PLUMED_WRAPPER_STATIC_INLINE void plumed_error_init (plumed_error *error) noexcept
 Initialize error (for internal usage) More...
 
__PLUMED_WRAPPER_STATIC_INLINE void plumed_error_set (void *ptr, int code, const char *what, const void *opt) noexcept
 Callback (for internal usage) More...
 
static __PLUMED_WRAPPER_ANONYMOUS_BEGIN bool PLMD::PlumedGetenvExceptionsDebug () noexcept
 Retrieve PLUMED_EXCEPTIONS_DEBUG (internal utility). More...
 

Macro Definition Documentation

◆ __PLUMED_WRAPPER_ANONYMOUS_BEGIN

#define __PLUMED_WRAPPER_ANONYMOUS_BEGIN

◆ __PLUMED_WRAPPER_ANONYMOUS_END

#define __PLUMED_WRAPPER_ANONYMOUS_END

◆ __PLUMED_WRAPPER_C_BEGIN

#define __PLUMED_WRAPPER_C_BEGIN   __PLUMED_WRAPPER_EXTERN_C_BEGIN extern

◆ __PLUMED_WRAPPER_C_END

#define __PLUMED_WRAPPER_C_END   __PLUMED_WRAPPER_EXTERN_C_END

◆ __PLUMED_WRAPPER_C_TYPESAFE

#define __PLUMED_WRAPPER_C_TYPESAFE   0

◆ __PLUMED_WRAPPER_CXX

#define __PLUMED_WRAPPER_CXX   1

◆ __PLUMED_WRAPPER_CXX_ANONYMOUS_NAMESPACE

#define __PLUMED_WRAPPER_CXX_ANONYMOUS_NAMESPACE   0

◆ __PLUMED_WRAPPER_CXX_BIND_C

#define __PLUMED_WRAPPER_CXX_BIND_C   1

◆ __PLUMED_WRAPPER_CXX_DEFAULT_INVALID

#define __PLUMED_WRAPPER_CXX_DEFAULT_INVALID   0

◆ __PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER

#define __PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER   512

◆ __PLUMED_WRAPPER_CXX_EXPLICIT

#define __PLUMED_WRAPPER_CXX_EXPLICIT   explicit

◆ __PLUMED_WRAPPER_CXX_LONGLONG

#define __PLUMED_WRAPPER_CXX_LONGLONG   1

◆ __PLUMED_WRAPPER_CXX_NOEXCEPT

#define __PLUMED_WRAPPER_CXX_NOEXCEPT   noexcept

◆ __PLUMED_WRAPPER_CXX_NORETURN

#define __PLUMED_WRAPPER_CXX_NORETURN   [[ noreturn ]]

◆ __PLUMED_WRAPPER_CXX_NULLPTR

#define __PLUMED_WRAPPER_CXX_NULLPTR   nullptr

◆ __PLUMED_WRAPPER_CXX_OVERRIDE

#define __PLUMED_WRAPPER_CXX_OVERRIDE   override

◆ __PLUMED_WRAPPER_CXX_POLYMORPHIC

#define __PLUMED_WRAPPER_CXX_POLYMORPHIC   1

◆ __PLUMED_WRAPPER_CXX_STD

#define __PLUMED_WRAPPER_CXX_STD   1

◆ __PLUMED_WRAPPER_CXX_TYPESAFE

#define __PLUMED_WRAPPER_CXX_TYPESAFE   1

◆ __PLUMED_WRAPPER_ENABLE_RTLD_DEEPBIND

#define __PLUMED_WRAPPER_ENABLE_RTLD_DEEPBIND   1

◆ __PLUMED_WRAPPER_EXTERN

#define __PLUMED_WRAPPER_EXTERN   1

◆ __PLUMED_WRAPPER_EXTERN_C_BEGIN

#define __PLUMED_WRAPPER_EXTERN_C_BEGIN   extern "C" {

◆ __PLUMED_WRAPPER_EXTERN_C_END

#define __PLUMED_WRAPPER_EXTERN_C_END   }

◆ __PLUMED_WRAPPER_GLOBAL

#define __PLUMED_WRAPPER_GLOBAL   1

◆ __PLUMED_WRAPPER_IMPLEMENTATION_

#define __PLUMED_WRAPPER_IMPLEMENTATION_   0

◆ __PLUMED_WRAPPER_INTERNALS_BEGIN

#define __PLUMED_WRAPPER_INTERNALS_BEGIN   __PLUMED_WRAPPER_EXTERN_C_BEGIN static

◆ __PLUMED_WRAPPER_INTERNALS_END

#define __PLUMED_WRAPPER_INTERNALS_END   __PLUMED_WRAPPER_EXTERN_C_END

◆ __PLUMED_WRAPPER_LIBCXX11

#define __PLUMED_WRAPPER_LIBCXX11   0

◆ __PLUMED_WRAPPER_NOSTRING_EXCEPTION

#define __PLUMED_WRAPPER_NOSTRING_EXCEPTION (   name)
Value:
class std_ ## name : \
public ::std::name \
{ \
public: \
__PLUMED_WRAPPER_CXX_EXPLICIT std_ ## name(const char * msg) __PLUMED_WRAPPER_CXX_NOEXCEPT { \
this->msg[0]='\0'; \
__PLUMED_WRAPPER_STD strncat(this->msg,msg,__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1); \
if(PlumedGetenvExceptionsDebug() && __PLUMED_WRAPPER_STD strlen(msg) > __PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1) __PLUMED_WRAPPER_STD fprintf(stderr,"+++ WARNING: message will be truncated\n"); \
} \
std_ ## name(const std_ ## name & other) __PLUMED_WRAPPER_CXX_NOEXCEPT { \
msg[0]='\0'; \
__PLUMED_WRAPPER_STD strncat(msg,other.msg,__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1); \
} \
std_ ## name & operator=(const std_ ## name & other) __PLUMED_WRAPPER_CXX_NOEXCEPT { \
if(this==&other) return *this;\
msg[0]='\0'; \
__PLUMED_WRAPPER_STD strncat(msg,other.msg,__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1); \
return *this; \
} \
const char* what() const __PLUMED_WRAPPER_CXX_NOEXCEPT __PLUMED_WRAPPER_CXX_OVERRIDE {return msg;} \
~std_ ## name() __PLUMED_WRAPPER_CXX_NOEXCEPT __PLUMED_WRAPPER_CXX_OVERRIDE {} \
};

◆ __PLUMED_WRAPPER_REDEFINE_CMD

#define __PLUMED_WRAPPER_REDEFINE_CMD   ::PLMD::Plumed::plumed_cmd_cxx

◆ __PLUMED_WRAPPER_REDEFINE_GCMD

#define __PLUMED_WRAPPER_REDEFINE_GCMD   ::PLMD::Plumed::plumed_gcmd_cxx

◆ __PLUMED_WRAPPER_SAFEPTR

#define __PLUMED_WRAPPER_SAFEPTR (   type,
  code,
  size 
)
Value:
__PLUMED_WRAPPER_SAFEPTR_INNER(type, size | (0x10000*(code)) | (0x2000000*2)) \
__PLUMED_WRAPPER_SAFEPTR_INNER(type const, size | (0x10000*(code)) | (0x2000000*3)) \
__PLUMED_WRAPPER_SAFEPTR_INNER(type*, size | (0x10000*(code)) | (0x2000000*4)) \
__PLUMED_WRAPPER_SAFEPTR_INNER(type*const, size | (0x10000*(code)) | (0x2000000*5)) \
__PLUMED_WRAPPER_SAFEPTR_INNER(type const*, size | (0x10000*(code)) | (0x2000000*6)) \
__PLUMED_WRAPPER_SAFEPTR_INNER(type const*const, size | (0x10000*(code)) | (0x2000000*7))

Macro that uses __PLUMED_WRAPPER_SAFEPTR_INNER to generate constructors with all possible pointer-const combinations.

◆ __PLUMED_WRAPPER_SAFEPTR_EMPTY

#define __PLUMED_WRAPPER_SAFEPTR_EMPTY (   type,
  code 
)    __PLUMED_WRAPPER_SAFEPTR(type,code,0)

Macro that generates the constructors from empy types (those of which sizeof cannot be computed)

◆ __PLUMED_WRAPPER_SAFEPTR_INNER

#define __PLUMED_WRAPPER_SAFEPTR_INNER (   type_,
  flags_ 
)
Value:
SafePtr(type_*ptr, __PLUMED_WRAPPER_STD size_t nelem, const __PLUMED_WRAPPER_STD size_t* shape) __PLUMED_WRAPPER_CXX_NOEXCEPT { \
safe.ptr=ptr; \
safe.nelem=nelem; \
safe.shape=const_cast<__PLUMED_WRAPPER_STD size_t*>(shape); \
safe.flags=flags_; \
buffer[0]='\0'; \
}

Macro that generate a constructor with given type and flags.

◆ __PLUMED_WRAPPER_SAFEPTR_SIZED

#define __PLUMED_WRAPPER_SAFEPTR_SIZED (   type,
  code 
)
Value:
__PLUMED_WRAPPER_SAFEPTR(type,code,sizeof(type)) \
SafePtr(type val, __PLUMED_WRAPPER_STD size_t nelem, const __PLUMED_WRAPPER_STD size_t* shape) __PLUMED_WRAPPER_CXX_NOEXCEPT { \
assert(sizeof(type)<=32); \
(void) nelem; \
(void) shape; \
safe.ptr=buffer; \
safe.nelem=1; \
safe.flags=sizeof(type) | (0x10000*(code)) | (0x2000000*1); \
__PLUMED_WRAPPER_STD memcpy(buffer,&val,sizeof(type)); \
}

Macro that generates the constructors from sized types (those of which sizeof can be computed).

In addition to generating constructors with all pointer types, it generates a constructor to allow pass-by-value

◆ __PLUMED_WRAPPER_STATIC_INLINE

#define __PLUMED_WRAPPER_STATIC_INLINE   static inline

◆ __PLUMED_WRAPPER_STD

#define __PLUMED_WRAPPER_STD   ::std::

Function Documentation

◆ plumed_cmd_safe()

void plumed_cmd_safe ( plumed  p,
const char *  key,
plumed_safeptr   
)

◆ plumed_cmd_safe_nothrow()

void plumed_cmd_safe_nothrow ( plumed  p,
const char *  key,
plumed_safeptr  ,
plumed_nothrow_handler  nothrow 
)

◆ plumed_create_dlopen2()

plumed plumed_create_dlopen2 ( const char *  path,
int  mode 
)

Constructor from path.

Available as of PLUMED 2.5

Same as plumed_create_dlopen, but also allows to specify the mode for dlopen.

Warning
Use with care, since not all the possible modes work correctly with PLUMED.

◆ plumed_create_dlsym()

plumed plumed_create_dlsym ( void *  dlhandle)

Constructor from dlopen handle.

Available as of PLUMED 2.8

Same as plumed_create_dlopen, but it acts on an already loaded library. This allows to separate the library loading from the construction of the plumed object. By using this function, the caller takes the responsibility to later use dlclose on this handle.

◆ plumed_error_finalize()

__PLUMED_WRAPPER_STATIC_INLINE void plumed_error_finalize ( plumed_error  error)
noexcept

Finalize error - should be called when an error is raised to avoid leaks.

◆ plumed_error_init()

__PLUMED_WRAPPER_STATIC_INLINE void plumed_error_init ( plumed_error error)
noexcept

Initialize error (for internal usage)

◆ plumed_error_set()

__PLUMED_WRAPPER_STATIC_INLINE void plumed_error_set ( void *  ptr,
int  code,
const char *  what,
const void *  opt 
)
noexcept

Callback (for internal usage)

__PLUMED_WRAPPER_SAFEPTR_INNER
#define __PLUMED_WRAPPER_SAFEPTR_INNER(type_, flags_)
Macro that generate a constructor with given type and flags.
Definition: Plumed.h:1938
__PLUMED_WRAPPER_CXX_NOEXCEPT
#define __PLUMED_WRAPPER_CXX_NOEXCEPT
Definition: Plumed.h:643
__PLUMED_WRAPPER_CXX_NULLPTR
#define __PLUMED_WRAPPER_CXX_NULLPTR
Definition: Plumed.h:647
PLMD::PlumedGetenvExceptionsDebug
static __PLUMED_WRAPPER_ANONYMOUS_BEGIN bool PlumedGetenvExceptionsDebug() noexcept
Retrieve PLUMED_EXCEPTIONS_DEBUG (internal utility).
Definition: Plumed.h:1530
__PLUMED_WRAPPER_SAFEPTR
#define __PLUMED_WRAPPER_SAFEPTR(type, code, size)
Macro that uses __PLUMED_WRAPPER_SAFEPTR_INNER to generate constructors with all possible pointer-con...
Definition: Plumed.h:1950
__PLUMED_WRAPPER_STD
#define __PLUMED_WRAPPER_STD
Definition: Plumed.h:635
PLMD::blas::n
int n
Definition: blas.cpp:40
__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER
#define __PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER
Definition: Plumed.h:605
PLMD::lapack::val
double val
Definition: lapack.cpp:3556