You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

  1. /*
  2. tests/pybind11_tests.cpp -- pybind example plugin
  3. Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #include "pybind11_tests.h"
  8. #include "constructor_stats.h"
  9. std::list<std::function<void(py::module &)>> &initializers() {
  10. static std::list<std::function<void(py::module &)>> inits;
  11. return inits;
  12. }
  13. test_initializer::test_initializer(std::function<void(py::module &)> initializer) {
  14. initializers().push_back(std::move(initializer));
  15. }
  16. void bind_ConstructorStats(py::module &m) {
  17. py::class_<ConstructorStats>(m, "ConstructorStats")
  18. .def("alive", &ConstructorStats::alive)
  19. .def("values", &ConstructorStats::values)
  20. .def_readwrite("default_constructions", &ConstructorStats::default_constructions)
  21. .def_readwrite("copy_assignments", &ConstructorStats::copy_assignments)
  22. .def_readwrite("move_assignments", &ConstructorStats::move_assignments)
  23. .def_readwrite("copy_constructions", &ConstructorStats::copy_constructions)
  24. .def_readwrite("move_constructions", &ConstructorStats::move_constructions)
  25. .def_static("get", (ConstructorStats &(*)(py::object)) &ConstructorStats::get, py::return_value_policy::reference_internal);
  26. }
  27. PYBIND11_PLUGIN(pybind11_tests) {
  28. py::module m("pybind11_tests", "pybind example plugin");
  29. bind_ConstructorStats(m);
  30. for (const auto &initializer : initializers())
  31. initializer(m);
  32. if (!py::hasattr(m, "have_eigen")) m.attr("have_eigen") = py::cast(false);
  33. return m.ptr();
  34. }