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