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_S_POLICY_HPP
10 #define PYGMO_S_POLICY_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/s11n.hpp>
20 #include <pagmo/s_policy.hpp>
21 #include <pagmo/types.hpp>
22 
23 #include "common_base.hpp"
24 
25 namespace pagmo
26 {
27 
28 namespace detail
29 {
30 
31 namespace py = pybind11;
32 
33 // Disable the static UDSP checks for py::object.
34 template <>
35 struct disable_udsp_checks<py::object> : std::true_type {
36 };
37 
38 template <>
39 struct s_pol_inner<py::object> final : s_pol_inner_base, pygmo::common_base {
40     // Just need the def ctor, delete everything else.
41     s_pol_inner() = default;
42     s_pol_inner(const s_pol_inner &) = delete;
43     s_pol_inner(s_pol_inner &&) = delete;
44     s_pol_inner &operator=(const s_pol_inner &) = delete;
45     s_pol_inner &operator=(s_pol_inner &&) = delete;
46     explicit s_pol_inner(const py::object &);
47     std::unique_ptr<s_pol_inner_base> clone() const final;
48     // Mandatory methods.
49     individuals_group_t select(const individuals_group_t &, const vector_double::size_type &,
50                                const vector_double::size_type &, const vector_double::size_type &,
51                                const vector_double::size_type &, const vector_double::size_type &,
52                                const vector_double &) const final;
53     // Optional methods.
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 s_pol_inner specialisation for py::object.
75 PAGMO_S11N_S_POLICY_EXPORT_KEY(pybind11::object)
76 
77 #endif
78