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