LCOV - code coverage report
Current view: top level - core - CLToolRegister.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 1 1 100.0 %
Date: 2018-12-19 07:49:13 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2018 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_core_CLToolRegister_h
      23             : #define __PLUMED_core_CLToolRegister_h
      24             : 
      25             : #include <string>
      26             : #include <map>
      27             : #include <set>
      28             : #include <vector>
      29             : #include <iosfwd>
      30             : #include "tools/Keywords.h"
      31             : 
      32             : namespace PLMD {
      33             : 
      34             : class CLTool;
      35             : class CLToolOptions;
      36             : 
      37             : /// Same as ActionRegister, but for CLTools
      38         841 : class CLToolRegister {
      39             : /// Write on a stream the list of registered directives
      40             :   friend std::ostream &operator<<(std::ostream &,const CLToolRegister&);
      41             : /// Pointer to a function which, given the options, create an CLTool
      42             :   typedef CLTool*(*creator_pointer)(const CLToolOptions&);
      43             : /// Pointer to a function which, returns the keywords allowed
      44             :   typedef void(*keywords_pointer)(Keywords&);
      45             : /// Map cltool to a function which creates the related object
      46             :   std::map<std::string,creator_pointer> m;
      47             : /// Map cltool name to the keywords for this function
      48             :   std::map<std::string,Keywords> mk;
      49             : /// Iterator over the map
      50             :   typedef std::map<std::string,creator_pointer>::iterator mIterator;
      51             : /// Iterator over the map
      52             :   typedef std::map<std::string,creator_pointer>::const_iterator const_mIterator;
      53             : /// Set of disabled cltools (which were registered more than once)
      54             :   std::set<std::string> disabled;
      55             : public:
      56             : /// Register a new class.
      57             : /// \param key The name of the directive to be used in the input file
      58             : /// \param cp  A pointer to a function which creates an object of that class
      59             : /// \param kp  A pointer to a function which returns the allowed keywords
      60             :   void add(std::string key,creator_pointer cp,keywords_pointer kp);
      61             : /// Verify if a directive is present in the register
      62             :   bool check(std::string cltool);
      63             : /// Create an CLTool of the type indicated in the options
      64             : /// \param ao object containing information for initialization, such as the full input line, a pointer to PlumedMain, etc
      65             :   CLTool* create(const CLToolOptions&ao);
      66             :   void remove(creator_pointer);
      67             :   ~CLToolRegister();
      68             : /// Returns a list of the allowed CLTools
      69             :   std::vector<std::string> list()const;
      70             : /// Print out the instructions for using the tool in html ready for input into the manual
      71             :   bool printManual(const std::string& cltool);
      72             : };
      73             : 
      74             : /// Function returning a reference to the CLToolRegister.
      75             : /// \relates CLToolRegister
      76             : /// To avoid problems with order of initialization, this function contains
      77             : /// a static CLToolRegister which is built the first time the function is called.
      78             : /// In this manner, it is always initialized before it's used
      79             : CLToolRegister& cltoolRegister();
      80             : 
      81             : std::ostream & operator<<(std::ostream &log,const CLToolRegister&ar);
      82             : 
      83             : }
      84             : 
      85             : 
      86             : /// Shortcut for CLTool registration
      87             : /// \relates PLMD::CLToolRegister
      88             : /// For easier registration, this file also provides a macro PLUMED_REGISTER_CLTOOL.
      89             : /// \param classname the name of the class to be registered
      90             : /// \param directive a string containing the corresponding directive
      91             : /// This macro should be used in the .cpp file of the corresponding class
      92             : #define PLUMED_REGISTER_CLTOOL(classname,directive) \
      93             :   static class classname##RegisterMe{ \
      94             :     static PLMD::CLTool* create(const PLMD::CLToolOptions&ao){return new classname(ao);} \
      95             :   public: \
      96             :     classname##RegisterMe(){PLMD::cltoolRegister().add(directive,create,classname::registerKeywords);} \
      97             :     ~classname##RegisterMe(){PLMD::cltoolRegister().remove(create);} \
      98             :   } classname##RegisterMeObject;
      99             : 
     100             : 
     101             : #endif
     102             : 

Generated by: LCOV version 1.13