Nektar++
library
LibUtilities
Python
NekPyConfig.hpp
Go to the documentation of this file.
1
///////////////////////////////////////////////////////////////////////////////
2
//
3
// File NekPyConfig.hpp
4
//
5
// For more information, please see: http://www.nektar.info
6
//
7
// The MIT License
8
//
9
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10
// Department of Aeronautics, Imperial College London (UK), and Scientific
11
// Computing and Imaging Institute, University of Utah (USA).
12
//
13
// Permission is hereby granted, free of charge, to any person obtaining a
14
// copy of this software and associated documentation files (the "Software"),
15
// to deal in the Software without restriction, including without limitation
16
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
// and/or sell copies of the Software, and to permit persons to whom the
18
// Software is furnished to do so, subject to the following conditions:
19
//
20
// The above copyright notice and this permission notice shall be included
21
// in all copies or substantial portions of the Software.
22
//
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
// DEALINGS IN THE SOFTWARE.
30
//
31
// Description:
32
//
33
///////////////////////////////////////////////////////////////////////////////
34
35
#include <boost/version.hpp>
36
37
#ifdef BOOST_HAS_NUMPY
38
39
#include <boost/python.hpp>
40
#include <boost/python/numpy.hpp>
41
42
namespace
py = boost::python;
43
namespace
np = boost::python::numpy;
44
45
#else
46
47
#include <boost/python.hpp>
48
#include <boost/numpy.hpp>
49
50
namespace
py = boost::python;
51
namespace
np = boost::numpy;
52
53
#endif
54
55
#define SIZENAME(s) SIZE_##s
56
#define NEKPY_WRAP_ENUM(ENUMNAME,MAPNAME) \
57
{ \
58
py::enum_<ENUMNAME> tmp(#ENUMNAME); \
59
for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
60
{ \
61
tmp.value(MAPNAME[a], (ENUMNAME)a); \
62
} \
63
tmp.export_values(); \
64
}
65
#define NEKPY_WRAP_ENUM_STRING(ENUMNAME,MAPNAME) \
66
{ \
67
py::enum_<ENUMNAME> tmp(#ENUMNAME); \
68
for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
69
{ \
70
tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
71
} \
72
tmp.export_values(); \
73
}
74
#if PY_MAJOR_VERSION == 2
75
#define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME,MAPNAME,DOCSTRING) \
76
{ \
77
py::enum_<ENUMNAME> tmp(#ENUMNAME); \
78
for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
79
{ \
80
tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
81
} \
82
tmp.export_values(); \
83
PyTypeObject * pto = \
84
reinterpret_cast<PyTypeObject*>(tmp.ptr()); \
85
PyDict_SetItemString(pto->tp_dict, "__doc__", \
86
PyString_FromString(DOCSTRING)); \
87
}
88
#else
89
#define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME,MAPNAME,DOCSTRING) \
90
{ \
91
py::enum_<ENUMNAME> tmp(#ENUMNAME); \
92
for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
93
{ \
94
tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
95
} \
96
tmp.export_values(); \
97
PyTypeObject * pto = \
98
reinterpret_cast<PyTypeObject*>(tmp.ptr()); \
99
PyDict_SetItemString(pto->tp_dict, "__doc__", \
100
PyUnicode_FromString(DOCSTRING)); \
101
}
102
#endif
103
104
// Boost 1.62 and earlier don't have native support for std::shared_ptr.
105
#if BOOST_VERSION < 106300
106
#define NEKPY_SHPTR_FIX(SOURCE,TARGET) \
107
py::implicitly_convertible<std::shared_ptr<SOURCE>, \
108
std::shared_ptr<TARGET>>();
109
#else
110
#define NEKPY_SHPTR_FIX(SOURCE,TARGET)
111
#endif
112
Generated on Wed Jan 20 2021 03:33:37 for Nektar++ by
1.8.13