LCOV - code coverage report
Current view: top level - core - CLToolRegister.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 20 38 52.6 %
Date: 2026-03-30 11:13:23 Functions: 5 7 71.4 %

          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      233949 : CLToolRegister& cltoolRegister() {
      32      239832 :   static CLToolRegister ans;
      33      233949 :   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        4390 : std::unique_ptr<CLTool> CLToolRegister::create(const std::vector<void*> & images,const CLToolOptions&ao) try {
      42        4390 :   if(ao.line.size()<1) {
      43             :     return nullptr;
      44             :   }
      45        4390 :   auto & content=get(images,ao.line[0]);
      46        4390 :   CLToolOptions nao( ao,content.keys );
      47        4390 :   return content.create(nao);
      48           0 : } catch (PLMD::ExceptionRegisterError &e ) {
      49             :   auto& toolName = e.getMissingKey();
      50           0 :   throw e <<"CL tool \"" << toolName << "\" is not known.";
      51           0 : }
      52             : 
      53      111782 : CLToolRegister::ID CLToolRegister::add(std::string key,creator_pointer cp,keywords_pointer kp) {
      54             :   // this force each action to be registered as an uppercase string
      55      111782 :   if ( std::any_of( std::begin( key ), std::end( key ), []( char c ) {
      56      370639 :   return ( std::isupper( c ) )
      57             :            ;
      58           0 :   } ) ) plumed_error() << "CLTool: " + key + " cannot be registered, use only LOWERCASE characters";
      59             : 
      60      111782 :   Keywords keys;
      61      111782 :   kp(keys);
      62      335346 :   return RegisterBase::add(key,Pointers{cp,keys});
      63      111782 : }
      64             : 
      65           2 : bool CLToolRegister::printManual( const std::string& cltool, const bool& spelling ) {
      66           2 :   if( spelling && check(cltool) ) {
      67           0 :     auto cl=get(cltool);
      68           0 :     cl.keys.print_spelling();
      69             :     return true;
      70           2 :   } else if ( check(cltool) ) {
      71           0 :     auto cl=get(cltool);
      72           0 :     cl.keys.print_html();
      73             :     return true;
      74             :   } else {
      75             :     return false;
      76             :   }
      77             : }
      78             : 
      79           0 : std::vector<std::string> CLToolRegister::getKeys(const std::string& cltool)const {
      80           0 :   if ( check(cltool) ) {
      81           0 :     auto cl=get(cltool);
      82             :     auto k=cl.keys.getKeys();
      83           0 :     std::cerr<<k.size()<<"\n";
      84           0 :     for(unsigned i=0; i<k.size(); i++) {
      85           0 :       std::cerr<<k[i]<<"\n";
      86             :     }
      87             :     return k;
      88           0 :   } else {
      89             :     std::vector<std::string> empty;
      90             :     return empty;
      91           0 :   }
      92             : }
      93             : 
      94             : 
      95        5113 : std::vector<std::string> CLToolRegister::list()const {
      96        5113 :   return RegisterBase::getKeys();
      97             : }
      98             : 
      99             : }

Generated by: LCOV version 1.16