LCOV - code coverage report
Current view: top level - vesselbase - VesselRegister.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 35 82.9 %
Date: 2026-03-30 13:16:06 Functions: 7 7 100.0 %

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

Generated by: LCOV version 1.16