All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Keywords.h
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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_tools_Keywords_h
23 #define __PLUMED_tools_Keywords_h
24 #include <vector>
25 #include <string>
26 #include <set>
27 #include <map>
28 
29 #include "Exception.h"
30 
31 namespace PLMD{
32 
33 class Log;
34 
35 /// This class holds the keywords and their documentation
36 class Keywords{
37 /// This class lets me pass keyword types easily
38  class KeyType{
39  public:
41  KeyType( const std::string& type );
42  void setStyle( const std::string& type );
43  bool isCompulsory() const { return (style==compulsory); }
44  bool isFlag() const { return (style==flag); }
45  bool isOptional() const { return (style==optional); }
46  bool isAtomList() const { return (style==atoms); }
47  std::string toString() const {
48  if(style==compulsory) return "compulsory";
49  else if(style==optional) return "optional";
50  else if(style==atoms) return "atoms";
51  else if(style==flag) return "flag";
52  else if(style==hidden) return "hidden";
53  else plumed_assert(0);
54  return "";
55  }
56  };
57 friend class Action;
58 private:
59 /// The names of the allowed keywords
60  std::vector<std::string> keys;
61 /// The names of the reserved keywords
62  std::vector<std::string> reserved_keys;
63 /// Whether the keyword is compulsory, optional...
64  std::map<std::string,KeyType> types;
65 /// Do we allow stuff like key1, key2 etc
66  std::map<std::string,bool> allowmultiple;
67 /// The documentation for the keywords
68  std::map<std::string,std::string> documentation;
69 /// The default values for the flags (are they on or of)
70  std::map<std::string,bool> booldefs;
71 /// The default values (if there are default values) for compulsory keywords
72  std::map<std::string,std::string> numdefs;
73 /// The tags for atoms - we use this so the manual can differentiate between different ways of specifying atoms
74  std::map<std::string,std::string> atomtags;
75 /// The string that should be printed out to describe how the components work for this particular action
76  std::string cstring;
77 /// The names of all the possible components for an action
78  std::vector<std::string> cnames;
79 /// The keyword that turns on a particular component
80  std::map<std::string,std::string> ckey;
81 /// The documentation for a particular component
82  std::map<std::string,std::string> cdocs;
83 /// Print the documentation for the jth keyword in html
84  void print_html_item( const std::string& ) const;
85 /// Print a particular keyword
86  void printKeyword( const std::string& j, Log& log ) const ;
87 /// Print a particular keyword (copy of the above that works with files)
88  void printKeyword( const std::string& j, FILE* out ) const ;
89 public:
90 /// find out whether flag key is on or off by default.
91  bool getLogicalDefault( std::string key, bool& def ) const ;
92 /// Get the value of the default for the keyword named key
93  bool getDefaultValue( std::string key, std::string& def ) const ;
94 /// Return the number of defined keywords
95  unsigned size() const;
96 /// Check if numbered keywords are allowed for this action
97  bool numbered( const std::string & k ) const ;
98 /// Return the ith keyword
99  std::string getKeyword( const unsigned i ) const ;
100 /// Print the documentation to the log file (used by PLMD::Action::error)
101  void print( Log& log ) const ;
102 /// Print the documentation to a file (use by PLUMED::CLTool::readCommandLineArgs)
103  void print( FILE* out ) const ;
104 /// Reserve a keyword
105  void reserve( const std::string & t, const std::string & k, const std::string & d, const bool isvessel=false );
106 /// Reserve a flag
107  void reserveFlag( const std::string & k, const bool def, const std::string & d, const bool isvessel=false );
108 /// Use one of the reserved keywords
109  void use( const std::string & k );
110 /// Get the ith keyword
111  std::string get( const unsigned k ) const ;
112 /// Add a new keyword of type t with name k and description d
113  void add( const std::string & t, const std::string & k, const std::string & d );
114 /// Add a new compulsory keyword (t must equal compulsory) with name k, default value def and description d
115  void add( const std::string & t, const std::string & k, const std::string & def, const std::string & d );
116 /// Add a falg with name k that is by default on if def is true and off if def is false. d should provide a description of the flag
117  void addFlag( const std::string & k, const bool def, const std::string & d );
118 /// Remove the keyword with name k
119  void remove( const std::string & k );
120 /// Check if there is a keyword with name k
121  bool exists( const std::string & k ) const ;
122 /// Check the keyword k has been reserved
123  bool reserved( const std::string & k ) const ;
124 /// Check if the keyword with name k has style t
125  bool style( const std::string & k, const std::string & t ) const ;
126 /// Print an html version of the documentation
127  void print_html( const bool isaction ) const ;
128 /// Print the template version for the documenation
129  void print_template( const std::string& actionname, bool include_optional) const ;
130 /// Change the style of a keyword
131  void reset_style( const std::string & k, const std::string & style );
132 /// Add keywords from one keyword object to another
133  void add( const Keywords& keys );
134 /// Copy the keywords data
135  void copyData( std::vector<std::string>& kk, std::vector<std::string>& rk, std::map<std::string,KeyType>& tt, std::map<std::string,bool>& am,
136  std::map<std::string,std::string>& docs, std::map<std::string,bool>& bools, std::map<std::string,std::string>& nums,
137  std::map<std::string,std::string>& atags, std::vector<std::string>& cnam, std::map<std::string,std::string>& ck,
138  std::map<std::string,std::string>& cd ) const ;
139 /// Clear everything from the keywords object
140  void destroyData();
141 /// Set the text that introduces how the components for this action are introduced
142  void setComponentsIntroduction( const std::string& instr );
143 /// Add a potential component which can be output by this particular action
144  void addOutputComponent( const std::string& name, const std::string& key, const std::string& descr );
145 /// Has a component with this name been added?
146  bool outputComponentExists( const std::string& name, const bool& custom ) const ;
147 };
148 
149 }
150 
151 #endif
void setComponentsIntroduction(const std::string &instr)
Set the text that introduces how the components for this action are introduced.
Definition: Keywords.cpp:561
void copyData(std::vector< std::string > &kk, std::vector< std::string > &rk, std::map< std::string, KeyType > &tt, std::map< std::string, bool > &am, std::map< std::string, std::string > &docs, std::map< std::string, bool > &bools, std::map< std::string, std::string > &nums, std::map< std::string, std::string > &atags, std::vector< std::string > &cnam, std::map< std::string, std::string > &ck, std::map< std::string, std::string > &cd) const
Copy the keywords data.
Definition: Keywords.cpp:65
std::vector< std::string > keys
The names of the allowed keywords.
Definition: Keywords.h:60
void setStyle(const std::string &type)
Definition: Keywords.cpp:45
void destroyData()
Clear everything from the keywords object.
Definition: Keywords.cpp:554
std::vector< std::string > reserved_keys
The names of the reserved keywords.
Definition: Keywords.h:62
std::map< std::string, std::string > documentation
The documentation for the keywords.
Definition: Keywords.h:68
bool isAtomList() const
Definition: Keywords.h:46
std::string toString() const
Definition: Keywords.h:47
void add(const std::string &t, const std::string &k, const std::string &d)
Add a new keyword of type t with name k and description d.
Definition: Keywords.cpp:167
std::map< std::string, std::string > atomtags
The tags for atoms - we use this so the manual can differentiate between different ways of specifying...
Definition: Keywords.h:74
Class containing the log stream.
Definition: Log.h:35
This class lets me pass keyword types easily.
Definition: Keywords.h:38
bool isFlag() const
Definition: Keywords.h:44
bool getDefaultValue(std::string key, std::string &def) const
Get the value of the default for the keyword named key.
Definition: Keywords.cpp:543
std::string cstring
The string that should be printed out to describe how the components work for this particular action...
Definition: Keywords.h:76
void addOutputComponent(const std::string &name, const std::string &key, const std::string &descr)
Add a potential component which can be output by this particular action.
Definition: Keywords.cpp:565
bool isCompulsory() const
Definition: Keywords.h:43
void print_html_item(const std::string &) const
Print the documentation for the jth keyword in html.
Definition: Keywords.cpp:522
This class holds the keywords and their documentation.
Definition: Keywords.h:36
void printKeyword(const std::string &j, Log &log) const
Print a particular keyword.
Definition: Keywords.cpp:505
void print(Log &log) const
Print the documentation to the log file (used by PLMD::Action::error)
Definition: Keywords.cpp:461
bool numbered(const std::string &k) const
Check if numbered keywords are allowed for this action.
Definition: Keywords.cpp:217
Base class for all the input Actions.
Definition: Action.h:60
std::map< std::string, std::string > ckey
The keyword that turns on a particular component.
Definition: Keywords.h:80
std::map< std::string, KeyType > types
Whether the keyword is compulsory, optional...
Definition: Keywords.h:64
std::string getKeyword(const unsigned i) const
Return the ith keyword.
Definition: Keywords.cpp:234
void reserve(const std::string &t, const std::string &k, const std::string &d, const bool isvessel=false)
Reserve a keyword.
Definition: Keywords.cpp:110
bool style(const std::string &k, const std::string &t) const
Check if the keyword with name k has style t.
Definition: Keywords.cpp:223
void use(const std::string &k)
Use one of the reserved keywords.
Definition: Keywords.cpp:154
std::map< std::string, bool > booldefs
The default values for the flags (are they on or of)
Definition: Keywords.h:70
bool isOptional() const
Definition: Keywords.h:45
void print_template(const std::string &actionname, bool include_optional) const
Print the template version for the documenation.
Definition: Keywords.cpp:253
void reserveFlag(const std::string &k, const bool def, const std::string &d, const bool isvessel=false)
Reserve a flag.
Definition: Keywords.cpp:140
std::map< std::string, std::string > numdefs
The default values (if there are default values) for compulsory keywords.
Definition: Keywords.h:72
bool exists(const std::string &k) const
Check if there is a keyword with name k.
Definition: Keywords.cpp:239
bool reserved(const std::string &k) const
Check the keyword k has been reserved.
Definition: Keywords.cpp:246
std::map< std::string, bool > allowmultiple
Do we allow stuff like key1, key2 etc.
Definition: Keywords.h:66
std::map< std::string, std::string > cdocs
The documentation for a particular component.
Definition: Keywords.h:82
KeyType(const std::string &type)
Definition: Keywords.cpp:29
bool outputComponentExists(const std::string &name, const bool &custom) const
Has a component with this name been added?
Definition: Keywords.cpp:572
void print_html(const bool isaction) const
Print an html version of the documentation.
Definition: Keywords.cpp:294
bool getLogicalDefault(std::string key, bool &def) const
find out whether flag key is on or off by default.
Definition: Keywords.cpp:534
void reset_style(const std::string &k, const std::string &style)
Change the style of a keyword.
Definition: Keywords.cpp:161
enum PLMD::Keywords::KeyType::@5 style
std::vector< std::string > cnames
The names of all the possible components for an action.
Definition: Keywords.h:78
void addFlag(const std::string &k, const bool def, const std::string &d)
Add a falg with name k that is by default on if def is true and off if def is false. d should provide a description of the flag.
Definition: Keywords.cpp:193
unsigned size() const
Return the number of defined keywords.
Definition: Keywords.cpp:230