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 3916 : VesselRegister::~VesselRegister() { 30 1958 : 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 1958 : } 36 : 37 80457 : VesselRegister& vesselRegister() { 38 80457 : static VesselRegister ans; 39 80457 : return ans; 40 : } 41 : 42 35244 : void VesselRegister::remove(creator_pointer f) { 43 258456 : for(auto p=m.begin(); p!=m.end(); ++p) { 44 223212 : if((*p).second==f) { 45 : m.erase(p); break; 46 : } 47 : } 48 35244 : } 49 : 50 35244 : void VesselRegister::add(std::string keyword,creator_pointer f,keyword_pointer k,keyword_pointer ik) { 51 35244 : plumed_massert(m.count(keyword)==0,"keyword has already been registered"); 52 35244 : m.insert(std::pair<std::string,creator_pointer>(keyword,f)); 53 35244 : 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 35244 : mk.insert(std::pair<std::string,keyword_pointer>(keyword,ik)); 58 35244 : } 59 : 60 9307 : bool VesselRegister::check(std::string key) { 61 9307 : if( m.count(key)>0 ) return true; 62 6333 : return false; 63 : } 64 : 65 343 : std::unique_ptr<Vessel> VesselRegister::create(std::string keyword, const VesselOptions&da) { 66 343 : std::unique_ptr<Vessel> df; 67 686 : if(check(keyword)) { 68 343 : Keywords keys; mk[keyword](keys); 69 686 : VesselOptions nda( da,keys ); 70 1029 : df=m[keyword](nda); 71 : } 72 343 : return df; 73 : } 74 : 75 662 : Keywords VesselRegister::getKeywords() { 76 662 : return keywords; 77 : } 78 : 79 : } 80 5874 : }