LCOV - code coverage report
Current view: top level - cltools - GenTemplate.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 13 23 56.5 %
Date: 2024-10-18 13:59:31 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2023 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             : #include "CLTool.h"
      23             : #include "core/CLToolRegister.h"
      24             : #include "tools/Tools.h"
      25             : #include "core/ActionRegister.h"
      26             : #include <cstdio>
      27             : #include <string>
      28             : #include <iostream>
      29             : 
      30             : namespace PLMD {
      31             : namespace cltools {
      32             : 
      33             : //+PLUMEDOC TOOLS gentemplate
      34             : /*
      35             : gentemplate is a tool that you can use to construct template inputs for the various actions
      36             : 
      37             : The templates generated by this tool are primarily for use with Toni Giorgino's VMD GUI.  It may be
      38             : useful however to use this tool as a quick aid memoir.
      39             : 
      40             : \par Examples
      41             : 
      42             : The following generates template input for the action DISTANCE.
      43             : \verbatim
      44             : plumed gentemplate --action DISTANCE
      45             : \endverbatim
      46             : 
      47             : 
      48             : */
      49             : //+ENDPLUMEDOC
      50             : 
      51             : class GenTemplate:
      52             :   public CLTool
      53             : {
      54             : public:
      55             :   static void registerKeywords( Keywords& keys );
      56             :   explicit GenTemplate(const CLToolOptions& co );
      57             :   int main(FILE* in, FILE*out,Communicator& pc) override;
      58           4 :   std::string description()const override {
      59           4 :     return "print out a template input for a particular action";
      60             :   }
      61             : };
      62             : 
      63       15952 : PLUMED_REGISTER_CLTOOL(GenTemplate,"gentemplate")
      64             : 
      65        5316 : void GenTemplate::registerKeywords( Keywords& keys ) {
      66        5316 :   CLTool::registerKeywords( keys );
      67       10632 :   keys.add("optional","--action","print the template for this particular action");
      68       10632 :   keys.addFlag("--list",false,"print a list of the available actions");
      69       10632 :   keys.addFlag("--include-optional",false,"also print optional modifiers");
      70        5316 : }
      71             : 
      72           4 : GenTemplate::GenTemplate(const CLToolOptions& co ):
      73           4 :   CLTool(co)
      74             : {
      75           4 :   inputdata=commandline;
      76           4 : }
      77             : 
      78           0 : int GenTemplate::main(FILE* in, FILE*out,Communicator& pc) {
      79             : 
      80             :   std::string action;
      81           0 :   bool list_templates=false;
      82           0 :   parseFlag("--list",list_templates);
      83             : 
      84           0 :   if(list_templates) {
      85           0 :     std::cerr<<actionRegister()<<"\n";
      86             :     return 0;
      87           0 :   } else if(parse("--action",action)) {
      88             :     bool include_optional;
      89           0 :     parseFlag("--include-optional",include_optional);
      90           0 :     if( !actionRegister().printTemplate(action,include_optional) ) {
      91           0 :       error("there is no registered action named " + action);
      92             :       return 1;
      93             :     }
      94             :   } else return 1;
      95             : 
      96             : 
      97             : 
      98           0 :   return 0;
      99             : }
     100             : }
     101             : 
     102             : } // End of namespace

Generated by: LCOV version 1.16