All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GenTemplate.cpp
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 #include "CLTool.h"
23 #include "CLToolRegister.h"
24 #include "tools/Tools.h"
25 //#include "PlumedConfig.h"
26 #include "core/ActionRegister.h"
27 #include <cstdio>
28 #include <string>
29 #include <vector>
30 #include <iostream>
31 
32 using namespace std;
33 
34 namespace PLMD {
35 namespace cltools{
36 
37 //+PLUMEDOC TOOLS gentemplate
38 /*
39 gentemplate is a tool that you can use to construct template inputs for the various
40 actions
41 
42 The templates generated by this tool are primarily for use with Toni Giorgino's vmd gui. It may be
43 useful however to use this tool as a quick aid memoir.
44 
45 \par Examples
46 
47 The following generates template input for the action DISTANCE.
48 \verbatim
49 plumed gentemplate --action DISTANCE
50 \endverbatim
51 
52 
53 */
54 //+ENDPLUMEDOC
55 
57 public CLTool
58 {
59 public:
60  static void registerKeywords( Keywords& keys );
61  GenTemplate(const CLToolOptions& co );
62  int main(FILE* in, FILE*out,Communicator& pc);
63  string description()const{
64  return "print out a template input for a particular action";
65  }
66 };
67 
68 PLUMED_REGISTER_CLTOOL(GenTemplate,"gentemplate")
69 
70 void GenTemplate::registerKeywords( Keywords& keys ){
71  CLTool::registerKeywords( keys );
72  keys.add("optional","--action","print the template for this particular action");
73  keys.addFlag("--list",false,"print a list of the available actions");
74  keys.addFlag("--include-optional",false,"also print optional modifiers");
75 }
76 
77 GenTemplate::GenTemplate(const CLToolOptions& co ):
78 CLTool(co)
79 {
81 }
82 
83 int GenTemplate::main(FILE* in, FILE*out,Communicator& pc){
84 
85  std::string action;
86  bool list_templates=false;
87  parseFlag("--list",list_templates);
88 
89  if(list_templates) {
90  std::cerr<<actionRegister()<<"\n";
91  return 0;
92  } else if(parse("--action",action)) {
93  bool include_optional;
94  parseFlag("--include-optional",include_optional);
95  if( !actionRegister().printTemplate(action,include_optional) ){
96  error("there is no registered action named " + action);
97  return 1;
98  }
99  } else return 1;
100 
101 
102 
103  return 0;
104 }
105 }
106 
107 } // End of namespace
ActionRegister & actionRegister()
int main(int argc, char **argv)
This main uses only the interface published in Plumed.h.
Definition: main.cpp:38
Class containing wrappers to MPI.
Definition: Communicator.h:44
STL namespace.
This is the abstract base class to use for implementing new command line tool, within it there is inf...
Definition: CLTool.h:55
This class holds the keywords and their documentation.
Definition: Keywords.h:36
int main(FILE *in, FILE *out, Communicator &pc)
virtual function mapping to the specific main for each tool
Definition: GenTemplate.cpp:83
bool parse(const std::string &key, T &t)
Get the value of one of the command line arguments.
Definition: CLTool.h:104
void parseFlag(const std::string &key, bool &t)
Find out whether one of the command line flags is present or not.
Definition: CLTool.cpp:51
string description() const
virtual function returning a one-line descriptor for the tool
Definition: GenTemplate.cpp:63
enum PLMD::CLTool::@0 inputdata
How is the input specified on the command line or in an input file.
void error(const std::string &msg)
Crash the command line tool with an error.
Definition: CLTool.cpp:206