Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-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 "PlumedMain.h"
23 : #include "tools/Exception.h"
24 : #include <cstdlib>
25 :
26 : using namespace std;
27 :
28 : // !!!!!!!!!!!!!!!!!!!!!! DANGER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
29 : // THE FOLLOWING ARE UTILITIES WHICH ARE NECESSARY FOR DYNAMIC LOADING OF THE PLUMED KERNEL:
30 : // This section should be consistent with the Plumed.h file.
31 : // Since the Plumed.h file may be included in host MD codes, **NEVER** MODIFY THE CODE IN THIS FILE
32 : // unless you know exactly what you are doing
33 :
34 : /**
35 : Container for plumedmain function pointers (create, cmd and finalize).
36 : */
37 : typedef struct {
38 : void*(*create)();
39 : void(*cmd)(void*,const char*,const void*);
40 : void(*finalize)(void*);
41 : } plumed_plumedmain_function_holder;
42 :
43 : /* These functions should be accessible from C, since they might be statically
44 : used from Plumed.c (for static binding) */
45 :
46 2152 : extern "C" void*plumedmain_create() {
47 2152 : return new PLMD::PlumedMain;
48 : }
49 :
50 256234 : extern "C" void plumedmain_cmd(void*plumed,const char*key,const void*val) {
51 256234 : plumed_massert(plumed,"trying to use a plumed object which is not initialized");
52 512468 : static_cast<PLMD::PlumedMain*>(plumed)->cmd(key,val);
53 256187 : }
54 :
55 2152 : extern "C" void plumedmain_finalize(void*plumed) {
56 2152 : plumed_massert(plumed,"trying to deallocate a plumed object which is not initialized");
57 2152 : delete static_cast<PLMD::PlumedMain*>(plumed);
58 2152 : }
59 :
60 : /* This refers to a function implemented in Plumed.c */
61 : extern "C" plumed_plumedmain_function_holder* plumed_kernel_register(const plumed_plumedmain_function_holder*);
62 :
63 : namespace PLMD {
64 :
65 : /// Static object which registers Plumed.
66 : /// This is a static object which, during its construction at startup,
67 : /// registers the pointers to plumedmain_create, plumedmain_cmd and plumedmain_finalize
68 : /// to the plumed_kernel_register function
69 : static class PlumedMainInitializer {
70 : public:
71 : PlumedMainInitializer() {
72 1613 : plumed_plumedmain_function_holder fh= {plumedmain_create,plumedmain_cmd,plumedmain_finalize};
73 1613 : plumed_kernel_register(&fh);
74 : }
75 : } RegisterMe;
76 :
77 4839 : }
78 :
79 :
|