All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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)
 Print out the keywords for an action in html 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...
 
typedef std::map< std::string,
creator_pointer >::iterator 
mIterator
 Iterator over the map. More...
 
typedef std::map< std::string,
creator_pointer >
::const_iterator 
const_mIterator
 Iterator over the map. More...
 
typedef std::map< std::string,
Keywords >::iterator 
mIteratork
 Iterator over the map. More...
 
typedef std::map< std::string,
Keywords >::const_iterator 
const_mIteratork
 Iterator over the map. More...
 

Private Attributes

std::map< std::string,
creator_pointer
m
 Map action to a function which creates the related object. More...
 
std::map< std::string,
keywords_pointer
mk
 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

typedef std::map<std::string,creator_pointer>::const_iterator PLMD::ActionRegister::const_mIterator
private

Iterator over the map.

typedef std::map<std::string,Keywords>::const_iterator PLMD::ActionRegister::const_mIteratork
private

Iterator over the map.

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

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

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

Pointer to a function which, returns the keywords allowed.

typedef std::map<std::string,creator_pointer>::iterator PLMD::ActionRegister::mIterator
private

Iterator over the map.

typedef std::map<std::string,Keywords>::iterator PLMD::ActionRegister::mIteratork
private

Iterator over the map.

Constructor & Destructor Documentation

PLMD::ActionRegister::~ActionRegister ( )

Member Function Documentation

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
bool PLMD::ActionRegister::check ( std::string  action)

Verify if a directive is present in the register.

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
bool PLMD::ActionRegister::printManual ( const std::string &  action)

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

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

Print out a template command for an action.

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

Friends And Related Function Documentation

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

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

Write on a stream the list of registered directives.

#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

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

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

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

Map action to a function which creates the related object.

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: