Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 1 | /* |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 2 | tests/pybind11_tests.cpp -- pybind example plugin |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 3 | |
Wenzel Jakob | 8cb6cb3 | 2016-04-17 20:21:41 +0200 | [diff] [blame] | 4 | Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 5 | |
| 6 | All rights reserved. Use of this source code is governed by a |
| 7 | BSD-style license that can be found in the LICENSE file. |
| 8 | */ |
| 9 | |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 10 | #include "pybind11_tests.h" |
| 11 | #include "constructor_stats.h" |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 12 | |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 13 | std::list<std::function<void(py::module &)>> &initializers() { |
| 14 | static std::list<std::function<void(py::module &)>> inits; |
| 15 | return inits; |
| 16 | } |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 17 | |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 18 | test_initializer::test_initializer(std::function<void(py::module &)> initializer) { |
| 19 | initializers().push_back(std::move(initializer)); |
| 20 | } |
Wenzel Jakob | 9e0a056 | 2016-05-05 20:33:54 +0200 | [diff] [blame] | 21 | |
Jason Rhinelander | 3f58937 | 2016-08-07 13:05:26 -0400 | [diff] [blame] | 22 | void bind_ConstructorStats(py::module &m) { |
| 23 | py::class_<ConstructorStats>(m, "ConstructorStats") |
| 24 | .def("alive", &ConstructorStats::alive) |
| 25 | .def("values", &ConstructorStats::values) |
| 26 | .def_readwrite("default_constructions", &ConstructorStats::default_constructions) |
| 27 | .def_readwrite("copy_assignments", &ConstructorStats::copy_assignments) |
| 28 | .def_readwrite("move_assignments", &ConstructorStats::move_assignments) |
| 29 | .def_readwrite("copy_constructions", &ConstructorStats::copy_constructions) |
| 30 | .def_readwrite("move_constructions", &ConstructorStats::move_constructions) |
Wenzel Jakob | 1ffce74 | 2016-08-25 01:43:33 +0200 | [diff] [blame] | 31 | .def_static("get", (ConstructorStats &(*)(py::object)) &ConstructorStats::get, py::return_value_policy::reference_internal); |
Jason Rhinelander | 3f58937 | 2016-08-07 13:05:26 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 34 | PYBIND11_PLUGIN(pybind11_tests) { |
| 35 | py::module m("pybind11_tests", "pybind example plugin"); |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 36 | |
Jason Rhinelander | 3f58937 | 2016-08-07 13:05:26 -0400 | [diff] [blame] | 37 | bind_ConstructorStats(m); |
| 38 | |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 39 | for (const auto &initializer : initializers()) |
| 40 | initializer(m); |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 41 | |
Jason Rhinelander | 3f1ff3f | 2016-12-12 17:42:52 -0500 | [diff] [blame] | 42 | if (!py::hasattr(m, "have_eigen")) m.attr("have_eigen") = false; |
Wenzel Jakob | 9e0a056 | 2016-05-05 20:33:54 +0200 | [diff] [blame] | 43 | |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 44 | return m.ptr(); |
| 45 | } |