std_map.cpp
Go to the documentation of this file.
1 
4 #include <eigenpy/eigenpy.hpp>
5 #include <eigenpy/std-map.hpp>
6 #include <boost/unordered_map.hpp>
7 
8 namespace bp = boost::python;
9 
10 template <typename T1>
11 bp::dict std_map_to_dict(const std::map<std::string, T1>& map) {
12  bp::dict dictionnary;
13  for (auto const& x : map) {
14  dictionnary[x.first] = x.second;
15  }
16  return dictionnary;
17 }
18 
19 template <typename T1>
20 std::map<std::string, T1> copy(const std::map<std::string, T1>& map) {
21  std::map<std::string, T1> out = map;
22  return out;
23 }
24 
25 template <typename T1>
26 boost::unordered_map<std::string, T1> copy_boost(
27  const boost::unordered_map<std::string, T1>& obj) {
28  return obj;
29 }
30 
31 struct X {
32  X() = delete;
33  X(int x) : val(x) {}
34  int val;
35 };
36 
39 
41  std::string, double, std::less<std::string>,
42  std::allocator<std::pair<const std::string, double> >,
43  true>::expose("StdMap_Double");
44 
46  "boost_map_int");
47 
48  using StdMap_X = std::map<std::string, X>;
49  bp::class_<X>("X", bp::init<int>()).def_readwrite("val", &X::val);
50 
51  // this just needs to compile
54 
55  bp::def("std_map_to_dict", std_map_to_dict<double>);
56  bp::def("copy", copy<double>);
57  bp::def("copy_boost", copy_boost<int>);
58  bp::def("copy_X", +[](const StdMap_X& m) { return m; });
59 }
boost::python
Definition: alignment.hpp:49
eigenpy::enableEigenPy
void EIGENPY_DLLAPI enableEigenPy()
Definition: eigenpy.cpp:43
eigenpy::overload_base_get_item_for_map
Change the behavior of indexing (method getitem in Python). This is suitable e.g. for container of Ei...
Definition: map.hpp:24
BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(std_map)
Definition: std_map.cpp:37
std_map_to_dict
bp::dict std_map_to_dict(const std::map< std::string, T1 > &map)
Definition: std_map.cpp:11
copy_boost
boost::unordered_map< std::string, T1 > copy_boost(const boost::unordered_map< std::string, T1 > &obj)
Definition: std_map.cpp:26
copy
std::map< std::string, T1 > copy(const std::map< std::string, T1 > &map)
Definition: std_map.cpp:20
eigenpy::GenericMapVisitor::expose
static void expose(const std::string &class_name, const std::string &doc_string, const bp::def_visitor< DerivedVisitor > &visitor)
Definition: map.hpp:217
test_user_struct.x
x
Definition: test_user_struct.py:4
eigenpy::expose
void expose()
Call the expose function of a given type T.
Definition: expose.hpp:23
eigenpy.hpp
eigenpy::GenericMapVisitor
Expose the map-like container, e.g. (std::map).
Definition: map.hpp:211
test_sparse_matrix.m
m
Definition: test_sparse_matrix.py:5
std-map.hpp
X::X
X(int x)
Definition: std_map.cpp:33
X::val
int val
Definition: std_map.cpp:34
eigenpy::StdMapPythonVisitor
Expose an std::map from a type given as template argument.
Definition: std-map.hpp:35
X::X
X()
Definition: multiple_registration.cpp:8
X
Definition: deprecation_policy.cpp:19


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45