Skip to content

Commit ae3081b

Browse files
committed
core: add id helper
1 parent ca81cf1 commit ae3081b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ set(${PROJECT_NAME}_HEADERS
232232
include/eigenpy/eigen-to-python.hpp
233233
include/eigenpy/eigen-from-python.hpp
234234
include/eigenpy/eigen-typedef.hpp
235+
include/eigenpy/id.hpp
235236
include/eigenpy/numpy-map.hpp
236237
include/eigenpy/geometry.hpp
237238
include/eigenpy/geometry-conversion.hpp

include/eigenpy/fwd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,6 @@ struct has_operator_equal : internal::has_operator_equal_impl<T1, T2>::type {};
200200
} // namespace eigenpy
201201

202202
#include "eigenpy/alignment.hpp"
203+
#include "eigenpy/id.hpp"
203204

204205
#endif // ifndef __eigenpy_fwd_hpp__

include/eigenpy/id.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright (c) 2024 INRIA
3+
//
4+
5+
#ifndef __eigenpy_id_hpp__
6+
#define __eigenpy_id_hpp__
7+
8+
#include <boost/python.hpp>
9+
#include <boost/cstdint.hpp>
10+
11+
namespace eigenpy {
12+
13+
///
14+
/// \brief Add the Python method id to retrieving a unique id for a given object
15+
/// exposed with Boost.Python
16+
///
17+
template <class C>
18+
struct IdVisitor : public bp::def_visitor<IdVisitor<C> > {
19+
template <class PyClass>
20+
void visit(PyClass& cl) const {
21+
cl.def("id", &id, bp::arg("self"),
22+
"Returns the unique identity of an object.\n"
23+
"For object held in C++, it corresponds to its memory address.");
24+
}
25+
26+
private:
27+
static boost::int64_t id(const C& self) {
28+
return boost::int64_t(reinterpret_cast<const void*>(&self));
29+
}
30+
};
31+
} // namespace eigenpy
32+
33+
#endif // ifndef __eigenpy_id_hpp__

0 commit comments

Comments
 (0)