Nektar++
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: NekPy configuration to include boost headers and define
32 // commonly-used macros.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIBRARY_LIBUTILITIES_PYTHON_NEKPYCONFIG_HPP
37 #define NEKTAR_LIBRARY_LIBUTILITIES_PYTHON_NEKPYCONFIG_HPP
38 
39 #include <boost/version.hpp>
40 #include <memory>
41 
42 // Boost 1.62 and earlier don't have native support for std::shared_ptr. This
43 // includes various patches that are pulled from the git changeset 97e4b34a15
44 // from the main boost.python github repository, which is where fixes were
45 // added to include std::shared_ptr support.
46 #if BOOST_VERSION < 106300
47 #include "ShPtrFixes.hpp"
48 #endif
49 
50 #ifdef BOOST_HAS_NUMPY
51 
52 #include <boost/python.hpp>
53 #include <boost/python/numpy.hpp>
54 
55 namespace py = boost::python;
56 namespace np = boost::python::numpy;
57 
58 #else
59 
60 #include <boost/numpy.hpp>
61 #include <boost/python.hpp>
62 
63 namespace py = boost::python;
64 namespace np = boost::numpy;
65 
66 #endif
67 
68 #define SIZENAME(s) SIZE_##s
69 #define NEKPY_WRAP_ENUM(ENUMNAME, MAPNAME) \
70  { \
71  py::enum_<ENUMNAME> tmp(#ENUMNAME); \
72  for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
73  { \
74  tmp.value(MAPNAME[a], (ENUMNAME)a); \
75  } \
76  tmp.export_values(); \
77  }
78 #define NEKPY_WRAP_ENUM_STRING(ENUMNAME, MAPNAME) \
79  { \
80  py::enum_<ENUMNAME> tmp(#ENUMNAME); \
81  for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
82  { \
83  tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
84  } \
85  tmp.export_values(); \
86  }
87 #if PY_MAJOR_VERSION == 2
88 #define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME, MAPNAME, DOCSTRING) \
89  { \
90  py::enum_<ENUMNAME> tmp(#ENUMNAME); \
91  for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
92  { \
93  tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
94  } \
95  tmp.export_values(); \
96  PyTypeObject *pto = reinterpret_cast<PyTypeObject *>(tmp.ptr()); \
97  PyDict_SetItemString(pto->tp_dict, "__doc__", \
98  PyString_FromString(DOCSTRING)); \
99  }
100 #else
101 #define NEKPY_WRAP_ENUM_STRING_DOCS(ENUMNAME, MAPNAME, DOCSTRING) \
102  { \
103  py::enum_<ENUMNAME> tmp(#ENUMNAME); \
104  for (int a = 0; a < (int)SIZENAME(ENUMNAME); ++a) \
105  { \
106  tmp.value(MAPNAME[a].c_str(), (ENUMNAME)a); \
107  } \
108  tmp.export_values(); \
109  PyTypeObject *pto = reinterpret_cast<PyTypeObject *>(tmp.ptr()); \
110  PyDict_SetItemString(pto->tp_dict, "__doc__", \
111  PyUnicode_FromString(DOCSTRING)); \
112  }
113 #endif
114 
115 #endif