blob: 06a56fcd1f925b23348795070d97d4ce69d04804 [file] [log] [blame]
Jason Rhinelander7437c692017-07-28 22:03:44 -04001#pragma once
2#include "pybind11_tests.h"
3
4/// Simple class used to test py::local:
5template <int> class LocalBase {
6public:
7 LocalBase(int i) : i(i) { }
8 int i = -1;
9};
10
11/// Registered with py::local in both main and secondary modules:
12using LocalType = LocalBase<0>;
13/// Registered without py::local in both modules:
14using NonLocalType = LocalBase<1>;
15/// A second non-local type (for stl_bind tests):
16using NonLocal2 = LocalBase<2>;
17/// Tests within-module, different-compilation-unit local definition conflict:
18using LocalExternal = LocalBase<3>;
Jason Rhinelander4b159232017-08-04 13:05:12 -040019/// Mixed: registered local first, then global
20using MixedLocalGlobal = LocalBase<4>;
21/// Mixed: global first, then local (which fails)
22using MixedGlobalLocal = LocalBase<5>;
Jason Rhinelander7437c692017-07-28 22:03:44 -040023
Dean Moldovan8d3cedb2017-08-13 03:03:06 +020024using LocalVec = std::vector<LocalType>;
25using LocalVec2 = std::vector<NonLocal2>;
26using LocalMap = std::unordered_map<std::string, LocalType>;
27using NonLocalVec = std::vector<NonLocalType>;
28using NonLocalVec2 = std::vector<NonLocal2>;
29using NonLocalMap = std::unordered_map<std::string, NonLocalType>;
30using NonLocalMap2 = std::unordered_map<std::string, uint8_t>;
31
Jason Rhinelander7437c692017-07-28 22:03:44 -040032// Simple bindings (used with the above):
33template <typename T, int Adjust, typename... Args>
34py::class_<T> bind_local(Args && ...args) {
35 return py::class_<T>(std::forward<Args>(args)...)
36 .def(py::init<int>())
37 .def("get", [](T &i) { return i.i + Adjust; });
38};