Commit e00ee0a2 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow nesting.

parent 1aa49b25
...@@ -30,7 +30,6 @@ class BaseType(object): ...@@ -30,7 +30,6 @@ class BaseType(object):
all.append(c) all.append(c)
else: else:
all.append('_%x_' % ord(c)) all.append('_%x_' % ord(c))
print self.declaration_code(""), ''.join(all)
return ''.join(all) return ''.join(all)
def base_declaration_code(self, base_code, entity_code): def base_declaration_code(self, base_code, entity_code):
...@@ -3026,9 +3025,12 @@ class CppClassType(CType): ...@@ -3026,9 +3025,12 @@ class CppClassType(CType):
if not T.create_from_py_utility_code(env): if not T.create_from_py_utility_code(env):
return False return False
tags.append(T.specialization_name()) tags.append(T.specialization_name())
context["T%s" % ix] = T.declaration_code("", for_display=True) # TODO: exception values
context["T%s" % ix] = T.declaration_code("")
context["T%s_from_py" % ix] = T.from_py_function
cls = self.cname[5:] cls = self.cname[5:]
cname = "__pyx_convert_%s_from_py_%s" % (cls, "____".join(tags)) cname = "__pyx_convert_%s_from_py_%s" % (cls, "____".join(tags))
print cls, "->", cname
context['cname'] = cname context['cname'] = cname
from UtilityCode import CythonUtilityCode from UtilityCode import CythonUtilityCode
env.use_utility_code(CythonUtilityCode.load(cls + ".from_py", "CppConvert.pyx", context=context)) env.use_utility_code(CythonUtilityCode.load(cls + ".from_py", "CppConvert.pyx", context=context))
...@@ -3045,7 +3047,8 @@ class CppClassType(CType): ...@@ -3045,7 +3047,8 @@ class CppClassType(CType):
if not T.create_to_py_utility_code(env): if not T.create_to_py_utility_code(env):
return False return False
tags.append(T.specialization_name()) tags.append(T.specialization_name())
context["T%s" % ix] = T.declaration_code("", for_display=True) context["T%s" % ix] = T.declaration_code("")
context["T%s_to_py" % ix] = T.to_py_function
cls = self.cname[5:] cls = self.cname[5:]
cname = "__pyx_convert_%s_to_py_%s" % (cls, "____".join(tags)) cname = "__pyx_convert_%s_to_py_%s" % (cls, "____".join(tags))
context['cname'] = cname context['cname'] = cname
......
...@@ -94,6 +94,9 @@ cdef extern from "<string>" namespace "std": ...@@ -94,6 +94,9 @@ cdef extern from "<string>" namespace "std":
#string& operator= (char*) #string& operator= (char*)
#string& operator= (char) #string& operator= (char)
string operator+ (string& rhs) nogil
string operator+ (char* rhs) nogil
bint operator==(string&) nogil bint operator==(string&) nogil
bint operator==(char*) nogil bint operator==(char*) nogil
......
...@@ -152,6 +152,14 @@ cdef object {{cname}}(pair[{{T0}},{{T1}}]& p): ...@@ -152,6 +152,14 @@ cdef object {{cname}}(pair[{{T0}},{{T1}}]& p):
#################### map.from_py #################### #################### map.from_py ####################
cdef extern from *:
ctypedef struct X "{{T0}}":
pass
ctypedef struct Y "{{T1}}":
pass
cdef X X_from_py "{{T0_from_py}}" (object) except *
cdef Y Y_from_py "{{T1_from_py}}" (object) except *
cdef extern from *: cdef extern from *:
cdef cppclass pair "std::pair" [T, U]: cdef cppclass pair "std::pair" [T, U]:
pair(T&, U&) pair(T&, U&)
...@@ -165,11 +173,11 @@ cdef extern from *: ...@@ -165,11 +173,11 @@ cdef extern from *:
@cname("{{cname}}") @cname("{{cname}}")
cdef map[{{T0}},{{T1}}] {{cname}}(object o) except *: cdef map[X,Y] {{cname}}(object o) except *:
cdef dict d = o cdef dict d = o
cdef map[{{T0}},{{T1}}] m cdef map[X,Y] m
for key, value in d.iteritems(): for key, value in d.iteritems():
m.insert(pair[{{T0}},{{T1}}](<{{T0}}>key, <{{T1}}>value)) m.insert(pair[X,Y](X_from_py(key), Y_from_py(value)))
return m return m
...@@ -179,6 +187,13 @@ cdef map[{{T0}},{{T1}}] {{cname}}(object o) except *: ...@@ -179,6 +187,13 @@ cdef map[{{T0}},{{T1}}] {{cname}}(object o) except *:
cimport cython cimport cython
cdef extern from *:
ctypedef struct X "{{T0}}":
pass
ctypedef struct Y "{{T1}}":
pass
cdef object X_to_py "{{T0_to_py}}" (X)
cdef object Y_to_py "{{T1_to_py}}" (Y)
cdef extern from *: cdef extern from *:
cdef cppclass map "std::map" [T, U]: cdef cppclass map "std::map" [T, U]:
...@@ -193,12 +208,12 @@ cdef extern from *: ...@@ -193,12 +208,12 @@ cdef extern from *:
iterator end() iterator end()
@cname("{{cname}}") @cname("{{cname}}")
cdef object {{cname}}(map[{{T0}},{{T1}}] s): cdef object {{cname}}(map[X,Y] s):
o = {} o = {}
cdef map[{{T0}},{{T1}}].value_type *key_value cdef map[X,Y].value_type *key_value
cdef map[{{T0}},{{T1}}].iterator iter = s.begin() cdef map[X,Y].iterator iter = s.begin()
while iter != s.end(): while iter != s.end():
key_value = &cython.operator.dereference(iter) key_value = &cython.operator.dereference(iter)
o[key_value.first] = key_value.second o[X_to_py(key_value.first)] = Y_to_py(key_value.second)
cython.operator.preincrement(iter) cython.operator.preincrement(iter)
return o return o
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