Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pybindgen/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, add_value_method, is_mapping=False):
container_traits_list['dequeue'] = container_traits_list['deque']

class Container(object):
def __init__(self, name, value_type, container_type, outer_class=None, custom_name=None):
def __init__(self, name, value_type, container_type, outer_class=None, custom_name=None, auto_convert=None):
"""
:param name: C++ type name of the container, e.g. std::vector<int> or MyIntList

Expand All @@ -116,6 +116,7 @@ def __init__(self, name, value_type, container_type, outer_class=None, custom_na
:type outer_class: None or L{CppClass}

:param custom_name: alternative name to register with in the Python module
:param auto_convert: Python type ("PyList_Type", "PyDict_Type", etc.) to convert the result to get richer methods

"""
if '<' in name or '::' in name:
Expand All @@ -139,6 +140,7 @@ def __init__(self, name, value_type, container_type, outer_class=None, custom_na
self.iter_pytypestruct = "***GIVE ME A NAME***"
self.iter_pytype = PyTypeObject()
self._iter_pystruct = None
self.auto_convert = auto_convert

if self.container_traits.is_mapping:
(key_type, value_type) = value_type
Expand Down Expand Up @@ -857,6 +859,9 @@ def convert_c_to_python(self, wrapper):
"%s = PyObject_New(%s, %s);" %
(py_name, self.container_type.pystruct, '&'+self.container_type.pytypestruct))
wrapper.after_call.write_code("%s->obj = new %s(%s);" % (self.py_name, self.container_type.full_name, self.value))
if self.container_type.auto_convert:
wrapper.after_call.add_cleanup_code("py_retval = PyType_Type.tp_call((PyObject*)&%s,Py_BuildValue(\"(O)\",py_retval),Py_BuildValue(\"{}\"));" % ( self.container_type.auto_convert))

wrapper.build_params.add_parameter("N", [py_name], prepend=True)

def convert_python_to_c(self, wrapper):
Expand Down
Loading