File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import 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
You can’t perform that action at this time.
0 commit comments