LCOV - code coverage report
Current view: top level - tools - Keywords.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 16 18 88.9 %
Date: 2026-03-30 13:16:06 Functions: 2 2 100.0 %

          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             : #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             : 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             :     bool isCompulsory() const {
      44       32736 :       return (style==compulsory);
      45             :     }
      46             :     bool isFlag() const {
      47       44222 :       return (style==flag);
      48             :     }
      49             :     bool isOptional() const {
      50       33764 :       return (style==optional);
      51             :     }
      52             :     bool isAtomList() const {
      53      693625 :       return (style==atoms);
      54             :     }
      55             :     bool isVessel() const {
      56       31747 :       return (style==vessel);
      57             :     }
      58      875721 :     std::string toString() const {
      59      875721 :       if(style==compulsory) {
      60       63580 :         return "compulsory";
      61             :       } else if(style==optional) {
      62      208413 :         return "optional";
      63             :       } else if(style==atoms) {
      64      166537 :         return "atoms";
      65             :       } else if(style==flag) {
      66      334037 :         return "flag";
      67             :       } else if(style==hidden) {
      68       78864 :         return "hidden";
      69             :       } else if(style==vessel) {
      70       24290 :         return "vessel";
      71             :       } else {
      72           0 :         plumed_assert(0);
      73             :       }
      74             :       return "";
      75             :     }
      76             :   };
      77             :   friend class Action;
      78             : private:
      79             : /// Is this an action or driver (this bool affects what style==atoms does in print)
      80             :   bool isaction;
      81             : /// This allows us to overwrite the behavior of the atoms type in analysis actions
      82             :   bool isatoms;
      83             : /// The names of the allowed keywords
      84             :   std::vector<std::string> keys;
      85             : /// The names of the reserved keywords
      86             :   std::vector<std::string> reserved_keys;
      87             : /// Whether the keyword is compulsory, optional...
      88             :   std::map<std::string,KeyType> types;
      89             : /// Do we allow stuff like key1, key2 etc
      90             :   std::map<std::string,bool> allowmultiple;
      91             : /// The documentation for the keywords
      92             :   std::map<std::string,std::string> documentation;
      93             : /// The default values for the flags (are they on or of)
      94             :   std::map<std::string,bool> booldefs;
      95             : /// The default values (if there are default values) for compulsory keywords
      96             :   std::map<std::string,std::string> numdefs;
      97             : /// The tags for atoms - we use this so the manual can differentiate between different ways of specifying atoms
      98             :   std::map<std::string,std::string> atomtags;
      99             : /// The string that should be printed out to describe how the components work for this particular action
     100             :   std::string cstring;
     101             : /// The names of all the possible components for an action
     102             :   std::vector<std::string> cnames;
     103             : /// The keyword that turns on a particular component
     104             :   std::map<std::string,std::string> ckey;
     105             : /// The documentation for a particular component
     106             :   std::map<std::string,std::string> cdocs;
     107             : /// Print the documentation for the jth keyword in html
     108             :   void print_html_item( const std::string& ) const;
     109             : public:
     110             : /// Constructor
     111      108087 :   Keywords() : isaction(true), isatoms(true) {}
     112             : ///
     113             :   void isDriver() {
     114        9190 :     isaction=false;
     115             :   }
     116             : ///
     117             :   void isAnalysis() {
     118         189 :     isatoms=false;
     119             :   }
     120             : /// find out whether flag key is on or off by default.
     121             :   bool getLogicalDefault(const std::string & key, bool& def ) const ;
     122             : /// Get the value of the default for the keyword named key
     123             :   bool getDefaultValue(const std::string & key, std::string& def ) const ;
     124             : /// Return the number of defined keywords
     125             :   unsigned size() const;
     126             : /// Check if numbered keywords are allowed for this action
     127             :   bool numbered( const std::string & k ) const ;
     128             : /// Return the ith keyword
     129             :   std::string getKeyword( const unsigned i ) const ;
     130             : /// Get the documentation for a particular keyword
     131             :   std::string getKeywordDocs( const std::string& key ) const ;
     132             : /// Print the documentation to the log file (used by PLMD::Action::error)
     133             :   void print( Log& log ) const ;
     134             : /// Print the documentation to a file (use by PLUMED::CLTool::readCommandLineArgs)
     135             :   void print( FILE* out ) const ;
     136             : /// Get the help string
     137             :   std::string getHelpString() const ;
     138             : /// Print a file containing the list of keywords for a particular action (used for spell checking)
     139             :   void print_spelling() const ;
     140             : /// Reserve a keyword
     141             :   void reserve( const std::string & t, const std::string & k, const std::string & d );
     142             : /// Reserve a flag
     143             :   void reserveFlag( const std::string & k, const bool def, const std::string & d );
     144             : /// Use one of the reserved keywords
     145             :   void use( const std::string  & k );
     146             : /// Get the ith keyword
     147             :   std::string get( const unsigned k ) const ;
     148             : /// Add a new keyword of type t with name k and description d
     149             :   void add( const std::string & t, const std::string & k, const std::string & d );
     150             : /// Add a new compulsory keyword (t must equal compulsory) with name k, default value def and description d
     151             :   void add( const std::string & t, const std::string & k, const std::string & def, const std::string & d );
     152             : /// 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
     153             :   void addFlag( const std::string & k, const bool def, const std::string & d );
     154             : /// Remove the keyword with name k
     155             :   void remove( const std::string & k );
     156             : /// Check if there is a keyword with name k
     157             :   bool exists( const std::string & k ) const ;
     158             : /// Check the keyword k has been reserved
     159             :   bool reserved( const std::string & k ) const ;
     160             : /// Get the type for the keyword with string k
     161             :   std::string getStyle( const std::string & k ) const ;
     162             : /// Check if the keyword with name k has style t
     163             :   bool style( const std::string & k, const std::string & t ) const ;
     164             : /// Print an html version of the documentation
     165             :   void print_html() const ;
     166             : /// Print keywords in form readable by vim
     167             :   void print_vim() const ;
     168             : /// Print the template version for the documentation
     169             :   void print_template( const std::string& actionname, bool include_optional) const ;
     170             : /// Change the style of a keyword
     171             :   void reset_style( const std::string & k, const std::string & style );
     172             : /// Add keywords from one keyword object to another
     173             :   void add( const Keywords& keys );
     174             : /// Copy the keywords data
     175             :   void copyData( std::vector<std::string>& kk, std::vector<std::string>& rk, std::map<std::string,KeyType>& tt, std::map<std::string,bool>& am,
     176             :                  std::map<std::string,std::string>& docs, std::map<std::string,bool>& bools, std::map<std::string,std::string>& nums,
     177             :                  std::map<std::string,std::string>& atags, std::vector<std::string>& cnam, std::map<std::string,std::string>& ck,
     178             :                  std::map<std::string,std::string>& cd ) const ;
     179             : /// Clear everything from the keywords object.
     180             : /// Not actually needed if your Keywords object is going out of scope.
     181             :   void destroyData();
     182             : /// Set the text that introduces how the components for this action are introduced
     183             :   void setComponentsIntroduction( const std::string& instr );
     184             : /// Add a potential component which can be output by this particular action
     185             :   void addOutputComponent( const std::string& name, const std::string& key, const std::string& descr );
     186             : /// Has a component with this name been added?
     187             :   bool outputComponentExists( const std::string& name, const bool& custom ) const ;
     188             : /// Get the flag that forces this component to be calculated
     189             :   std::string getOutputComponentFlag( const std::string& name ) const ;
     190             : /// Get the description of this component
     191             :   std::string getOutputComponentDescription( const std::string& name ) const ;
     192             : /// Get the full list of output components
     193             :   std::vector<std::string> getOutputComponents() const ;
     194             : /// Get the description of a particular keyword
     195             :   std::string getKeywordDescription( const std::string& name ) const ;
     196             : /// Remove a component with a particular name from the keywords
     197             :   void removeComponent( const std::string& name );
     198             : /// Reference to keys
     199             :   std::vector<std::string> getKeys() const {
     200           0 :     return keys;
     201             :   }
     202             : /// Get the description of a particular keyword
     203             :   std::string getTooltip( const std::string& name ) const ;
     204             : };
     205             : 
     206             : }
     207             : 
     208             : #endif

Generated by: LCOV version 1.16