local_bindings.h
Go to the documentation of this file.
1 #pragma once
2 #include "pybind11_tests.h"
3 
5 template <int> class LocalBase {
6 public:
7  LocalBase(int i) : i(i) { }
8  int i = -1;
9 };
10 
23 
27 
28 using LocalVec = std::vector<LocalType>;
29 using LocalVec2 = std::vector<NonLocal2>;
30 using LocalMap = std::unordered_map<std::string, LocalType>;
31 using NonLocalVec = std::vector<NonLocalType>;
32 using NonLocalVec2 = std::vector<NonLocal2>;
33 using NonLocalMap = std::unordered_map<std::string, NonLocalType>;
34 using NonLocalMap2 = std::unordered_map<std::string, uint8_t>;
35 
40 //PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2
43 
44 
45 // Simple bindings (used with the above):
46 template <typename T, int Adjust = 0, typename... Args>
47 py::class_<T> bind_local(Args && ...args) {
48  return py::class_<T>(std::forward<Args>(args)...)
49  .def(py::init<int>())
50  .def("get", [](T &i) { return i.i + Adjust; });
51 };
52 
53 // Simulate a foreign library base class (to match the example in the docs):
54 namespace pets {
55 class Pet {
56 public:
57  Pet(std::string name) : name_(name) {}
58  std::string name_;
59  const std::string &name() { return name_; }
60 };
61 } // namespace pets
62 
63 struct MixGL { int i; MixGL(int i) : i{i} {} };
64 struct MixGL2 { int i; MixGL2(int i) : i{i} {} };
LocalBase(int i)
Definition: local_bindings.h:7
py::class_< T > bind_local(Args &&...args)
PYBIND11_MAKE_OPAQUE(LocalVec)
std::unordered_map< std::string, uint8_t > NonLocalMap2
std::vector< LocalType > LocalVec
Definition: pytypes.h:1322
std::vector< NonLocal2 > LocalVec2
std::unordered_map< std::string, LocalType > LocalMap
Pet(std::string name)
std::vector< NonLocal2 > NonLocalVec2
Eigen::Triplet< double > T
MixGL(int i)
std::string name_
std::vector< NonLocalType > NonLocalVec
Annotation for function names.
Definition: attr.h:36
Simple class used to test py::local:
Definition: local_bindings.h:5
std::unordered_map< std::string, NonLocalType > NonLocalMap
MixGL2(int i)
const std::string & name()


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:32