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 5252278 : ActionRegister& actionRegister() { 30 5258161 : static ActionRegister ans; 31 5252278 : 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 51076 : std::unique_ptr<Action> ActionRegister::create(const std::vector<void*> & images,const ActionOptions&ao) try { 40 51076 : if(ao.line.size()<1) { 41 : return nullptr; 42 : } 43 : 44 51076 : auto content=get(images,ao.line[0]); 45 51074 : Keywords keys; 46 : keys.thisactname = ao.line[0]; 47 51074 : content.keys(keys); 48 51074 : ActionOptions nao( ao,keys ); 49 51074 : auto fullPath=getFullPath(images,ao.line[0]); 50 : nao.setFullPath(fullPath); 51 51074 : return content.create(nao); 52 51129 : } catch (PLMD::ExceptionRegisterError &e ) { 53 : auto& actionName = e.getMissingKey(); 54 : e <<"Action \"" << actionName << "\" is not known."; 55 2 : if (getModuleMap().count(actionName)>0) { 56 : e << "\nAn Action named \"" 57 : <<actionName 58 : <<"\" is available in module \"" 59 0 : << getModuleMap().at(actionName) 60 : << "\".\nPlease consider installing PLUMED with that module enabled."; 61 : } 62 2 : throw e; 63 2 : } 64 : 65 880 : bool ActionRegister::printManual(const std::string& action, const bool& vimout, const bool& spellout) { 66 880 : if ( check(action) ) { 67 878 : Keywords keys; 68 878 : getKeywords( action, keys ); 69 878 : if( vimout ) { 70 : printf("%s",action.c_str()); 71 878 : keys.print_vim(); 72 : printf("\n"); 73 0 : } else if( spellout ) { 74 0 : keys.print_spelling(); 75 : } else { 76 0 : keys.print_html(); 77 : } 78 : return true; 79 878 : } else { 80 : return false; 81 : } 82 : } 83 : 84 0 : bool ActionRegister::printTemplate(const std::string& action, bool include_optional) { 85 : //no need to insert the try/catch block: check will ensure that action is known 86 0 : if( check(action) ) { 87 0 : Keywords keys; 88 : keys.thisactname = action; 89 0 : get(action).keys(keys); 90 0 : keys.print_template(action, include_optional); 91 : return true; 92 0 : } else { 93 : return false; 94 : } 95 : } 96 : 97 3 : std::vector<std::string> ActionRegister::getActionNames() const { 98 3 : return getKeys(); 99 : } 100 : 101 2582650 : ActionRegister::ID ActionRegister::add(std::string key,creator_pointer cp,keywords_pointer kp) { 102 : // this force each action to be registered as an uppercase string 103 2582650 : if ( std::any_of( std::begin( key ), std::end( key ), []( char c ) { 104 10871818 : return ( std::islower( c ) ) 105 : ; 106 0 : } ) ) plumed_error() << "Action: " + key + " cannot be registered, use only UPPERCASE characters"; 107 5165300 : return RegisterBase::add(key,Pointers{cp,kp}); 108 : } 109 : 110 23648 : bool ActionRegister::getKeywords(const std::string& action, Keywords& keys) { 111 : //no need to insert the try/catch block: check will ensure that action is known 112 23648 : if(check(action)) { 113 23648 : keys.thisactname = action; 114 23648 : get(action).keys(keys); 115 23648 : return true; 116 : } 117 : return false; 118 : } 119 : 120 97 : void ActionRegister::getKeywords(const std::vector<void*> & images, const std::string& action, Keywords& keys) { 121 97 : auto content=get(images,action); 122 97 : keys.thisactname = action; 123 97 : content.keys(keys); 124 97 : } 125 : 126 : }