test_cpp.pyx 1.13 KB
Newer Older
gsamain's avatar
gsamain committed
1 2
# distutils: language = c++

gsamain's avatar
gsamain committed
3 4
#cdef extern from "unistd.h" nogil:
#    unsigned int sleep(unsigned int seconds)
gsamain's avatar
gsamain committed
5

gsamain's avatar
gsamain committed
6
cdef cppclass Rectangle nogil:
gsamain's avatar
gsamain committed
7
    int a
gsamain's avatar
gsamain committed
8

gsamain's avatar
gsamain committed
9 10
    void test():
        this.a += 3
gsamain's avatar
gsamain committed
11

gsamain's avatar
gsamain committed
12 13
    void test(int a):
        this.a += a
gsamain's avatar
gsamain committed
14

gsamain's avatar
gsamain committed
15 16
    void Rectangle(int a):
        this.a = a
gsamain's avatar
gsamain committed
17

gsamain's avatar
gsamain committed
18
    void Rectangle():
gsamain's avatar
gsamain committed
19 20 21 22 23
        this.a = 5

cdef cypclass Rectangle_wrapper(Rectangle):

    Rectangle_wrapper __iadd__(Rectangle_wrapper other):
gsamain's avatar
gsamain committed
24 25
        return this

gsamain's avatar
gsamain committed
26
    Rectangle_wrapper __le__(Rectangle_wrapper other):
gsamain's avatar
gsamain committed
27 28
        return other

gsamain's avatar
gsamain committed
29 30

cdef cypclass Carre(Rectangle_wrapper):
gsamain's avatar
gsamain committed
31
    int b
gsamain's avatar
gsamain committed
32

gsamain's avatar
gsamain committed
33
    void __dealloc__():
gsamain's avatar
gsamain committed
34 35
        pass

gsamain's avatar
gsamain committed
36 37 38
    void __init__(int a):
        Rectangle.__init__(a)

gsamain's avatar
gsamain committed
39 40 41 42 43 44 45 46 47 48 49 50 51
    void test():
        this.a += 5


cdef cypclass Truc(Rectangle_wrapper):
    Carre c

    void __init__(int a=1):
        # Rectangle.__init__() is always called
        this.c = Carre(a)

    void __dealloc__():
        del this.c
gsamain's avatar
gsamain committed
52

gsamain's avatar
gsamain committed
53 54
cdef cppclass SomeMemory(Truc) nogil:
    int d
gsamain's avatar
gsamain committed
55 56

cdef int tipo() nogil:
gsamain's avatar
gsamain committed
57 58 59 60 61 62 63 64 65
    cdef Carre c = Carre(32)
    cdef Truc truc = Truc()

    truc += c

    truc.c.Rectangle.test()
    #truc.c.test()

    return truc.c.a
gsamain's avatar
gsamain committed
66 67 68

def toto():
    print(tipo())