Commit eb3e5e6e authored by Robert Bradshaw's avatar Robert Bradshaw

Don't forget std::list.

parent 4a57c2c3
...@@ -2987,7 +2987,7 @@ class CStructOrUnionType(CType): ...@@ -2987,7 +2987,7 @@ class CStructOrUnionType(CType):
return super(CStructOrUnionType, self).cast_code(expr_code) return super(CStructOrUnionType, self).cast_code(expr_code)
builtin_cpp_conversions = ("std::string", "std::vector", "std::set", "std::map", "std::pair") builtin_cpp_conversions = ("std::string", "std::vector", "std::list", "std::set", "std::map", "std::pair")
class CppClassType(CType): class CppClassType(CType):
# name string # name string
......
...@@ -74,8 +74,8 @@ cdef extern from *: ...@@ -74,8 +74,8 @@ cdef extern from *:
void push_back(T&) void push_back(T&)
@cname("{{cname}}") @cname("{{cname}}")
cdef cpp_list[{{T0}}] {{cname}}(object o) except *: cdef cpp_list[X] {{cname}}(object o) except *:
cdef cpp_list[{{T0}}] l cdef cpp_list[X] l
for item in o: for item in o:
l.push_back(X_from_py(item)) l.push_back(X_from_py(item))
return l return l
...@@ -83,6 +83,8 @@ cdef cpp_list[{{T0}}] {{cname}}(object o) except *: ...@@ -83,6 +83,8 @@ cdef cpp_list[{{T0}}] {{cname}}(object o) except *:
#################### list.to_py #################### #################### list.to_py ####################
cimport cython
cdef extern from *: cdef extern from *:
ctypedef struct X "{{T0}}": ctypedef struct X "{{T0}}":
pass pass
...@@ -96,13 +98,14 @@ cdef extern from *: ...@@ -96,13 +98,14 @@ cdef extern from *:
bint operator!=(const_iterator) bint operator!=(const_iterator)
const_iterator begin() const_iterator begin()
const_iterator end() const_iterator end()
cdef cppclass const_cpp_list "const std::list" [T] (cpp_list) cdef cppclass const_cpp_list "const std::list" [T] (cpp_list):
pass
@cname("{{cname}}") @cname("{{cname}}")
cdef object {{cname}}(const_cpp_list[X]& v): cdef object {{cname}}(const_cpp_list[X]& v):
o = [] o = []
cdef cpp_list[X].const_iterator iter = s.begin() cdef cpp_list[X].const_iterator iter = v.begin()
while iter != s.end(): while iter != v.end():
o.append(X_to_py(cython.operator.dereference(iter))) o.append(X_to_py(cython.operator.dereference(iter)))
cython.operator.preincrement(iter) cython.operator.preincrement(iter)
return o return o
......
...@@ -6,6 +6,7 @@ from libcpp.set cimport set as cpp_set ...@@ -6,6 +6,7 @@ from libcpp.set cimport set as cpp_set
from libcpp.string cimport string from libcpp.string cimport string
from libcpp.pair cimport pair from libcpp.pair cimport pair
from libcpp.vector cimport vector from libcpp.vector cimport vector
from libcpp.list cimport list as cpp_list
py_set = set py_set = set
...@@ -67,6 +68,14 @@ def test_pair(o): ...@@ -67,6 +68,14 @@ def test_pair(o):
cdef pair[long, double] p = o cdef pair[long, double] p = o
return p return p
def test_list(o):
"""
>>> test_list([1, 2, 3])
[1, 2, 3]
"""
cdef cpp_list[int] l = o
return l
def test_set(o): def test_set(o):
""" """
>>> sorted(test_set([1, 2, 3])) >>> sorted(test_set([1, 2, 3]))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment