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

 ~ActionRegister ()
 
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...
 
std::unique_ptr< Actioncreate (const ActionOptions &ao)
 Create an Action of the type indicated in the options. More...
 
bool getKeywords (const std::string &action, Keywords &keys)
 Retrieve a keywords object for a particular action. More...
 
bool printManual (const std::string &action, const bool &vimout, const bool &spellout)
 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)
 

Private Types

typedef std::unique_ptr< 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::set< std::string > disabled
 Set of disabled actions (which were registered more than once) More...
 
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...
 

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 std::unique_ptr<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()

std::unique_ptr< 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

◆ getKeywords()

bool PLMD::ActionRegister::getKeywords ( const std::string &  action,
Keywords keys 
)

Retrieve a keywords object for a particular action.

◆ printManual()

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

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 std::unique_ptr<PLMD::Action> create(const PLMD::ActionOptions&ao){return std::unique_ptr<classname>(new classname(ao));} \
public: \
PLUMED_UNIQUENAME(classname##RegisterMe)(){PLMD::actionRegister().add(directive,create,classname::registerKeywords);} \
~PLUMED_UNIQUENAME(classname##RegisterMe)(){PLMD::actionRegister().remove(create);} \
} PLUMED_UNIQUENAME(classname##RegisterMe);

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:
PLMD::ActionRegister::remove
void remove(creator_pointer)
Definition: ActionRegister.cpp:45
PLUMED_UNIQUENAME
#define PLUMED_UNIQUENAME(str)
Definition: ActionRegister.h:93
PLMD::ActionOptions
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
PLMD::actionRegister
ActionRegister & actionRegister()
Definition: ActionRegister.cpp:40
PLMD::ActionRegister::add
void add(std::string key, creator_pointer cp, keywords_pointer kp)
Register a new class.
Definition: ActionRegister.cpp:53
PLMD::ActionRegister::create
std::unique_ptr< Action > create(const ActionOptions &ao)
Create an Action of the type indicated in the options.
Definition: ActionRegister.cpp:73