LCOV - code coverage report
Current view: top level - core - CLToolRegister.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 2 2 100.0 %
Date: 2024-10-18 14:00:25 Functions: 0 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_core_CLToolRegister_h
      23             : #define __PLUMED_core_CLToolRegister_h
      24             : 
      25             : #include "RegisterBase.h"
      26             : #include "tools/Keywords.h"
      27             : 
      28             : namespace PLMD {
      29             : 
      30             : class CLTool;
      31             : class CLToolOptions;
      32             : 
      33      404040 : struct CLToolRegisterPointers {
      34             : /// Pointer to a function which, given the options, create an CLTool
      35             :   typedef std::unique_ptr<CLTool>(*creator_pointer)(const CLToolOptions&);
      36             : /// Pointer to a function which, returns the keywords allowed
      37             :   typedef void(*keywords_pointer)(Keywords&);
      38             :   creator_pointer create;
      39             :   Keywords keys;
      40             : };
      41             : 
      42             : 
      43             : /// Same as ActionRegister, but for CLTools
      44        5316 : class CLToolRegister :
      45             :   public RegisterBase<CLToolRegisterPointers> {
      46             :   typedef CLToolRegisterPointers::creator_pointer creator_pointer;
      47             :   typedef CLToolRegisterPointers::keywords_pointer keywords_pointer;
      48             :   typedef CLToolRegisterPointers Pointers;
      49             : 
      50             :   // this is necessary to avoid warnings on getKeys overload.
      51             :   // notice that RegisterBase<CLToolRegisterPointers>::getKeys returns
      52             :   // the list of keys (here: CLTools). conversely
      53             :   // CLToolRegister::getKeys(std::string name) returns the options
      54             :   // associated to CLTool name.
      55             :   // We hide the former here, which is actually implemented by list()
      56             :   // not to break existing code.
      57             :   using RegisterBase<CLToolRegisterPointers>::getKeys;
      58             : 
      59             : public:
      60             : /// Register a new class.
      61             : /// \param key The name of the directive to be used in the input file
      62             : /// \param cp  A pointer to a function which creates an object of that class
      63             : /// \param kp  A pointer to a function which returns the allowed keywords
      64             :   ID add(std::string key,creator_pointer cp,keywords_pointer kp);
      65             : /// Create an CLTool of the type indicated in the options
      66             : /// \param ao object containing information for initialization, such as the full input line, a pointer to PlumedMain, etc
      67             :   std::unique_ptr<CLTool> create(const CLToolOptions&ao);
      68             :   std::unique_ptr<CLTool> create(const std::vector<void*> & images,const CLToolOptions&ao);
      69             : /// Returns a list of the allowed CLTools
      70             :   std::vector<std::string> list()const;
      71             : /// Print out the instructions for using the tool in html ready for input into the manual
      72             :   bool printManual(const std::string& cltool,const bool& spelling);
      73             : /// Return all the keys of this cltool
      74             :   std::vector<std::string> getKeys(const std::string& cltool)const;
      75             : };
      76             : 
      77             : /// Function returning a reference to the CLToolRegister.
      78             : /// \relates CLToolRegister
      79             : /// To avoid problems with order of initialization, this function contains
      80             : /// a static CLToolRegister which is built the first time the function is called.
      81             : /// In this manner, it is always initialized before it's used
      82             : CLToolRegister& cltoolRegister();
      83             : 
      84             : }
      85             : 
      86             : 
      87             : /// Shortcut for CLTool registration
      88             : /// \relates PLMD::CLToolRegister
      89             : /// For easier registration, this file also provides a macro PLUMED_REGISTER_CLTOOL.
      90             : /// \param classname the name of the class to be registered
      91             : /// \param directive a string containing the corresponding directive
      92             : /// This macro should be used in the .cpp file of the corresponding class
      93             : #define PLUMED_REGISTER_CLTOOL(classname,directive) \
      94             :   namespace { class classname##RegisterMe{ \
      95             :     CLToolRegister::ID id; \
      96             :     static std::unique_ptr<CLTool> create(const CLToolOptions&ao) { \
      97             :       return std::make_unique<classname>(ao); \
      98             :     } \
      99             :   public: \
     100             :     classname##RegisterMe() : \
     101             :       id(PLMD::cltoolRegister().add(directive,create,classname::registerKeywords)) \
     102             :     {} \
     103             :     ~classname##RegisterMe(){PLMD::cltoolRegister().remove(id);} \
     104             :   } classname##RegisterMeObject; }
     105             : 
     106             : 
     107             : #endif
     108             : 

Generated by: LCOV version 1.16