All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CLToolMain.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_core_CLToolMain_h
23 #define __PLUMED_core_CLToolMain_h
24 #include <cstdio>
25 #include <vector>
26 #include <string>
27 #include "WithCmd.h"
28 
29 
30 namespace PLMD{
31 
32 class Communicator;
33 
34 /**
35 Class providing cmd() access to command line tools.
36 
37 This class provides an interface using the "cmd()" syntax to all the
38 command-line tools.
39 It is only accessed via the cmd() function, which can
40 be used to set the arguments, communicators and IO descriptors and
41 to run the tool.
42 It can run all the tools registered via the PLUMED_REGISTER_CLTOOL macro,
43 or the scripts which are located in PLUMED_ROOT/scripts.
44 
45 A typical usage is:
46 \verbatim
47 #include "CLToolMain.h"
48 int main(int argc,char**argv){
49  PLMD::CLToolMain cltoolMain;
50  cltoolMain.cmd("setArgc",&argc);
51  cltoolMain.cmd("setArgv",argv);
52  int ret;
53  cltoolMain.cmd("run",&ret);
54  return ret;
55 }
56 \endverbatim
57 This will run the tool registered with name argv[1] with options argv[2]...argv[argc-1].
58 
59 This class is also used in the \ref PlumedMain class to provide
60 the same functionalities through the external plumed interface, which
61 is available also for C and FORTRAN. Thus, the preferred approach is to do something like
62 \verbatim
63 #include "Plumed.h"
64 int main(int argc,char**argv){
65  PLMD::Plumed p;
66  p.cmd("CLTool setArgc",&argc);
67  p.cmd("CLTool setArgv",argv);
68  int ret;
69  p.cmd("CLTool run",&ret);
70  return ret;
71 }
72 \endverbatim
73 
74 See the file \ref main.cpp for a similar example.
75 
76 */
77 class CLToolMain:
78 public WithCmd
79 {
80 /// arguments for command-line mode:
81  int argc;
82 /// arguments for command-line mode:
83  std::vector<std::string> argv;
84  FILE*in;
85  FILE*out;
87  static int run(int argc, char **argv,FILE*in,FILE*out,Communicator&pc);
88 public:
89  CLToolMain();
90  ~CLToolMain();
91 /**
92 Send messages to the CLToolMain.
93 */
94  void cmd(const std::string& key,void*val=NULL);
95 };
96 
97 }
98 
99 
100 #endif
Communicator & comm
Definition: CLToolMain.h:86
Class containing wrappers to MPI.
Definition: Communicator.h:44
static int run(int argc, char **argv, FILE *in, FILE *out, Communicator &pc)
This is the entry point to the command line tools included in the plumed library. ...
Definition: CLToolMain.cpp:99
void cmd(const std::string &key, void *val=NULL)
Send messages to the CLToolMain.
Definition: CLToolMain.cpp:53
std::vector< std::string > argv
arguments for command-line mode:
Definition: CLToolMain.h:83
Base for classes with cmd() method.
Definition: WithCmd.h:34
int argc
arguments for command-line mode:
Definition: CLToolMain.h:81
Class providing cmd() access to command line tools.
Definition: CLToolMain.h:77