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_TOPOLOGY_HPP
10 #define PYGMO_TOPOLOGY_HPP
11 
12 #include <cstddef>
13 #include <memory>
14 #include <string>
15 #include <type_traits>
16 #include <typeindex>
17 #include <utility>
18 #include <vector>
19 
20 #include <pybind11/pybind11.h>
21 
22 #include <pagmo/s11n.hpp>
23 #include <pagmo/topology.hpp>
24 #include <pagmo/types.hpp>
25 
26 #include "common_base.hpp"
27 
28 namespace pagmo
29 {
30 
31 namespace detail
32 {
33 
34 namespace py = pybind11;
35 
36 // Disable the static UDT checks for py::object.
37 template <>
38 struct disable_udt_checks<py::object> : std::true_type {
39 };
40 
41 template <>
42 struct topo_inner<py::object> final : topo_inner_base, pygmo::common_base {
43     // Just need the def ctor, delete everything else.
44     topo_inner() = default;
45     topo_inner(const topo_inner &) = delete;
46     topo_inner(topo_inner &&) = delete;
47     topo_inner &operator=(const topo_inner &) = delete;
48     topo_inner &operator=(topo_inner &&) = delete;
49     explicit topo_inner(const py::object &);
50     std::unique_ptr<topo_inner_base> clone() const final;
51     // Mandatory methods.
52     std::pair<std::vector<std::size_t>, vector_double> get_connections(std::size_t) const final;
53     void push_back() final;
54     // Optional methods.
55     std::string get_name() const final;
56     std::string get_extra_info() const final;
57 
58     bgl_graph_t to_bgl() const final;
59     std::type_index get_type_index() const final;
60     const void *get_ptr() const final;
61     void *get_ptr() final;
62 
63     template <typename Archive>
64     void save(Archive &, unsigned) const;
65     template <typename Archive>
66     void load(Archive &, unsigned);
67     BOOST_SERIALIZATION_SPLIT_MEMBER()
68 
69     py::object m_value;
70 };
71 
72 } // namespace detail
73 
74 } // namespace pagmo
75 
76 // Register the topo_inner specialisation for py::object.
77 PAGMO_S11N_TOPOLOGY_EXPORT_KEY(pybind11::object)
78 
79 #endif
80