LCOV - code coverage report
Current view: top level - vesselbase - VesselRegister.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 30 34 88.2 %
Date: 2018-12-19 07:49:13 Functions: 9 9 100.0 %

          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 "VesselRegister.h"
      23             : #include "Vessel.h"
      24             : #include <iostream>
      25             : 
      26             : namespace PLMD {
      27             : namespace vesselbase {
      28             : 
      29        1682 : VesselRegister::~VesselRegister() {
      30         841 :   if(m.size()>0) {
      31           0 :     std::string names="";
      32           0 :     for(std::map<std::string,creator_pointer>::iterator p=m.begin(); p!=m.end(); ++p) names+=p->first+" ";
      33           0 :     std::cerr<<"WARNING: Vessel "+ names +" has not been properly unregistered. This might lead to memory leak!!\n";
      34             :   }
      35         841 : }
      36             : 
      37       36107 : VesselRegister& vesselRegister() {
      38       36107 :   static VesselRegister ans;
      39       36107 :   return ans;
      40             : }
      41             : 
      42       14297 : void VesselRegister::remove(creator_pointer f) {
      43       85782 :   for(std::map<std::string,creator_pointer>::iterator p=m.begin(); p!=m.end(); ++p) {
      44       85782 :     if((*p).second==f) {
      45       14297 :       m.erase(p); break;
      46             :     }
      47             :   }
      48       14297 : }
      49             : 
      50       14297 : void VesselRegister::add(std::string keyword,creator_pointer f,keyword_pointer k,keyword_pointer ik) {
      51       14297 :   plumed_massert(m.count(keyword)==0,"keyword has already been registered");
      52       14297 :   m.insert(std::pair<std::string,creator_pointer>(keyword,f));
      53       14297 :   k( keywords );   // Store the keywords for all the things
      54             :   // Store a pointer to the function that creates keywords
      55             :   // A pointer is stored and not the keywords because all
      56             :   // Vessels must be dynamically loaded before the actions.
      57       14297 :   mk.insert(std::pair<std::string,keyword_pointer>(keyword,ik));
      58       14297 : }
      59             : 
      60        7099 : bool VesselRegister::check(std::string key) {
      61        7099 :   if( m.count(key)>0 ) return true;
      62        4679 :   return false;
      63             : }
      64             : 
      65         301 : Vessel* VesselRegister::create(std::string keyword, const VesselOptions&da) {
      66             :   Vessel* df;
      67         301 :   if(check(keyword)) {
      68         301 :     Keywords keys; mk[keyword](keys);
      69         602 :     VesselOptions nda( da,keys );
      70         301 :     df=m[keyword](nda);
      71         602 :     keys.destroyData();
      72             :   }
      73           0 :   else df=NULL;
      74         301 :   return df;
      75             : }
      76             : 
      77         414 : Keywords VesselRegister::getKeywords() {
      78         414 :   return keywords;
      79             : }
      80             : 
      81             : }
      82        2523 : }

Generated by: LCOV version 1.13