mantaflow  0.10
A framework for fluid simulation
registry.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * MantaFlow fluid solver framework
5  * Copyright 2011-2014 Tobias Pfaff, Nils Thuerey
6  *
7  * This program is free software, distributed under the terms of the
8  * GNU General Public License (GPL)
9  * http://www.gnu.org/licenses
10  *
11  * Auto python registry
12  *
13  ******************************************************************************/
14 
15 #ifndef _REGISTRY_H
16 #define _REGISTRY_H
17 
18 #include <string>
19 #include <vector>
20 
21 // forward declaration to minimize Python.h includes
22 #ifndef PyObject_HEAD
23 #ifndef PyObject_Fake
24 struct _object;
25 typedef _object PyObject;
26 #define PyObject_Fake
27 #endif
28 #endif
29 
30 namespace Manta {
31  class PbClass;
32  class PbArgs;
33 }
34 
35 // **************************************************
36 // NOTE
37 // Everything in this file is intend only for internal
38 // use by the generated wrappers or pclass/pconvert.
39 // For user code, use the functionality exposed in
40 // pclass.h / pconvert.h instead.
41 // **************************************************
42 
43 // Used to turn names into strings
44 namespace Manta {
45 template<class T> struct Namify {
46  static const char* S;
47 };
48 }
49 namespace Pb {
50 
51 // internal registry access
52 void setup(const std::string& filename, const std::vector<std::string>& args);
53 void finalize();
54 bool canConvert(PyObject* obj, const std::string& to);
55 Manta::PbClass* objFromPy(PyObject* obj);
56 Manta::PbClass* createPy(const std::string& classname, const std::string& name, Manta::PbArgs& args, Manta::PbClass* parent);
57 void setReference(Manta::PbClass* cls, PyObject* obj);
58 PyObject* copyObject(Manta::PbClass* cls, const std::string& classname);
59 void MantaEnsureRegistration();
60 
61 #ifdef BLENDER
62 #ifdef PyMODINIT_FUNC
63 PyMODINIT_FUNC PyInit_Main(void);
64 #endif
65 #endif
66 
67 // callback type
68 typedef void (*InitFunc)(PyObject*);
69 typedef PyObject* (*GenericFunction)(PyObject* self, PyObject* args, PyObject* kwds);
70 typedef PyObject* (*OperatorFunction)(PyObject* self, PyObject* o);
71 typedef int (*Constructor)(PyObject* self, PyObject* args, PyObject* kwds);
72 typedef PyObject* (*Getter)(PyObject* self, void* closure);
73 typedef int (*Setter)(PyObject* self, PyObject* value, void* closure);
74 
76 struct Register {
78  Register(const std::string& className, const std::string& funcName, GenericFunction func);
80  Register(const std::string& className, const std::string& funcName, OperatorFunction func);
82  Register(const std::string& className, const std::string& funcName, Constructor func);
84  Register(const std::string& className, const std::string& property, Getter getter, Setter setter);
86  Register(const std::string& className, const std::string& pyName, const std::string& baseClass);
88  Register(const std::string& file, const std::string& pythonCode);
90  Register(InitFunc func);
91 };
92 
93 #define KEEP_UNUSED(var) do { (void)var; } while(false);
94 
95 }
96 #endif
97 
98 
Definition: commonkernels.h:22
Definition: registry.h:45
Auto registry of python methods and classes.
Definition: registry.h:76
Definition: registry.cpp:24