summaryrefslogtreecommitdiff
path: root/src/pyutils.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-19 21:53:02 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-19 22:24:24 -0500
commit4e30fcdf4094a0c450cbe1918c2e12dd19eb58f2 (patch)
treee4bce67522d52cd7be03544501191d761dce7799 /src/pyutils.h
parent6e31328bd62d15e8da4238394abd8de65539cfa2 (diff)
downloadfork-ledger-4e30fcdf4094a0c450cbe1918c2e12dd19eb58f2.tar.gz
fork-ledger-4e30fcdf4094a0c450cbe1918c2e12dd19eb58f2.tar.bz2
fork-ledger-4e30fcdf4094a0c450cbe1918c2e12dd19eb58f2.zip
Many improvements to Ledger's Python bindings
Diffstat (limited to 'src/pyutils.h')
-rw-r--r--src/pyutils.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/pyutils.h b/src/pyutils.h
index a9e968e0..d8a46527 100644
--- a/src/pyutils.h
+++ b/src/pyutils.h
@@ -106,6 +106,26 @@ struct register_optional_to_python : public boost::noncopyable
}
};
+template <typename T1, typename T2>
+struct PairToTupleConverter
+{
+ static PyObject * convert(const std::pair<T1, T2>& pair) {
+ return boost::python::incref
+ (boost::python::make_tuple(pair.first, pair.second).ptr());
+ }
+};
+
+template <typename MapType>
+struct map_value_type_converter
+{
+ map_value_type_converter() {
+ boost::python::to_python_converter
+ <typename MapType::value_type,
+ PairToTupleConverter<const typename MapType::key_type,
+ typename MapType::mapped_type> >();
+ }
+};
+
namespace boost { namespace python {
// Use expr to create the PyObject corresponding to x