LCOV - code coverage report
Current view: top level - core - CLToolRegister.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 37 56 66.1 %
Date: 2018-12-19 07:49:13 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2018 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             : using namespace std;
      30             : namespace PLMD {
      31             : 
      32        1682 : CLToolRegister::~CLToolRegister() {
      33         841 :   if(m.size()>0) {
      34           0 :     string names="";
      35           0 :     for(mIterator p=m.begin(); p!=m.end(); ++p)names+=p->first+" ";
      36           0 :     std::cerr<<"WARNING: CLTools "+ names +" has not been properly unregistered. This might lead to memory leak!!\n";
      37             :   }
      38         841 : }
      39             : 
      40       15158 : CLToolRegister& cltoolRegister() {
      41       15158 :   static CLToolRegister ans;
      42       15158 :   return ans;
      43             : }
      44             : 
      45        6728 : void CLToolRegister::remove(creator_pointer f) {
      46       30276 :   for(mIterator p=m.begin(); p!=m.end(); ++p) {
      47       30276 :     if((*p).second==f) {
      48        6728 :       m.erase(p); break;
      49             :     }
      50             :   }
      51        6728 : }
      52             : 
      53        6728 : void CLToolRegister::add(string key,creator_pointer f,keywords_pointer kf) {
      54        6728 :   if(m.count(key)) {
      55           0 :     m.erase(key);
      56           0 :     disabled.insert(key);
      57             :   } else {
      58        6728 :     m.insert(pair<string,creator_pointer>(key,f));
      59        6728 :     Keywords keys; kf(keys);
      60        6728 :     mk.insert(pair<string,Keywords>(key,keys));
      61             :   };
      62        6728 : }
      63             : 
      64         724 : bool CLToolRegister::check(string key) {
      65         724 :   if(m.count(key)>0) return true;
      66           0 :   return false;
      67             : }
      68             : 
      69         724 : CLTool* CLToolRegister::create(const CLToolOptions&ao) {
      70         724 :   if(ao.line.size()<1)return NULL;
      71             :   CLTool* cltool;
      72         724 :   if(check(ao.line[0])) {
      73         724 :     CLToolOptions nao( ao,mk[ao.line[0]] );
      74         724 :     cltool=m[ao.line[0]](nao);
      75           0 :   } else cltool=NULL;
      76         724 :   return cltool;
      77             : }
      78             : 
      79             : 
      80         160 : std::ostream & operator<<(std::ostream &log,const CLToolRegister&ar) {
      81         160 :   vector<string> s(ar.list());
      82         160 :   for(unsigned i=0; i<s.size(); i++) log<<"  "<<s[i]<<"\n";
      83         160 :   if(!ar.disabled.empty()) {
      84           0 :     s.assign(ar.disabled.size(),"");
      85           0 :     copy(ar.disabled.begin(),ar.disabled.end(),s.begin());
      86           0 :     sort(s.begin(),s.end());
      87           0 :     log<<"+++++++ WARNING +++++++\n";
      88           0 :     log<<"The following keywords have been registered more than once and will be disabled:\n";
      89           0 :     for(unsigned i=0; i<s.size(); i++) log<<"  - "<<s[i]<<"\n";
      90           0 :     log<<"+++++++ END WARNING +++++++\n";
      91             :   };
      92         160 :   return log;
      93             : }
      94             : 
      95           0 : bool CLToolRegister::printManual( const std::string& cltool ) {
      96           0 :   if ( check(cltool) ) {
      97           0 :     mk[cltool].print_html();
      98           0 :     return true;
      99             :   } else {
     100           0 :     return false;
     101             :   }
     102             : }
     103             : 
     104         978 : vector<string> CLToolRegister::list()const {
     105         978 :   vector<string> s;
     106        8802 :   for(const_mIterator it=m.begin(); it!=m.end(); ++it)
     107        7824 :     s.push_back((*it).first);
     108         978 :   sort(s.begin(),s.end());
     109         978 :   return s;
     110             : }
     111             : 
     112             : 
     113             : 
     114        2523 : }

Generated by: LCOV version 1.13