Commit 4bd204aa authored by Stefan Behnel's avatar Stefan Behnel

reference naming conflict resolution from C++ wrapping doc, show how to wrap...

reference naming conflict resolution from C++ wrapping doc, show how to wrap C++ objects in cdef class attributes
parent ee13190c
......@@ -214,6 +214,8 @@ If ``__stdcall`` is used, the function is only considered compatible with
other ``__stdcall`` functions of the same signature.
.. _resolve-conflicts:
Resolving naming conflicts - C name specifications
--------------------------------------------------
......
......@@ -283,6 +283,9 @@ attribute access, you could just implement some properties::
def __set__(self, x0): self.thisptr.x0 = x0
...
If you prefer giving the same name to the wrapper as the C++ class, see the
section on :ref:`resolving naming conflicts <resolve-conflicts>`.
Advanced C++ features
======================
......@@ -477,6 +480,34 @@ The items in the containers are converted to a corresponding type
automatically, which includes recursively converting containers
inside of containers, e.g. a C++ vector of maps of strings.
Simplified wrapping with default constructor
--------------------------------------------
If your extension type instantiates a wrapped C++ class using the default
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
object. Instead of a pointer attribute, you can declare an instance::
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
Cython will automatically generate code that instantiates the C++ object
instance when the Python object is created and deletes it when the Python
object is garbage collected.
Exceptions
-----------
......
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