Commit 70c5dca1 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved a wrapper code snippet into the example directory.

parent 084a25f5
# distutils: language = c++
from libcpp.vector cimport vector
cdef class VectorStack:
cdef vector[int] v
def push(self, x):
self.v.push_back(x)
def pop(self):
if self.v.empty():
raise IndexError()
x = self.v.back()
self.v.pop_back()
return x
...@@ -430,20 +430,9 @@ Simplified wrapping with default constructor ...@@ -430,20 +430,9 @@ Simplified wrapping with default constructor
If your extension type instantiates a wrapped C++ class using the default If your extension type instantiates a wrapped C++ class using the default
constructor (not passing any arguments), you may be able to simplify the constructor (not passing any arguments), you may be able to simplify the
lifecycle handling by tying it directly to the lifetime of the Python wrapper lifecycle handling by tying it directly to the lifetime of the Python wrapper
object. Instead of a pointer attribute, you can declare an instance:: object. Instead of a pointer attribute, you can declare an instance:
cdef class VectorStack: .. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
cdef vector[int] v
def push(self, x):
self.v.push_back(x)
def pop(self):
if self.v.empty():
raise IndexError()
x = self.v.back()
self.v.pop_back()
return x
Cython will automatically generate code that instantiates the C++ object Cython will automatically generate code that instantiates the C++ object
instance when the Python object is created and deletes it when the Python instance when the Python object is created and deletes it when the Python
......
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