All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VesselRegister.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 "Vessel.h"
23 #include "VesselRegister.h"
24 #include <iostream>
25 
26 namespace PLMD{
27 namespace vesselbase{
28 
30  if(m.size()>0){
31  std::string names="";
32  for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p) names+=p->first+" ";
33  std::cerr<<"WARNING: Vessel "+ names +" has not been properly unregistered. This might lead to memory leak!!\n";
34  }
35 }
36 
38  static VesselRegister ans;
39  return ans;
40 }
41 
42 void VesselRegister::remove(creator_pointer f){
43  for(std::map<std::string,creator_pointer>::iterator p=m.begin();p!=m.end();++p){
44  if((*p).second==f){
45  m.erase(p); break;
46  }
47  }
48 }
49 
50 void VesselRegister::add(std::string keyword,creator_pointer f,keyword_pointer k,keyword_pointer ik){
51  plumed_massert(m.count(keyword)==0,"keyword has already been registered");
52  m.insert(std::pair<std::string,creator_pointer>(keyword,f));
53  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  mk.insert(std::pair<std::string,keyword_pointer>(keyword,ik));
58 }
59 
60 bool VesselRegister::check(std::string key){
61  if( m.count(key)>0 ) return true;
62  return false;
63 }
64 
65 Vessel* VesselRegister::create(std::string keyword, const VesselOptions&da){
66  Vessel* df;
67  if(check(keyword)){
68  Keywords keys; mk[keyword](keys);
69  VesselOptions nda( da,keys );
70  df=m[keyword](nda);
71  keys.destroyData();
72  }
73  else df=NULL;
74  return df;
75 }
76 
78  return keywords;
79 }
80 
81 }
82 }
bool check(std::string keyname)
Verify if a distribution keyword is present in the register.
void remove(creator_pointer f)
Remove a distribution function from the register of distribution functions.
Vessel * create(std::string keyword, const VesselOptions &da)
Create a distribution function of the specified type.
void destroyData()
Clear everything from the keywords object.
Definition: Keywords.cpp:554
Keywords keywords
A vector of function pointers - this is used to create the documentation.
void add(std::string keyword, creator_pointer, keyword_pointer k, keyword_pointer ik)
Add a new distribution function option to the register of distribution functions. ...
This class holds the keywords and their documentation.
Definition: Keywords.h:36
VesselRegister & vesselRegister()
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
std::map< std::string, keyword_pointer > mk
Map action to a function which documents the related object.
Keywords getKeywords()
Return the keywords.
void int double * da
Definition: Matrix.h:47
std::map< std::string, creator_pointer > m
The set of possible distribution functions we can work with.