1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of Qt for Python.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #ifndef VIRTUALMETHODS_H
30 #define VIRTUALMETHODS_H
31 
32 #include "point.h"
33 #include "complex.h"
34 #include "str.h"
35 
36 #include "libsamplemacros.h"
37 #include "strlist.h"
38 
39 class LIBSAMPLE_API VirtualMethods
40 {
41 public:
m_name(name)42     VirtualMethods(Str name = "VirtualMethods") : m_name(name)
43     {
44         m_left = m_top = m_right = m_bottom = 0;
45     }
~VirtualMethods()46     virtual ~VirtualMethods() {}
47 
48     virtual double virtualMethod0(Point pt, int val, Complex cpx, bool b);
callVirtualMethod0(Point pt,int val,Complex cpx,bool b)49     double callVirtualMethod0(Point pt, int val, Complex cpx, bool b)
50     {
51         return virtualMethod0(pt, val, cpx, b);
52     }
53 
54     // Binding modification: rename.
sum0(int a0,int a1,int a2)55     virtual int sum0(int a0, int a1, int a2) { return a0 + a1 + a2; }
callSum0(int a0,int a1,int a2)56     int callSum0(int a0, int a1, int a2) { return sum0(a0, a1, a2); }
57 
58     // Binding modification: set default value for the last argument.
sum1(int a0,int a1,int a2)59     virtual int sum1(int a0, int a1, int a2) { return a0 + a1 + a2; }
callSum1(int a0,int a1,int a2)60     int callSum1(int a0, int a1, int a2) { return sum1(a0, a1, a2); }
61 
62     // Binding modification: remove the last argument and set a default value for it.
sum2(int a0,int a1,int a2)63     virtual int sum2(int a0, int a1, int a2) { return a0 + a1 + a2; }
callSum2(int a0,int a1,int a2)64     int callSum2(int a0, int a1, int a2) { return sum2(a0, a1, a2); }
65 
66     // Binding modification: remove the second argument.
sum3(int a0,int a1,int a2)67     virtual int sum3(int a0, int a1, int a2) { return a0 + a1 + a2; }
callSum3(int a0,int a1,int a2)68     int callSum3(int a0, int a1, int a2) { return sum3(a0, a1, a2); }
69 
70     // Binding modification: remove the second argument and set its default
71     // value, then inject code on the binding reimplementation of the virtual
72     // (with a native inject-code) to sum the value of the removed
73     // argument to the first argument before the method is called.
sum4(int a0,int a1,int a2)74     virtual int sum4(int a0, int a1, int a2) { return a0 + a1 + a2; }
callSum4(int a0,int a1,int a2)75     int callSum4(int a0, int a1, int a2) { return sum4(a0, a1, a2); }
76 
77     // Binding modification: prepend a string to the results of a Python override.
name()78     virtual Str name() { return m_name; }
callName()79     Str callName() { return name(); }
80 
81     // Binding modification: code injection that calls the Python override by itself.
callMe()82     virtual void callMe() {}
callCallMe()83     void callCallMe() { callMe(); }
84 
85     // Passing reference to pointers.
86     virtual bool createStr(const char* text, Str*& ret);
callCreateStr(const char * text,Str * & ret)87     bool callCreateStr(const char* text, Str*& ret) { return createStr(text, ret); }
88 
89     // Return a non-binded method
callStrListToStdList(const StrList & strList)90     std::list<Str> callStrListToStdList(const StrList& strList) { return strListToStdList(strList); }
strListToStdList(const StrList & strList)91     virtual std::list<Str> strListToStdList(const StrList& strList ) { return strList; }
92 
setMargins(int left,int top,int right,int bottom)93     void setMargins(int left, int top, int right, int bottom)
94     {
95         m_left = left;
96         m_top = top;
97         m_right = right;
98         m_bottom = bottom;
99     }
100     virtual void getMargins(int* left, int* top, int* right, int* bottom) const;
callGetMargins(int * left,int * top,int * right,int * bottom)101     void callGetMargins(int* left, int* top, int* right, int* bottom) const
102     {
103         getMargins(left, top, right, bottom);
104     }
105 
recursionOnModifiedVirtual(Str arg)106     virtual int recursionOnModifiedVirtual(Str arg) const { return 0; }
callRecursionOnModifiedVirtual(Str arg)107     int callRecursionOnModifiedVirtual(Str arg) const { return recursionOnModifiedVirtual(arg); }
108 
109     virtual const Str & returnConstRef() const;
110 
111 protected:
112     // PYSIDE-1388: Protected hack with final classes (see VirtualFinalDaughter).
protectedMethod()113     void protectedMethod() {}
114 
115 private:
116     Str m_name;
117     int m_left;
118     int m_top;
119     int m_right;
120     int m_bottom;
121 };
122 
123 class LIBSAMPLE_API VirtualDaughter : public VirtualMethods
124 {
125 public:
VirtualDaughter()126     VirtualDaughter() : VirtualMethods() {}
VirtualDaughter(Str name)127     VirtualDaughter(Str name) : VirtualMethods(name) {}
128 };
129 
130 class LIBSAMPLE_API VirtualDaughter2 : public VirtualMethods
131 {
132 public:
VirtualDaughter2()133     VirtualDaughter2() : VirtualMethods("VirtualDaughter2") {}
134 
135     double virtualMethod0(Point pt, int val, Complex cpx, bool b) override;
136     int sum0(int a0, int a1, int a2) final;
137 };
138 
139 class LIBSAMPLE_API VirtualFinalDaughter final : public VirtualMethods
140 {
141 public:
VirtualFinalDaughter()142     VirtualFinalDaughter() : VirtualMethods("VirtualFinalDaughter") {}
143 
144     double virtualMethod0(Point pt, int val, Complex cpx, bool b) override;
145     int sum0(int a0, int a1, int a2) override;
146 };
147 
148 class LIBSAMPLE_API VirtualDtor
149 {
150 public:
VirtualDtor()151     VirtualDtor() {}
~VirtualDtor()152     virtual ~VirtualDtor() { dtor_called++; }
153 
create()154     static VirtualDtor* create() { return new VirtualDtor(); }
dtorCalled()155     static int dtorCalled() { return dtor_called; }
resetDtorCounter()156     static void resetDtorCounter() { dtor_called = 0; }
157 
158 private:
159     static int dtor_called;
160 };
161 
162 #endif // VIRTUALMETHODS_H
163 
164