| 1 |
// Copyright (C) 2017 Chris Richardson and Garth N. Wells |
| 2 |
// |
| 3 |
// This file is part of DOLFIN. |
| 4 |
// |
| 5 |
// DOLFIN is free software: you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU Lesser General Public License as published by |
| 7 |
// the Free Software Foundation, either version 3 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// DOLFIN is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU Lesser General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
#ifndef _DOLFIN_PYBIND11_CASTERS |
| 19 |
#define _DOLFIN_PYBIND11_CASTERS |
| 20 |
|
| 21 |
#include <pybind11/pybind11.h> |
| 22 |
#include <pybind11/stl.h> |
| 23 |
#include <boost/variant.hpp> |
| 24 |
#include <boost/optional.hpp> |
| 25 |
|
| 26 |
#include "mpi_casters.h" |
| 27 |
#include "petsc_casters.h" |
| 28 |
|
| 29 |
namespace pybind11 |
| 30 |
{ |
| 31 |
namespace detail |
| 32 |
{ |
| 33 |
// Caster for boost::optional |
| 34 |
template <typename T> |
| 35 |
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {}; |
| 36 |
|
| 37 |
// Caster for boost::variant (from pybind11 docs) |
| 38 |
template <typename... Ts> |
| 39 |
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {}; |
| 40 |
|
| 41 |
// Specifies the function used to visit the variant -- |
| 42 |
// `apply_visitor` instead of `visit` |
| 43 |
template <> |
| 44 |
struct visit_helper<boost::variant> { |
| 45 |
template <typename... Args> |
| 46 |
static auto call(Args &&...args) -> decltype(boost::apply_visitor(args...)) { |
| 47 |
return boost::apply_visitor(args...); |
| 48 |
} |
| 49 |
}; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
#endif |