Skip to content

Commit 073b4c4

Browse files
author
AshleySetter
committed
added comments saying what everything in the pyx file does
1 parent 47ff547 commit 073b4c4

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎ClassCythonCPP/TestClass.pyx‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import cython
22

3-
cdef extern from "TestClassC.cpp":
4-
cdef cppclass TestClass:
5-
TestClass(int Dimensionality)
6-
int Dimensionality
3+
cdef extern from "TestClassC.cpp": # defines the source C++ file
4+
cdef cppclass TestClass: # says that there is a class defined in the above C++ file called TestClass
5+
TestClass(int Dimensionality) # the class has public member function TestClass which takes some arguments
6+
int Dimensionality # the class has a public variable that is an integer and is called Dimensionality
77

8-
cdef class CTestClass:
9-
cdef TestClass* thisptr # hold a C++ instance
10-
def __cinit__(self, int Dimensionality):
11-
self.thisptr = new TestClass(Dimensionality)
12-
def __dealloc__(self):
13-
del self.thisptr
8+
cdef class CTestClass: # defines a python wrapper to the C++ class
9+
cdef TestClass* thisptr # thisptr is a pointer that will hold to the instance of the C++ class
10+
def __cinit__(self, int Dimensionality): # defines the python wrapper class' init function
11+
self.thisptr = new TestClass(Dimensionality) # creates an instance of the C++ class and puts allocates the pointer to thisB
12+
def __dealloc__(self): # defines the python wrapper class' deallocation function (python destructor)
13+
del self.thisptr # destroys the reference to the C++ instance (which calls the C++ class destructor
1414

0 commit comments

Comments
 (0)