LCOV - code coverage report
Current view: top level - tools - Keywords.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 15 16 93.8 %
Date: 2020-11-18 11:20:57 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2019 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             : #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      330984 : class Keywords {
      37             : /// This class lets me pass keyword types easily
      38             :   class KeyType {
      39             :   public:
      40             :     enum {hidden,compulsory,flag,optional,atoms,vessel} style;
      41             :     explicit KeyType( const std::string& type );
      42             :     void setStyle( const std::string& type );
      43        5612 :     bool isCompulsory() const { return (style==compulsory); }
      44        9338 :     bool isFlag() const { return (style==flag); }
      45        5953 :     bool isOptional() const { return (style==optional); }
      46      223698 :     bool isAtomList() const { return (style==atoms); }
      47        6581 :     bool isVessel() const { return (style==vessel); }
      48      406814 :     std::string toString() const {
      49      406814 :       if(style==compulsory) return "compulsory";
      50      368452 :       else if(style==optional) return "optional";
      51      262428 :       else if(style==atoms) return "atoms";
      52      167588 :       else if(style==flag) return "flag";
      53       70213 :       else if(style==hidden) return "hidden";
      54       19481 :       else if(style==vessel) return "vessel";
      55           0 :       else plumed_assert(0);
      56             :       return "";
      57             :     }
      58             :   };
      59             :   friend class Action;
      60             : private:
      61             : /// Is this an action or driver (this bool affects what style==atoms does in print)
      62             :   bool isaction;
      63             : /// The names of the allowed keywords
      64             :   std::vector<std::string> keys;
      65             : /// The names of the reserved keywords
      66             :   std::vector<std::string> reserved_keys;
      67             : /// Whether the keyword is compulsory, optional...
      68             :   std::map<std::string,KeyType> types;
      69             : /// Do we allow stuff like key1, key2 etc
      70             :   std::map<std::string,bool> allowmultiple;
      71             : /// The documentation for the keywords
      72             :   std::map<std::string,std::string> documentation;
      73             : /// The default values for the flags (are they on or of)
      74             :   std::map<std::string,bool> booldefs;
      75             : /// The default values (if there are default values) for compulsory keywords
      76             :   std::map<std::string,std::string> numdefs;
      77             : /// The tags for atoms - we use this so the manual can differentiate between different ways of specifying atoms
      78             :   std::map<std::string,std::string> atomtags;
      79             : /// The string that should be printed out to describe how the components work for this particular action
      80             :   std::string cstring;
      81             : /// The names of all the possible components for an action
      82             :   std::vector<std::string> cnames;
      83             : /// The keyword that turns on a particular component
      84             :   std::map<std::string,std::string> ckey;
      85             : /// The documentation for a particular component
      86             :   std::map<std::string,std::string> cdocs;
      87             : /// Print the documentation for the jth keyword in html
      88             :   void print_html_item( const std::string& ) const;
      89             : /// Print a particular keyword
      90             :   void printKeyword( const std::string& j, Log& log ) const ;
      91             : /// Print a particular keyword (copy of the above that works with files)
      92             :   void printKeyword( const std::string& j, FILE* out ) const ;
      93             : public:
      94             : /// Constructor
      95       63414 :   Keywords() : isaction(true) {}
      96             : ///
      97        3226 :   void isDriver() { isaction=false; }
      98             : /// find out whether flag key is on or off by default.
      99             :   bool getLogicalDefault( std::string key, bool& def ) const ;
     100             : /// Get the value of the default for the keyword named key
     101             :   bool getDefaultValue( std::string key, std::string& def ) const ;
     102             : /// Return the number of defined keywords
     103             :   unsigned size() const;
     104             : /// Check if numbered keywords are allowed for this action
     105             :   bool numbered( const std::string & k ) const ;
     106             : /// Return the ith keyword
     107             :   std::string getKeyword( const unsigned i ) const ;
     108             : /// Print the documentation to the log file (used by PLMD::Action::error)
     109             :   void print( Log& log ) const ;
     110             : /// Print the documentation to a file (use by PLUMED::CLTool::readCommandLineArgs)
     111             :   void print( FILE* out ) const ;
     112             : /// Reserve a keyword
     113             :   void reserve( const std::string & t, const std::string & k, const std::string & d );
     114             : /// Reserve a flag
     115             :   void reserveFlag( const std::string & k, const bool def, const std::string & d );
     116             : /// Use one of the reserved keywords
     117             :   void use( const std::string  & k );
     118             : /// Get the ith keyword
     119             :   std::string get( const unsigned k ) const ;
     120             : /// Add a new keyword of type t with name k and description d
     121             :   void add( const std::string & t, const std::string & k, const std::string & d );
     122             : /// Add a new compulsory keyword (t must equal compulsory) with name k, default value def and description d
     123             :   void add( const std::string & t, const std::string & k, const std::string & def, const std::string & d );
     124             : /// 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
     125             :   void addFlag( const std::string & k, const bool def, const std::string & d );
     126             : /// Remove the keyword with name k
     127             :   void remove( const std::string & k );
     128             : /// Check if there is a keyword with name k
     129             :   bool exists( const std::string & k ) const ;
     130             : /// Check the keyword k has been reserved
     131             :   bool reserved( const std::string & k ) const ;
     132             : /// Check if the keyword with name k has style t
     133             :   bool style( const std::string & k, const std::string & t ) const ;
     134             : /// Print an html version of the documentation
     135             :   void print_html() const ;
     136             : /// Print keywords in form readable by vim
     137             :   void print_vim() const ;
     138             : /// Print the template version for the documenation
     139             :   void print_template( const std::string& actionname, bool include_optional) const ;
     140             : /// Change the style of a keyword
     141             :   void reset_style( const std::string & k, const std::string & style );
     142             : /// Add keywords from one keyword object to another
     143             :   void add( const Keywords& keys );
     144             : /// Copy the keywords data
     145             :   void copyData( std::vector<std::string>& kk, std::vector<std::string>& rk, std::map<std::string,KeyType>& tt, std::map<std::string,bool>& am,
     146             :                  std::map<std::string,std::string>& docs, std::map<std::string,bool>& bools, std::map<std::string,std::string>& nums,
     147             :                  std::map<std::string,std::string>& atags, std::vector<std::string>& cnam, std::map<std::string,std::string>& ck,
     148             :                  std::map<std::string,std::string>& cd ) const ;
     149             : /// Clear everything from the keywords object
     150             :   void destroyData();
     151             : /// Set the text that introduces how the components for this action are introduced
     152             :   void setComponentsIntroduction( const std::string& instr );
     153             : /// Add a potential component which can be output by this particular action
     154             :   void addOutputComponent( const std::string& name, const std::string& key, const std::string& descr );
     155             : /// Has a component with this name been added?
     156             :   bool outputComponentExists( const std::string& name, const bool& custom ) const ;
     157             : };
     158             : 
     159             : }
     160             : 
     161             : #endif

Generated by: LCOV version 1.13