IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
PythonStdMapUtils.h
Go to the documentation of this file.
1 // PythonStdMapUtils.h:
3 // --------------------
4 //
14 
15 #ifndef __PYIPSDKBASE_PYTHONSTDMAPUTILS_H__
16 #define __PYIPSDKBASE_PYTHONSTDMAPUTILS_H__
17 
18 #include <boost/python/suite/indexing/map_indexing_suite.hpp>
19 
20 namespace ipsdk {
21 namespace python {
22 
25 
26 template <typename Container>
27 std::string
28 mapToString(const Container& dataColl)
29 {
30  std::stringstream ss;
31  ss << "{";
32  bool first = true;
33  for (typename Container::const_iterator
34  i = dataColl.begin(), e = dataColl.end(); i != e; ++i) {
35  if (first) {
36  first = false;
37  }
38  else {
39  ss << ", ";
40  }
41  ss << "(" << i->first << ", " << i->second << ")";
42  }
43  ss << "}";
44  return ss.str();
45 }
46 
49 
50 // export map
51 template<class Container>
52 void
53 export_map(const char* py_name) {
54 
55  boost::python::class_<Container>(py_name)
56  .def(boost::python::map_indexing_suite<Container>())
57  .def("__str__", &mapToString<Container>);
58 }
59 
60 // export map
61 template<class Container>
62 void
63 export_map_no_str(const char* py_name) {
64 
65  boost::python::class_<Container>(py_name)
66  .def(boost::python::map_indexing_suite<Container>());
67 }
68 
71 
72 } // end of namespace python
73 } // end of namespace ipsdk
74 
75 #endif // __PYIPSDKBASE_PYTHONSTDMAPUTILS_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22