LCOV - code coverage report
Current view: top level - core - ActionRegister.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 46 73.9 %
Date: 2024-10-18 14:00:25 Functions: 7 9 77.8 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "ActionRegister.h"
      23             : #include "ModuleMap.h"
      24             : #include "Action.h"
      25             : #include <algorithm>
      26             : 
      27             : namespace PLMD {
      28             : 
      29     4742803 : ActionRegister& actionRegister() {
      30     4748119 :   static ActionRegister ans;
      31     4742803 :   return ans;
      32             : }
      33             : 
      34           0 : std::unique_ptr<Action> ActionRegister::create(const ActionOptions&ao) {
      35             :   std::vector<void*> images; // empty vector
      36           0 :   return create(images,ao);
      37             : }
      38             : 
      39       51206 : std::unique_ptr<Action> ActionRegister::create(const std::vector<void*> & images,const ActionOptions&ao) try {
      40       51206 :   if(ao.line.size()<1)return nullptr;
      41             : 
      42       51206 :   auto content=get(images,ao.line[0]);
      43       51204 :   Keywords keys; keys.thisactname = ao.line[0];
      44       51204 :   content.keys(keys);
      45       51204 :   ActionOptions nao( ao,keys );
      46       51204 :   auto fullPath=getFullPath(images,ao.line[0]);
      47             :   nao.setFullPath(fullPath);
      48       51204 :   return content.create(nao);
      49       51259 : } catch (PLMD::ExceptionRegisterError &e ) {
      50             :   auto& actionName = e.getMissingKey();
      51             :   e <<"Action \"" << actionName << "\" is not known.";
      52           2 :   if (getModuleMap().count(actionName)>0) {
      53             :     e << "\nAn Action named \""
      54             :       <<actionName
      55             :       <<"\" is available in module \""
      56           0 :       << getModuleMap().at(actionName)
      57             :       << "\".\nPlease consider installing PLUMED with that module enabled.";
      58             :   }
      59           2 :   throw e;
      60           2 : }
      61             : 
      62         439 : bool ActionRegister::printManual(const std::string& action, const bool& vimout, const bool& spellout) {
      63         439 :   if ( check(action) ) {
      64         438 :     Keywords keys; getKeywords( action, keys );
      65         438 :     if( vimout ) {
      66         438 :       printf("%s",action.c_str()); keys.print_vim(); printf("\n");
      67           0 :     } else if( spellout ) {
      68           0 :       keys.print_spelling();
      69             :     } else {
      70           0 :       keys.print_html();
      71             :     }
      72             :     return true;
      73         438 :   } else {
      74             :     return false;
      75             :   }
      76             : }
      77             : 
      78           0 : bool ActionRegister::printTemplate(const std::string& action, bool include_optional) {
      79             :   //no need to insert the try/catch block: check will ensure that action is known
      80           0 :   if( check(action) ) {
      81           0 :     Keywords keys; keys.thisactname = action;
      82           0 :     get(action).keys(keys);
      83           0 :     keys.print_template(action, include_optional);
      84             :     return true;
      85           0 :   } else {
      86             :     return false;
      87             :   }
      88             : }
      89             : 
      90           2 : std::vector<std::string> ActionRegister::getActionNames() const {
      91           2 :   return getKeys();
      92             : }
      93             : 
      94     2328421 : ActionRegister::ID ActionRegister::add(std::string key,creator_pointer cp,keywords_pointer kp) {
      95             :   // this force each action to be registered as an uppercase string
      96    12147107 :   if ( std::any_of( std::begin( key ), std::end( key ), []( char c ) { return ( std::islower( c ) ); } ) ) plumed_error() << "Action: " + key + " cannot be registered, use only UPPERCASE characters";
      97     4656842 :   return RegisterBase::add(key,Pointers{cp,kp});
      98             : }
      99             : 
     100       22979 : bool ActionRegister::getKeywords(const std::string& action, Keywords& keys) {
     101             :   //no need to insert the try/catch block: check will ensure that action is known
     102       22979 :   if(check(action)) {
     103       22979 :     keys.thisactname = action;
     104       22979 :     get(action).keys(keys);
     105       22979 :     return true;
     106             :   }
     107             :   return false;
     108             : }
     109             : 
     110          97 : void ActionRegister::getKeywords(const std::vector<void*> & images, const std::string& action, Keywords& keys) {
     111          97 :   auto content=get(images,action); keys.thisactname = action; content.keys(keys);
     112          97 : }
     113             : 
     114             : }

Generated by: LCOV version 1.16