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 #include <iostream>
30 #include "modifications.h"
31 #include "objecttype.h"
32
33 using namespace std;
34
Modifications()35 Modifications::Modifications()
36 {
37 m_object = new ObjectType();
38 m_object->setObjectName("MyObject");
39 }
40
~Modifications()41 Modifications::~Modifications()
42 {
43 delete m_object;
44 }
45
46 std::pair<double, double>
pointToPair(Point pt,bool * ok)47 Modifications::pointToPair(Point pt, bool* ok)
48 {
49 std::pair<double, double> retval(pt.x(), pt.y());
50 *ok = true;
51 return retval;
52 }
53
54 double
multiplyPointCoordsPlusValue(bool * ok,Point pt,double value)55 Modifications::multiplyPointCoordsPlusValue(bool* ok, Point pt, double value)
56 {
57 double retval = (pt.x() * pt.y()) + value;
58 *ok = true;
59 return retval;
60 }
61
62 int
doublePlus(int value,int plus)63 Modifications::doublePlus(int value, int plus)
64 {
65 return (2 * value) + plus;
66 }
67
68 int
power(int base,int exponent)69 Modifications::power(int base, int exponent)
70 {
71 if (exponent == 0)
72 return 1;
73 int retval = base;
74 for (int i = 1; i < exponent; i++)
75 retval = retval * base;
76 return retval;
77 }
78
79 int
timesTen(int number)80 Modifications::timesTen(int number)
81 {
82 return number * 10;
83 }
84
85 int
increment(int number)86 Modifications::increment(int number)
87 {
88 return ++number;
89 }
90
91 void
exclusiveCppStuff()92 Modifications::exclusiveCppStuff()
93 {
94 cout << __FUNCTION__ << endl;
95 }
96
97 int
cppMultiply(int a,int b)98 Modifications::cppMultiply(int a, int b)
99 {
100 return a * b;
101 }
102
103 const char*
className()104 Modifications::className()
105 {
106 return "Modifications";
107 }
108
109 Point
sumPointArray(int arraySize,const Point pointArray[])110 Modifications::sumPointArray(int arraySize, const Point pointArray[])
111 {
112 Point point;
113 for (int i = 0; i < arraySize; ++i)
114 point = point + pointArray[i];
115 return point;
116 }
117
118 int
getSize(const void * data,int size)119 Modifications::getSize(const void* data, int size)
120 {
121 (void)data;
122 return size;
123 }
124
125 int
sumPointCoordinates(const Point * point)126 Modifications::sumPointCoordinates(const Point* point)
127 {
128 return point->x() + point->y();
129 }
130
131 double
differenceOfPointCoordinates(const Point * pt,bool * ok)132 Modifications::differenceOfPointCoordinates(const Point* pt, bool* ok)
133 {
134 if (!pt) {
135 *ok = false;
136 return 0.0;
137 }
138 *ok = true;
139 double result = pt->x() - pt->y();
140 if (result < 0)
141 result = result * -1.0;
142 return result;
143 }
144
145 bool
nonConversionRuleForArgumentWithDefaultValue(ObjectType ** object)146 Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType** object)
147 {
148 if (object)
149 *object = m_object;
150 return true;
151 }
152
setEnumValue(TestEnum e)153 void Modifications::setEnumValue(TestEnum e)
154 {
155 m_enumValue = e;
156 }
157
enumValue() const158 Modifications::TestEnum Modifications::enumValue() const
159 {
160 return m_enumValue;
161 }
162
defaultEnumValue() const163 Modifications::TestEnum Modifications::defaultEnumValue() const
164 {
165 return TestEnumValue2;
166 }
167
wasGetAttroCalled() const168 bool Modifications::wasGetAttroCalled() const
169 {
170 return m_getAttroCalled;
171 }
172
notifyGetAttroCalled()173 void Modifications::notifyGetAttroCalled()
174 {
175 m_getAttroCalled = true;
176 }
177
wasSetAttroCalled() const178 bool Modifications::wasSetAttroCalled() const
179 {
180 return m_setAttroCalled;
181 }
182
notifySetAttroCalled()183 void Modifications::notifySetAttroCalled()
184 {
185 m_setAttroCalled = true;
186 }
187