summaryrefslogtreecommitdiffstats
path: root/tests/libsample
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-12-13 18:36:53 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2010-12-13 19:03:22 -0200
commit66bb59f9be9f7f38af48b1c4dc1108017c06ef72 (patch)
tree80fd1f69416ba3aa7891475791056f67dc62e1e6 /tests/libsample
parent701b31ef3ddae7c43380d1513f9938f70f46eb7e (diff)
downloadshiboken-66bb59f9be9f7f38af48b1c4dc1108017c06ef72.tar.gz
shiboken-66bb59f9be9f7f38af48b1c4dc1108017c06ef72.tar.xz
shiboken-66bb59f9be9f7f38af48b1c4dc1108017c06ef72.zip
Fix bug#513 - "Hardcoded bool return type for operator overloads"
Reviewer: Renato Ara├║jo <renato.filho@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests/libsample')
-rw-r--r--tests/libsample/CMakeLists.txt1
-rw-r--r--tests/libsample/expression.cpp127
-rw-r--r--tests/libsample/expression.h58
3 files changed, 186 insertions, 0 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
index 158c0e5e..3452c576 100644
--- a/tests/libsample/CMakeLists.txt
+++ b/tests/libsample/CMakeLists.txt
@@ -34,6 +34,7 @@ sometime.cpp
str.cpp
strlist.cpp
virtualmethods.cpp
+expression.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/tests/libsample/expression.cpp b/tests/libsample/expression.cpp
new file mode 100644
index 00000000..d93d47f0
--- /dev/null
+++ b/tests/libsample/expression.cpp
@@ -0,0 +1,127 @@
+/*
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * Contact: PySide team <contact@pyside.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include "expression.h"
+#include <sstream>
+
+Expression::Expression() : m_value(0), m_operation(None), m_operand1(0), m_operand2(0)
+{
+}
+
+Expression::Expression(int number) : m_value(number), m_operation(None), m_operand1(0), m_operand2(0)
+{
+}
+
+Expression::Expression(const Expression& other)
+{
+ m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : 0;
+ m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : 0;
+ m_value = other.m_value;
+ m_operation = other.m_operation;
+}
+
+Expression& Expression::operator=(const Expression& other)
+{
+ delete m_operand1;
+ delete m_operand2;
+ m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : 0;
+ m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : 0;
+ m_operation = other.m_operation;
+ m_value = other.m_value;
+ return *this;
+}
+
+Expression::~Expression()
+{
+ delete m_operand1;
+ delete m_operand2;
+}
+
+Expression Expression::operator+(const Expression& other)
+{
+ Expression expr;
+ expr.m_operation = Add;
+ expr.m_operand1 = new Expression(*this);
+ expr.m_operand2 = new Expression(other);
+ return expr;
+}
+
+Expression Expression::operator-(const Expression& other)
+{
+ Expression expr;
+ expr.m_operation = Add;
+ expr.m_operand1 = new Expression(*this);
+ expr.m_operand2 = new Expression(other);
+ return expr;
+}
+
+Expression Expression::operator<(const Expression& other)
+{
+ Expression expr;
+ expr.m_operation = LessThan;
+ expr.m_operand1 = new Expression(*this);
+ expr.m_operand2 = new Expression(other);
+ return expr;
+}
+
+Expression Expression::operator>(const Expression& other)
+{
+ Expression expr;
+ expr.m_operation = GreaterThan;
+ expr.m_operand1 = new Expression(*this);
+ expr.m_operand2 = new Expression(other);
+ return expr;
+}
+
+std::string Expression::toString() const
+{
+ if (m_operation == None) {
+ std::ostringstream s;
+ s << m_value;
+ return s.str();
+ }
+
+ std::string result;
+ result += '(';
+ result += m_operand1->toString();
+ char op;
+ switch (m_operation) {
+ case Add:
+ op = '+';
+ break;
+ case Sub:
+ op = '-';
+ break;
+ case LessThan:
+ op = '<';
+ break;
+ case GreaterThan:
+ op = '<';
+ break;
+ }
+ result += op;
+ result += m_operand2->toString();
+ result += ')';
+ return result;
+}
+
diff --git a/tests/libsample/expression.h b/tests/libsample/expression.h
new file mode 100644
index 00000000..608d5b5e
--- /dev/null
+++ b/tests/libsample/expression.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * Contact: PySide team <contact@pyside.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#ifndef EXPRESSION_H
+#define EXPRESSION_H
+
+#include "libsamplemacros.h"
+#include <string>
+
+class LIBSAMPLE_API Expression
+{
+public:
+ enum Operation {
+ None, Add, Sub, LessThan, GreaterThan
+ };
+
+ Expression(int number);
+ Expression(const Expression& other);
+ Expression& operator=(const Expression& other);
+
+ ~Expression();
+
+ Expression operator>(const Expression& other);
+ Expression operator<(const Expression& other);
+ Expression operator+(const Expression& other);
+ Expression operator-(const Expression& other);
+
+ std::string toString() const;
+private:
+ int m_value;
+ Operation m_operation;
+ Expression* m_operand1;
+ Expression* m_operand2;
+
+ Expression();
+};
+
+#endif // EXPRESSION_H