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 : #include "CLToolRegister.h" 23 : #include "tools/Tools.h" 24 : #include "CLTool.h" 25 : #include <algorithm> 26 : #include <iostream> 27 : 28 : 29 : namespace PLMD { 30 : 31 210892 : CLToolRegister& cltoolRegister() { 32 216208 : static CLToolRegister ans; 33 210892 : return ans; 34 : } 35 : 36 0 : std::unique_ptr<CLTool> CLToolRegister::create(const CLToolOptions&ao) { 37 : std::vector<void*> images; // empty vector 38 0 : return create(images,ao); 39 : } 40 : 41 3859 : std::unique_ptr<CLTool> CLToolRegister::create(const std::vector<void*> & images,const CLToolOptions&ao) try { 42 3859 : if(ao.line.size()<1)return nullptr; 43 3859 : auto & content=get(images,ao.line[0]); 44 3859 : CLToolOptions nao( ao,content.keys ); 45 3859 : return content.create(nao); 46 0 : } catch (PLMD::ExceptionRegisterError &e ) { 47 : auto& toolName = e.getMissingKey(); 48 0 : throw e <<"CL tool \"" << toolName << "\" is not known."; 49 0 : } 50 : 51 101012 : CLToolRegister::ID CLToolRegister::add(std::string key,creator_pointer cp,keywords_pointer kp) { 52 : // this force each action to be registered as an uppercase string 53 435936 : if ( std::any_of( std::begin( key ), std::end( key ), []( char c ) { return ( std::isupper( c ) ); } ) ) plumed_error() << "CLTool: " + key + " cannot be registered, use only LOWERCASE characters"; 54 : 55 101012 : Keywords keys; kp(keys); 56 303036 : return RegisterBase::add(key,Pointers{cp,keys}); 57 101012 : } 58 : 59 1 : bool CLToolRegister::printManual( const std::string& cltool, const bool& spelling ) { 60 1 : if( spelling && check(cltool) ) { 61 0 : auto cl=get(cltool); 62 0 : cl.keys.print_spelling(); 63 : return true; 64 1 : } else if ( check(cltool) ) { 65 0 : auto cl=get(cltool); 66 0 : cl.keys.print_html(); 67 : return true; 68 : } else { 69 : return false; 70 : } 71 : } 72 : 73 0 : std::vector<std::string> CLToolRegister::getKeys(const std::string& cltool)const { 74 0 : if ( check(cltool) ) { 75 0 : auto cl=get(cltool); 76 : auto k=cl.keys.getKeys(); 77 0 : std::cerr<<k.size()<<"\n"; 78 0 : for(unsigned i=0; i<k.size(); i++) std::cerr<<k[i]<<"\n"; 79 : return k; 80 0 : } else { 81 : std::vector<std::string> empty; 82 : return empty; 83 0 : } 84 : } 85 : 86 : 87 4569 : std::vector<std::string> CLToolRegister::list()const { 88 4569 : return RegisterBase::getKeys(); 89 : } 90 : 91 : }