1 // Copyright 2020, 2021 PaGMO development team 2 // 3 // This file is part of the pygmo library. 4 // 5 // This Source Code Form is subject to the terms of the Mozilla 6 // Public License v. 2.0. If a copy of the MPL was not distributed 7 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 9 #ifndef PYGMO_BFE_HPP 10 #define PYGMO_BFE_HPP 11 12 #include <memory> 13 #include <string> 14 #include <type_traits> 15 #include <typeindex> 16 17 #include <pybind11/pybind11.h> 18 19 #include <pagmo/bfe.hpp> 20 #include <pagmo/problem.hpp> 21 #include <pagmo/s11n.hpp> 22 #include <pagmo/threading.hpp> 23 #include <pagmo/types.hpp> 24 25 #include "common_base.hpp" 26 27 namespace pagmo 28 { 29 30 namespace detail 31 { 32 33 namespace py = pybind11; 34 35 // Disable the static UDBFE checks for py::object. 36 template <> 37 struct disable_udbfe_checks<py::object> : std::true_type { 38 }; 39 40 template <> 41 struct bfe_inner<py::object> final : bfe_inner_base, pygmo::common_base { 42 // Just need the def ctor, delete everything else. 43 bfe_inner() = default; 44 bfe_inner(const bfe_inner &) = delete; 45 bfe_inner(bfe_inner &&) = delete; 46 bfe_inner &operator=(const bfe_inner &) = delete; 47 bfe_inner &operator=(bfe_inner &&) = delete; 48 explicit bfe_inner(const py::object &); 49 std::unique_ptr<bfe_inner_base> clone() const final; 50 // Mandatory methods. 51 vector_double operator()(const problem &, const vector_double &) const final; 52 // Optional methods. 53 thread_safety get_thread_safety() const final; 54 std::string get_name() const final; 55 std::string get_extra_info() const final; 56 57 std::type_index get_type_index() const final; 58 const void *get_ptr() const final; 59 void *get_ptr() final; 60 61 template <typename Archive> 62 void save(Archive &, unsigned) const; 63 template <typename Archive> 64 void load(Archive &, unsigned); 65 BOOST_SERIALIZATION_SPLIT_MEMBER() 66 67 py::object m_value; 68 }; 69 70 } // namespace detail 71 72 } // namespace pagmo 73 74 // Register the bfe_inner specialisation for py::object. 75 PAGMO_S11N_BFE_EXPORT_KEY(pybind11::object) 76 77 #endif 78