Drake
type_safe_index_pybind.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include "pybind11/pybind11.h"
6 
7 #include "drake/bindings/pydrake/pydrake_pybind.h"
8 #include "drake/common/type_safe_index.h"
9 
10 namespace drake {
11 namespace pydrake {
12 
13 /// Binds a TypeSafeIndex instantiation.
14 template <typename Type>
15 auto BindTypeSafeIndex(py::module m, const std::string& name) {
16  py::class_<Type> cls(m, name.c_str());
17  cls
18  .def(py::init<int>())
19  .def("__int__", &Type::operator int)
20  .def("__eq__", [](const Type* self, const Type* other) {
21  return *self == *other;
22  }, py::is_operator())
23  .def("__eq__", [](const Type* self, int other) {
24  return *self == other;
25  }, py::is_operator())
26  // TODO(eric.cousineau): Add more operators.
27  .def("is_valid", &Type::is_valid);
28  return cls;
29 }
30 
31 } // namespace pydrake
32 } // namespace drake
Definition: automotive_demo.cc:90
auto BindTypeSafeIndex(py::module m, const std::string &name)
Binds a TypeSafeIndex instantiation.
Definition: type_safe_index_pybind.h:15