All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PlumedMainInitializer.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 "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*);
42 
43 /* These functions should be accessible from C, since they might be statically
44  used from Plumed.c (for static binding) */
45 
46 extern "C" void*plumedmain_create(){
47  return new PLMD::PlumedMain;
48 }
49 
50 extern "C" void plumedmain_cmd(void*plumed,const char*key,const void*val){
51  plumed_massert(plumed,"trying to use a plumed object which is not initialized");
52  static_cast<PLMD::PlumedMain*>(plumed)->cmd(key,val);
53 }
54 
55 extern "C" void plumedmain_finalize(void*plumed){
56  plumed_massert(plumed,"trying to deallocate a plumed object which is not initialized");
57  delete static_cast<PLMD::PlumedMain*>(plumed);
58 }
59 
60 /* This refers to a function implemented in Plumed.c */
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:
74  }
75 } RegisterMe;
76 
77 }
78 
79 
Static object which registers Plumed.
STL namespace.
static class PLMD::PlumedMainInitializer RegisterMe
Container for plumedmain function pointers (create, cmd and finalize).
void plumedmain_finalize(void *plumed)
void plumedmain_cmd(void *plumed, const char *key, const void *val)
Main plumed object.
Definition: PlumedMain.h:71
Main plumed object.
Definition: Plumed.h:201
plumed_plumedmain_function_holder * plumed_kernel_register(const plumed_plumedmain_function_holder *)
Register for plumedmain function pointers.
Definition: Plumed.c:101
void * plumedmain_create()