Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2019 The plumed team
3 : (see the PEOPLE file at the root of the distribution for a list of names)
4 :
5 : See http://www.plumed.org for more information.
6 :
7 : This file is part of plumed, version 2.
8 :
9 : plumed is free software: you can redistribute it and/or modify
10 : it under the terms of the GNU Lesser General Public License as published by
11 : the Free Software Foundation, either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : plumed is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU Lesser General Public License for more details.
18 :
19 : You should have received a copy of the GNU Lesser General Public License
20 : along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 : #ifndef __PLUMED_core_CLToolRegister_h
23 : #define __PLUMED_core_CLToolRegister_h
24 :
25 : #include <string>
26 : #include <map>
27 : #include <set>
28 : #include <vector>
29 : #include <iosfwd>
30 : #include "tools/Keywords.h"
31 :
32 : namespace PLMD {
33 :
34 : class CLTool;
35 : class CLToolOptions;
36 :
37 : /// Same as ActionRegister, but for CLTools
38 1607 : class CLToolRegister {
39 : /// Write on a stream the list of registered directives
40 : friend std::ostream &operator<<(std::ostream &,const CLToolRegister&);
41 : /// Pointer to a function which, given the options, create an CLTool
42 : typedef CLTool*(*creator_pointer)(const CLToolOptions&);
43 : /// Pointer to a function which, returns the keywords allowed
44 : typedef void(*keywords_pointer)(Keywords&);
45 : /// Map cltool to a function which creates the related object
46 : std::map<std::string,creator_pointer> m;
47 : /// Map cltool name to the keywords for this function
48 : std::map<std::string,Keywords> mk;
49 : /// Set of disabled cltools (which were registered more than once)
50 : std::set<std::string> disabled;
51 : public:
52 : /// Register a new class.
53 : /// \param key The name of the directive to be used in the input file
54 : /// \param cp A pointer to a function which creates an object of that class
55 : /// \param kp A pointer to a function which returns the allowed keywords
56 : void add(std::string key,creator_pointer cp,keywords_pointer kp);
57 : /// Verify if a directive is present in the register
58 : bool check(std::string cltool);
59 : /// Create an CLTool of the type indicated in the options
60 : /// \param ao object containing information for initialization, such as the full input line, a pointer to PlumedMain, etc
61 : CLTool* create(const CLToolOptions&ao);
62 : void remove(creator_pointer);
63 : ~CLToolRegister();
64 : /// Returns a list of the allowed CLTools
65 : std::vector<std::string> list()const;
66 : /// Print out the instructions for using the tool in html ready for input into the manual
67 : bool printManual(const std::string& cltool);
68 : };
69 :
70 : /// Function returning a reference to the CLToolRegister.
71 : /// \relates CLToolRegister
72 : /// To avoid problems with order of initialization, this function contains
73 : /// a static CLToolRegister which is built the first time the function is called.
74 : /// In this manner, it is always initialized before it's used
75 : CLToolRegister& cltoolRegister();
76 :
77 : std::ostream & operator<<(std::ostream &log,const CLToolRegister&ar);
78 :
79 : }
80 :
81 :
82 : /// Shortcut for CLTool registration
83 : /// \relates PLMD::CLToolRegister
84 : /// For easier registration, this file also provides a macro PLUMED_REGISTER_CLTOOL.
85 : /// \param classname the name of the class to be registered
86 : /// \param directive a string containing the corresponding directive
87 : /// This macro should be used in the .cpp file of the corresponding class
88 : #define PLUMED_REGISTER_CLTOOL(classname,directive) \
89 : static class classname##RegisterMe{ \
90 : static PLMD::CLTool* create(const PLMD::CLToolOptions&ao){return new classname(ao);} \
91 : public: \
92 : classname##RegisterMe(){PLMD::cltoolRegister().add(directive,create,classname::registerKeywords);} \
93 : ~classname##RegisterMe(){PLMD::cltoolRegister().remove(create);} \
94 : } classname##RegisterMeObject;
95 :
96 :
97 : #endif
98 :
|