Skip to content

Commit 26653fc

Browse files
committed
Fixed compilation with NumericObject.cpp
1 parent aed55c8 commit 26653fc

File tree

5 files changed

+253
-57
lines changed

5 files changed

+253
-57
lines changed

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def remove_if_exist(filename):
113113

114114
system = extension(
115115
'system',
116-
['system.pyx', 'error.cpp', 'hacks.cpp'],#, 'NumericObject.cpp'],
116+
['system.pyx', 'error.cpp', 'hacks.cpp', 'NumericObject.cpp'],
117117
['sfml-system'])
118118

119119
window = extension(
@@ -123,7 +123,7 @@ def remove_if_exist(filename):
123123

124124
graphics = extension(
125125
'graphics',
126-
['graphics.pyx', 'DerivableRenderWindow.cpp', 'DerivableDrawable.cpp'],
126+
['graphics.pyx', 'DerivableRenderWindow.cpp', 'DerivableDrawable.cpp', 'NumericObject.cpp'],
127127
['sfml-system', 'sfml-window', 'sfml-graphics'])
128128

129129
audio = extension(

src/sfml/NumericObject.cpp renamed to src/sfml/graphics/NumericObject.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
//------------------------------------------------------------------------------
2-
// PySFML - Python bindings for SFML
3-
// Copyright (c) 2012-2014, Jonathan De Wachter <dewachter.jonathan@gmail.com>
4-
// Edwin Marshall <emarshall85@gmail.com>
5-
//
6-
// This software is provided 'as-is', without any express or implied warranty.
7-
// In no event will the authors be held liable for any damages arising from the
8-
// use of this software.
9-
//
10-
// Permission is granted to anyone to use this software for any purpose,
11-
// including commercial applications, and to alter it and redistribute it
12-
// freely, subject to the following restrictions:
13-
//
14-
// 1. The origin of this software must not be misrepresented; you must not
15-
// claim that you wrote the original software. If you use this software in a
16-
// product, an acknowledgment in the product documentation would be
17-
// appreciated but is not required.
18-
//
19-
// 2. Altered source versions must be plainly marked as such, and must not be
20-
// misrepresented as being the original software.
21-
//
22-
// 3. This notice may not be removed or altered from any source distribution.
23-
//------------------------------------------------------------------------------
24-
25-
#include "pysfml/NumericObject.hpp"
1+
/*
2+
* PySFML - Python bindings for SFML
3+
* Copyright (c) 2012-2016, Jonathan De Wachter <dewachter.jonathan@gmail.com>
4+
* Edwin Marshall <emarshall85@gmail.com>
5+
*
6+
* This file is part of PySFML project and is available under the zlib
7+
* license.
8+
*/
9+
10+
#include <pysfml/graphics/NumericObject.hpp>
2611

2712
NumericObject::NumericObject()
2813
: m_object(NULL)

include/pysfml/NumericObject.hpp renamed to src/sfml/graphics/NumericObject.hpp

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
1-
//------------------------------------------------------------------------------
2-
// PySFML - Python bindings for SFML
3-
// Copyright (c) 2012-2014, Jonathan De Wachter <dewachter.jonathan@gmail.com>
4-
// Edwin Marshall <emarshall85@gmail.com>
5-
//
6-
// This software is provided 'as-is', without any express or implied warranty.
7-
// In no event will the authors be held liable for any damages arising from the
8-
// use of this software.
9-
//
10-
// Permission is granted to anyone to use this software for any purpose,
11-
// including commercial applications, and to alter it and redistribute it
12-
// freely, subject to the following restrictions:
13-
//
14-
// 1. The origin of this software must not be misrepresented; you must not
15-
// claim that you wrote the original software. If you use this software in a
16-
// product, an acknowledgment in the product documentation would be
17-
// appreciated but is not required.
18-
//
19-
// 2. Altered source versions must be plainly marked as such, and must not be
20-
// misrepresented as being the original software.
21-
//
22-
// 3. This notice may not be removed or altered from any source distribution.
23-
//------------------------------------------------------------------------------
24-
25-
#ifndef PYSFML_NUMERICOBJECT_HPP
26-
#define PYSFML_NUMERICOBJECT_HPP
1+
/*
2+
* PySFML - Python bindings for SFML
3+
* Copyright (c) 2012-2016, Jonathan De Wachter <dewachter.jonathan@gmail.com>
4+
* Edwin Marshall <emarshall85@gmail.com>
5+
*
6+
* This file is part of PySFML project and is available under the zlib
7+
* license.
8+
*/
9+
10+
#ifndef PYSFML_GRAPHICS_NUMERICOBJECT_HPP
11+
#define PYSFML_GRAPHICS_NUMERICOBJECT_HPP
2712

2813
#include "Python.h"
29-
#include <SFML/Window/Window.hpp>
14+
#include <SFML/Config.hpp>
3015

31-
class NumericObject
16+
class SFML_API_EXPORT NumericObject
3217
{
3318
public:
3419
NumericObject();
@@ -70,5 +55,4 @@ class NumericObject
7055
PyObject* m_object;
7156
};
7257

73-
74-
#endif // PYSFML_NUMERICOBJECT_HPP
58+
#endif // PYSFML_GRAPHICS_NUMERICOBJECT_HPP

src/sfml/system/NumericObject.cpp

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* PySFML - Python bindings for SFML
3+
* Copyright (c) 2012-2016, Jonathan De Wachter <dewachter.jonathan@gmail.com>
4+
* Edwin Marshall <emarshall85@gmail.com>
5+
*
6+
* This file is part of PySFML project and is available under the zlib
7+
* license.
8+
*/
9+
10+
#include <pysfml/system/NumericObject.hpp>
11+
12+
NumericObject::NumericObject()
13+
: m_object(NULL)
14+
{
15+
}
16+
17+
NumericObject::NumericObject(const NumericObject& copy)
18+
{
19+
m_object = copy.m_object;
20+
Py_INCREF(m_object);
21+
}
22+
23+
NumericObject::NumericObject(PyObject* object)
24+
: m_object(object)
25+
{
26+
Py_XINCREF(m_object);
27+
}
28+
29+
NumericObject::~NumericObject()
30+
{
31+
Py_XDECREF(m_object);
32+
}
33+
34+
PyObject* NumericObject::NumericObject::get()
35+
{
36+
Py_XINCREF(m_object);
37+
return m_object;
38+
}
39+
40+
void NumericObject::set(PyObject* object)
41+
{
42+
if (m_object)
43+
Py_DECREF(m_object);
44+
45+
m_object = object;
46+
Py_INCREF(m_object);
47+
}
48+
49+
NumericObject NumericObject::operator+() const
50+
{
51+
return PyNumber_Positive(const_cast<PyObject*>(m_object));
52+
}
53+
54+
NumericObject NumericObject::operator-() const
55+
{
56+
return PyNumber_Negative(const_cast<PyObject*>(m_object));
57+
}
58+
59+
NumericObject NumericObject::operator+(const NumericObject& object) const
60+
{
61+
return PyNumber_Add(m_object, object.m_object);
62+
}
63+
64+
NumericObject NumericObject::operator-(const NumericObject& object) const
65+
{
66+
return PyNumber_Subtract(m_object, object.m_object);
67+
}
68+
69+
NumericObject NumericObject::operator*(const NumericObject& object) const
70+
{
71+
return PyNumber_Multiply(m_object, object.m_object);
72+
}
73+
74+
NumericObject NumericObject::operator/(const NumericObject& object) const
75+
{
76+
return PyNumber_TrueDivide(m_object, object.m_object);
77+
}
78+
79+
NumericObject NumericObject::operator~() const
80+
{
81+
return PyNumber_Invert(const_cast<PyObject*>(m_object));
82+
}
83+
84+
NumericObject NumericObject::operator&(const NumericObject& object) const
85+
{
86+
return PyNumber_And(m_object, object.m_object);
87+
}
88+
89+
NumericObject NumericObject::operator|(const NumericObject& object) const
90+
{
91+
return PyNumber_Or(m_object, object.m_object);
92+
}
93+
94+
NumericObject NumericObject::operator^(const NumericObject& object) const
95+
{
96+
return PyNumber_Xor(m_object, object.m_object);
97+
}
98+
99+
NumericObject& NumericObject::operator+=(const NumericObject& b)
100+
{
101+
m_object = PyNumber_InPlaceAdd(m_object, b.m_object);
102+
return *this;
103+
}
104+
105+
NumericObject& NumericObject::operator-=(const NumericObject& b)
106+
{
107+
m_object = PyNumber_InPlaceSubtract(m_object, b.m_object);
108+
return *this;
109+
}
110+
111+
NumericObject& NumericObject::operator*=(const NumericObject& b)
112+
{
113+
m_object = PyNumber_InPlaceMultiply(m_object, b.m_object);
114+
return *this;
115+
}
116+
117+
NumericObject& NumericObject::operator/=(const NumericObject& b)
118+
{
119+
m_object = PyNumber_InPlaceTrueDivide(m_object, b.m_object);
120+
return *this;
121+
}
122+
123+
NumericObject& NumericObject::operator&=(const NumericObject& b)
124+
{
125+
m_object = PyNumber_InPlaceAnd(m_object, b.m_object);
126+
return *this;
127+
}
128+
129+
NumericObject& NumericObject::operator|=(const NumericObject& b)
130+
{
131+
m_object = PyNumber_InPlaceOr(m_object, b.m_object);
132+
return *this;
133+
}
134+
135+
NumericObject& NumericObject::operator^=(const NumericObject& b)
136+
{
137+
m_object = PyNumber_InPlaceXor(m_object, b.m_object);
138+
return *this;
139+
}
140+
141+
bool NumericObject::operator==(const NumericObject &b) const
142+
{
143+
return PyObject_RichCompareBool(m_object, b.m_object, Py_EQ);
144+
}
145+
146+
bool NumericObject::operator!=(const NumericObject &b) const
147+
{
148+
return PyObject_RichCompareBool(m_object, b.m_object, Py_NE);
149+
}
150+
151+
bool NumericObject::operator<(const NumericObject &b) const
152+
{
153+
return PyObject_RichCompareBool(m_object, b.m_object, Py_LT);
154+
}
155+
156+
bool NumericObject::operator>(const NumericObject &b) const
157+
{
158+
return PyObject_RichCompareBool(m_object, b.m_object, Py_GT);
159+
}
160+
161+
bool NumericObject::operator<=(const NumericObject &b) const
162+
{
163+
return PyObject_RichCompareBool(m_object, b.m_object, Py_LE);
164+
}
165+
166+
bool NumericObject::operator>=(const NumericObject &b) const
167+
{
168+
return PyObject_RichCompareBool(m_object, b.m_object, Py_GE);
169+
}

src/sfml/system/NumericObject.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* PySFML - Python bindings for SFML
3+
* Copyright (c) 2012-2016, Jonathan De Wachter <dewachter.jonathan@gmail.com>
4+
* Edwin Marshall <emarshall85@gmail.com>
5+
*
6+
* This file is part of PySFML project and is available under the zlib
7+
* license.
8+
*/
9+
10+
#ifndef PYSFML_SYSTEM_NUMERICOBJECT_HPP
11+
#define PYSFML_SYSTEM_NUMERICOBJECT_HPP
12+
13+
#include "Python.h"
14+
#include <SFML/Config.hpp>
15+
16+
class SFML_API_EXPORT NumericObject
17+
{
18+
public:
19+
NumericObject();
20+
NumericObject(const NumericObject& copy);
21+
NumericObject(PyObject* object);
22+
23+
~NumericObject();
24+
25+
PyObject* get();
26+
void set(PyObject* object);
27+
28+
NumericObject operator+() const;
29+
NumericObject operator-() const;
30+
NumericObject operator+(const NumericObject& object) const;
31+
NumericObject operator-(const NumericObject& object) const;
32+
NumericObject operator*(const NumericObject& object) const;
33+
NumericObject operator/(const NumericObject& object) const;
34+
NumericObject operator~() const;
35+
NumericObject operator&(const NumericObject& object) const;
36+
NumericObject operator|(const NumericObject& object) const;
37+
NumericObject operator^(const NumericObject& object) const;
38+
39+
NumericObject& operator+=(const NumericObject& b);
40+
NumericObject& operator-=(const NumericObject& b);
41+
NumericObject& operator*=(const NumericObject& b);
42+
NumericObject& operator/=(const NumericObject& b);
43+
NumericObject& operator&=(const NumericObject& b);
44+
NumericObject& operator|=(const NumericObject& b);
45+
NumericObject& operator^=(const NumericObject& b);
46+
47+
bool operator==(const NumericObject &b) const;
48+
bool operator!=(const NumericObject &b) const;
49+
bool operator<(const NumericObject &b) const;
50+
bool operator>(const NumericObject &b) const;
51+
bool operator<=(const NumericObject &b) const;
52+
bool operator>=(const NumericObject &b) const;
53+
54+
private:
55+
PyObject* m_object;
56+
};
57+
58+
#endif // PYSFML_SYSTEM_NUMERICOBJECT_HPP

0 commit comments

Comments
 (0)