changeset 73:76355b91cd92 vampyhost

Add vector<string> -> Python converter
author Chris Cannam
date Mon, 24 Nov 2014 11:02:20 +0000
parents ffaa1fb3d7de
children e7d03f88ef43
files PyTypeConversions.cpp PyTypeConversions.h
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/PyTypeConversions.cpp	Mon Nov 24 09:50:49 2014 +0000
+++ b/PyTypeConversions.cpp	Mon Nov 24 11:02:20 2014 +0000
@@ -741,6 +741,16 @@
 }
 #endif
 
+PyObject *
+PyTypeConversions::PyValue_From_StringVector(const std::vector<std::string> &v) const
+{
+	PyObject *pyList = PyList_New(v.size());
+	for (size_t i = 0; i < v.size(); ++i) {
+		PyObject *pyStr = PyString_FromString(v[i].c_str());
+		PyList_SET_ITEM(pyList, i, pyStr);
+	}
+	return pyList;
+}
 
 
 /*			   			  	Error handling		   			  		*/
--- a/PyTypeConversions.h	Mon Nov 24 09:50:49 2014 +0000
+++ b/PyTypeConversions.h	Mon Nov 24 11:02:20 2014 +0000
@@ -98,6 +98,8 @@
 	std::vector<float> PyValue_To_FloatVector (PyObject*) const;
 	std::vector<float> PyList_To_FloatVector (PyObject*) const;
 
+	PyObject *PyValue_From_StringVector(const std::vector<std::string> &) const;
+	
 	// Numpy types
 #ifdef HAVE_NUMPY
 	std::vector<float> PyArray_To_FloatVector (PyObject *pyValue) const;