Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
PLMD::CLToolMain Class Reference

Class providing cmd() access to command line tools. More...

#include <CLToolMain.h>

Inheritance diagram for PLMD::CLToolMain:
Inheritance graph
[legend]

Public Member Functions

 CLToolMain ()
 
 ~CLToolMain ()
 
void cmd (const char *key, const TypesafePtr &val=nullptr)
 This is needed to avoid ambiguities. More...
 
virtual void cmd (const std::string &key, const TypesafePtr &val=nullptr)
 This is the legacy method we used in older plumed versions, so it is still possible. More...
 
void cmd (std::string_view key, const TypesafePtr &val, const std::size_t *shape)
 
template<typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void cmd (std::string_view key, const TypesafePtr &val, I nelem, const std::size_t *shape=nullptr)
 
void cmd (std::string_view key, const TypesafePtr &val, std::initializer_list< SizeLike > shape)
 
void cmd (std::string_view key, const TypesafePtr &val=nullptr) override
 Send messages to the CLToolMain. More...
 

Static Private Member Functions

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. More...
 

Private Attributes

int argc
 arguments for command-line mode: More...
 
std::vector< std::string > argv
 arguments for command-line mode: More...
 
Communicatorcomm =*comm_fwd
 
ForwardDecl< Communicatorcomm_fwd
 
FILE * in
 
FILE * out
 

Detailed Description

Class providing cmd() access to command line tools.

This class provides an interface using the "cmd()" syntax to all the command-line tools. It is only accessed via the cmd() function, which can be used to set the arguments, communicators and IO descriptors and to run the tool. It can run all the tools registered via the PLUMED_REGISTER_CLTOOL macro, or the scripts which are located in PLUMED_ROOT/scripts.

A typical usage is:

#include "CLToolMain.h"
int main(int argc,char**argv){
  PLMD::CLToolMain cltoolMain;
  cltoolMain.cmd("setArgc",&argc);
  cltoolMain.cmd("setArgv",argv);
  int ret;
  cltoolMain.cmd("run",&ret);
  return ret;
}

This will run the tool registered with name argv[1] with options argv[2]...argv[argc-1].

This class is also used in the PlumedMain class to provide the same functionalities through the external plumed interface, which is available also for C and FORTRAN. Thus, the preferred approach is to do something like

#include "Plumed.h"
int main(int argc,char**argv){
  PLMD::Plumed p;
  p.cmd("CLTool setArgc",&argc);
  p.cmd("CLTool setArgv",argv);
  int ret;
  p.cmd("CLTool run",&ret);
  return ret;
}

See the file main.cpp for a similar example.

Constructor & Destructor Documentation

◆ CLToolMain()

PLMD::CLToolMain::CLToolMain ( )

◆ ~CLToolMain()

PLMD::CLToolMain::~CLToolMain ( )

Member Function Documentation

◆ cmd() [1/6]

void PLMD::WithCmd::cmd ( const char *  key,
const TypesafePtr val = nullptr 
)
inlineinherited

This is needed to avoid ambiguities.

◆ cmd() [2/6]

virtual void PLMD::WithCmd::cmd ( const std::string &  key,
const TypesafePtr val = nullptr 
)
inlinevirtualinherited

This is the legacy method we used in older plumed versions, so it is still possible.

If this is not overridden, it will call the preferred method

◆ cmd() [3/6]

void PLMD::WithCmd::cmd ( std::string_view  key,
const TypesafePtr val,
const std::size_t *  shape 
)
inlineinherited

◆ cmd() [4/6]

template<typename I , typename std::enable_if< std::is_integral< I >::value, int >::type = 0>
void PLMD::WithCmd::cmd ( std::string_view  key,
const TypesafePtr val,
nelem,
const std::size_t *  shape = nullptr 
)
inlineinherited

◆ cmd() [5/6]

void PLMD::WithCmd::cmd ( std::string_view  key,
const TypesafePtr val,
std::initializer_list< SizeLike shape 
)
inlineinherited

◆ cmd() [6/6]

void PLMD::CLToolMain::cmd ( std::string_view  key,
const TypesafePtr val = nullptr 
)
overridevirtual

Send messages to the CLToolMain.

Reimplemented from PLMD::WithCmd.

◆ run()

int PLMD::CLToolMain::run ( int  argc,
char **  argv,
FILE *  in,
FILE *  out,
Communicator pc 
)
staticprivate

This is the entry point to the command line tools included in the plumed library.

Member Data Documentation

◆ argc

int PLMD::CLToolMain::argc
private

arguments for command-line mode:

◆ argv

std::vector<std::string> PLMD::CLToolMain::argv
private

arguments for command-line mode:

◆ comm

Communicator& PLMD::CLToolMain::comm =*comm_fwd
private

◆ comm_fwd

ForwardDecl<Communicator> PLMD::CLToolMain::comm_fwd
private

◆ in

FILE* PLMD::CLToolMain::in
private

◆ out

FILE* PLMD::CLToolMain::out
private

The documentation for this class was generated from the following files: