Public Member Functions | Private Types | Private Attributes | Friends | Related Functions | List of all members
PLMD::ActionRegister Class Reference

Register holding all the allowed keywords. More...

#include <ActionRegister.h>

Public Member Functions

void add (std::string key, creator_pointer cp, keywords_pointer kp)
 Register a new class. More...
 
bool check (std::string action)
 Verify if a directive is present in the register. More...
 
Actioncreate (const ActionOptions &ao)
 Create an Action of the type indicated in the options. More...
 
bool printManual (const std::string &action, const bool &vimout)
 Print out the keywords for an action in html/vim ready for input into the manual. More...
 
bool printTemplate (const std::string &action, bool include_optional)
 Print out a template command for an action. More...
 
void remove (creator_pointer)
 
 ~ActionRegister ()
 

Private Types

typedef Action *(* creator_pointer) (const ActionOptions &)
 Pointer to a function which, given the options, create an Action. More...
 
typedef void(* keywords_pointer) (Keywords &)
 Pointer to a function which, returns the keywords allowed. More...
 

Private Attributes

std::map< std::string, creator_pointerm
 Map action to a function which creates the related object. More...
 
std::map< std::string, keywords_pointermk
 Map action to a function which documents the related object. More...
 
std::set< std::string > disabled
 Set of disabled actions (which were registered more than once) More...
 

Friends

std::ostream & operator<< (std::ostream &, const ActionRegister &)
 Write on a stream the list of registered directives. More...
 

Related Functions

(Note that these are not member functions.)

ActionRegisteractionRegister ()
 Function returning a reference to the ActionRegister. More...
 
#define PLUMED_REGISTER_ACTION(classname, directive)
 Shortcut for Action registration. More...
 

Detailed Description

Register holding all the allowed keywords.

This is a register which holds a map between strings (directives) and function pointers. The function pointers are pointing to functions which create an object of the corresponding class given the corresponding options (ActionOptions). There should be only one of there objects allocated. Actions should be registered here at the beginning of execution If the same directive is used for different classes, it is automatically disabled to avoid random results.

Member Typedef Documentation

◆ creator_pointer

typedef Action*(* PLMD::ActionRegister::creator_pointer) (const ActionOptions &)
private

Pointer to a function which, given the options, create an Action.

◆ keywords_pointer

typedef void(* PLMD::ActionRegister::keywords_pointer) (Keywords &)
private

Pointer to a function which, returns the keywords allowed.

Constructor & Destructor Documentation

◆ ~ActionRegister()

PLMD::ActionRegister::~ActionRegister ( )

Member Function Documentation

◆ add()

void PLMD::ActionRegister::add ( std::string  key,
creator_pointer  cp,
keywords_pointer  kp 
)

Register a new class.

Parameters
keyThe name of the directive to be used in the input file
cpA pointer to a function which creates an object of that class
kpA pointer to a function which returns the allowed keywords

◆ check()

bool PLMD::ActionRegister::check ( std::string  action)

Verify if a directive is present in the register.

◆ create()

Action * PLMD::ActionRegister::create ( const ActionOptions ao)

Create an Action of the type indicated in the options.

Parameters
aoobject containing information for initialization, such as the full input line, a pointer to PlumedMain, etc

◆ printManual()

bool PLMD::ActionRegister::printManual ( const std::string &  action,
const bool &  vimout 
)

Print out the keywords for an action in html/vim ready for input into the manual.

◆ printTemplate()

bool PLMD::ActionRegister::printTemplate ( const std::string &  action,
bool  include_optional 
)

Print out a template command for an action.

◆ remove()

void PLMD::ActionRegister::remove ( creator_pointer  f)

Friends And Related Function Documentation

◆ actionRegister()

ActionRegister & actionRegister ( )
related

Function returning a reference to the ActionRegister.

To avoid problems with order of initialization, this function contains a static ActionRegister which is built the first time the function is called. In this manner, it is always initialized before it's used

◆ operator<<

std::ostream& operator<< ( std::ostream &  ,
const ActionRegister  
)
friend

Write on a stream the list of registered directives.

◆ PLUMED_REGISTER_ACTION

#define PLUMED_REGISTER_ACTION (   classname,
  directive 
)
related
Value:
static class PLUMED_UNIQUENAME(classname##RegisterMe){ \
static PLMD::Action* create(const PLMD::ActionOptions&ao){return new classname(ao);} \
public: \
PLUMED_UNIQUENAME(classname##RegisterMe)(){PLMD::actionRegister().add(directive,create,classname::registerKeywords);} \
~PLUMED_UNIQUENAME(classname##RegisterMe)(){PLMD::actionRegister().remove(create);} \

Shortcut for Action registration.

For easier registration, this file also provides a macro PLUMED_REGISTER_ACTION.

Parameters
classnamethe name of the class to be registered
directivea string containing the corresponding directive This macro should be used in the .cpp file of the corresponding class

Member Data Documentation

◆ disabled

std::set<std::string> PLMD::ActionRegister::disabled
private

Set of disabled actions (which were registered more than once)

◆ m

std::map<std::string,creator_pointer> PLMD::ActionRegister::m
private

Map action to a function which creates the related object.

◆ mk

std::map<std::string,keywords_pointer> PLMD::ActionRegister::mk
private

Map action to a function which documents the related object.


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