All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VesselRegister.h
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 #ifndef __PLUMED_vesselbase_VesselRegister_h
23 #define __PLUMED_vesselbase_VesselRegister_h
24 
25 #include <string>
26 #include <cstring>
27 #include <vector>
28 #include <map>
29 #include "tools/Exception.h"
30 #include "tools/Keywords.h"
31 
32 namespace PLMD{
33 namespace vesselbase{
34 
35 class Vessel;
36 class VesselOptions;
37 
39 private:
40 /// Pointer to a function which, given the keyword for a distribution function, creates it
41  typedef Vessel*(*creator_pointer)(const VesselOptions&);
42 /// Pointer to the function that reserves the keyword for the distribution
43  typedef void(*keyword_pointer)(Keywords&);
44 /// The set of possible distribution functions we can work with
45  std::map<std::string,creator_pointer> m;
46 /// Map action to a function which documents the related object
47  std::map<std::string,keyword_pointer> mk;
48 /// A vector of function pointers - this is used to create the documentation
50 public:
51 /// The destructor
53 /// Add a new distribution function option to the register of distribution functions
54  void add(std::string keyword,creator_pointer,keyword_pointer k,keyword_pointer ik);
55 /// Remove a distribution function from the register of distribution functions
56  void remove(creator_pointer f);
57 /// Verify if a distribution keyword is present in the register
58  bool check(std::string keyname);
59 /// Create a distribution function of the specified type
60  Vessel* create(std::string keyword, const VesselOptions&da);
61 /// Return the keywords
63 };
64 
66 
67 #define PLUMED_REGISTER_VESSEL(classname,keyword) \
68  static class classname##RegisterMe{ \
69  static PLMD::vesselbase::Vessel * create(const PLMD::vesselbase::VesselOptions&da){return new classname(da);} \
70  public: \
71  classname##RegisterMe(){PLMD::vesselbase::vesselRegister().add(keyword,create,classname::reserveKeyword,classname::registerKeywords);} \
72  ~classname##RegisterMe(){PLMD::vesselbase::vesselRegister().remove(create);} \
73  } classname##RegisterMeObject;
74 
75 }
76 }
77 #endif
bool check(std::string keyname)
Verify if a distribution keyword is present in the register.
Vessel * create(std::string keyword, const VesselOptions &da)
Create a distribution function of the specified type.
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
void(* keyword_pointer)(Keywords &)
Pointer to the function that reserves the keyword for the distribution.
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
Vessel *(* creator_pointer)(const VesselOptions &)
Pointer to a function which, given the keyword for a distribution function, creates it...
std::map< std::string, creator_pointer > m
The set of possible distribution functions we can work with.