Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
70c5dca1
Commit
70c5dca1
authored
Jun 29, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved a wrapper code snippet into the example directory.
parent
084a25f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
docs/examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
.../examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
+17
-0
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+2
-13
No files found.
docs/examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
0 → 100644
View file @
70c5dca1
# 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
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
70c5dca1
...
...
@@ -430,20 +430,9 @@ 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:
:
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
.. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
Cython will automatically generate code that instantiates the C++ object
instance when the Python object is created and deletes it when the Python
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment