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: 2019-08-13 10:39:37 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2019 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        3214 : VesselRegister::~VesselRegister() {
      30        1607 :   if(m.size()>0) {
      31           0 :     std::string names="";
      32           0 :     for(const auto & p : m) names+=p.first+" ";
      33           0 :     std::cerr<<"WARNING: Vessel "+ names +" has not been properly unregistered. This might lead to memory leak!!\n";
      34             :   }
      35        1607 : }
      36             : 
      37       66918 : VesselRegister& vesselRegister() {
      38       66918 :   static VesselRegister ans;
      39       66918 :   return ans;
      40             : }
      41             : 
      42       28926 : void VesselRegister::remove(creator_pointer f) {
      43      183198 :   for(auto p=m.begin(); p!=m.end(); ++p) {
      44      183198 :     if((*p).second==f) {
      45       28926 :       m.erase(p); break;
      46             :     }
      47             :   }
      48       28926 : }
      49             : 
      50       28926 : void VesselRegister::add(std::string keyword,creator_pointer f,keyword_pointer k,keyword_pointer ik) {
      51       28926 :   plumed_massert(m.count(keyword)==0,"keyword has already been registered");
      52       28926 :   m.insert(std::pair<std::string,creator_pointer>(keyword,f));
      53       28926 :   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       28926 :   mk.insert(std::pair<std::string,keyword_pointer>(keyword,ik));
      58       28926 : }
      59             : 
      60        8557 : bool VesselRegister::check(std::string key) {
      61        8557 :   if( m.count(key)>0 ) return true;
      62        5728 :   return false;
      63             : }
      64             : 
      65         328 : Vessel* VesselRegister::create(std::string keyword, const VesselOptions&da) {
      66             :   Vessel* df;
      67         328 :   if(check(keyword)) {
      68         328 :     Keywords keys; mk[keyword](keys);
      69         656 :     VesselOptions nda( da,keys );
      70         328 :     df=m[keyword](nda);
      71         656 :     keys.destroyData();
      72             :   }
      73           0 :   else df=NULL;
      74         328 :   return df;
      75             : }
      76             : 
      77         509 : Keywords VesselRegister::getKeywords() {
      78         509 :   return keywords;
      79             : }
      80             : 
      81             : }
      82        4821 : }

Generated by: LCOV version 1.13