From 0987f941852f8198f8a9469971ffd3876c6e6591 Mon Sep 17 00:00:00 2001 From: marioalexis Date: Tue, 8 Aug 2023 19:18:10 -0300 Subject: [PATCH] App: Change indentation to 4 spaces in String*PyImp.cpp --- src/App/StringHasherPyImp.cpp | 75 ++++++++++++++++++++--------------- src/App/StringIDPyImp.cpp | 66 ++++++++++++++++-------------- 2 files changed, 80 insertions(+), 61 deletions(-) diff --git a/src/App/StringHasherPyImp.cpp b/src/App/StringHasherPyImp.cpp index 79b10a1bee..582effc79f 100644 --- a/src/App/StringHasherPyImp.cpp +++ b/src/App/StringHasherPyImp.cpp @@ -32,14 +32,14 @@ using namespace App; // returns a string which represent the object e.g. when printed in python std::string StringHasherPy::representation() const { - std::ostringstream str; - str << ""; - return str.str(); + std::ostringstream str; + str << ""; + return str.str(); } PyObject *StringHasherPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper { - return new StringHasherPy(new StringHasher); + return new StringHasherPy(new StringHasher); } // constructor method @@ -56,14 +56,15 @@ int StringHasherPy::PyInit(PyObject* args, PyObject* kwds) PyObject* StringHasherPy::isSame(PyObject *args) { - PyObject *other; - if (!PyArg_ParseTuple(args, "O!", &StringHasherPy::Type, &other)) { - return nullptr; - } - auto otherHasher = static_cast(other)->getStringHasherPtr(); - bool same = getStringHasherPtr() == otherHasher; + PyObject *other; + if (!PyArg_ParseTuple(args, "O!", &StringHasherPy::Type, &other)) { + return nullptr; + } - return PyBool_FromLong(same ? 1 : 0); + auto otherHasher = static_cast(other)->getStringHasherPtr(); + bool same = getStringHasherPtr() == otherHasher; + + return PyBool_FromLong(same ? 1 : 0); } PyObject* StringHasherPy::getID(PyObject *args) @@ -77,6 +78,7 @@ PyObject* StringHasherPy::getID(PyObject *args) if (!sid) { Py_Return; } + return sid.getPyObject(); } PY_CATCH; @@ -96,8 +98,8 @@ PyObject* StringHasherPy::getID(PyObject *args) QByteArray data; StringIDRef sid; if (PyObject_IsTrue(base64)) { - data = QByteArray::fromBase64(QByteArray::fromRawData(txt.c_str(),txt.size())); - sid = getStringHasherPtr()->getID(data,true); + data = QByteArray::fromBase64(QByteArray::fromRawData(txt.c_str(),txt.size())); + sid = getStringHasherPtr()->getID(data,true); } else { sid = getStringHasherPtr()->getID(txt.c_str(),txt.size()); @@ -113,43 +115,52 @@ PyObject* StringHasherPy::getID(PyObject *args) return nullptr; } -Py::Int StringHasherPy::getCount() const { - return Py::Int((long)getStringHasherPtr()->count()); +Py::Long StringHasherPy::getCount() const +{ + return Py::Long(PyLong_FromSize_t(getStringHasherPtr()->count()), true); } -Py::Int StringHasherPy::getSize() const { - return Py::Int((long)getStringHasherPtr()->size()); +Py::Long StringHasherPy::getSize() const +{ + return Py::Long(PyLong_FromSize_t(getStringHasherPtr()->size()), true); } -Py::Boolean StringHasherPy::getSaveAll() const { - return Py::Boolean(getStringHasherPtr()->getSaveAll()); +Py::Boolean StringHasherPy::getSaveAll() const +{ + return Py::Boolean(getStringHasherPtr()->getSaveAll()); } -void StringHasherPy::setSaveAll(Py::Boolean value) { - getStringHasherPtr()->setSaveAll(value); +void StringHasherPy::setSaveAll(Py::Boolean value) +{ + getStringHasherPtr()->setSaveAll(value); } -Py::Int StringHasherPy::getThreshold() const { - return Py::Int((long)getStringHasherPtr()->getThreshold()); +Py::Long StringHasherPy::getThreshold() const +{ + return Py::Long(getStringHasherPtr()->getThreshold()); } -void StringHasherPy::setThreshold(Py::Int value) { - getStringHasherPtr()->setThreshold(value); +void StringHasherPy::setThreshold(Py::Long value) +{ + getStringHasherPtr()->setThreshold(value); } -Py::Dict StringHasherPy::getTable() const { - Py::Dict dict; - for(auto &v : getStringHasherPtr()->getIDMap()) - dict.setItem(Py::Int(v.first),Py::String(v.second.dataToText())); - return dict; +Py::Dict StringHasherPy::getTable() const +{ + Py::Dict dict; + for (const auto &v : getStringHasherPtr()->getIDMap()) { + dict.setItem(Py::Long(v.first), Py::String(v.second.dataToText())); + } + + return dict; } PyObject *StringHasherPy::getCustomAttributes(const char* /*attr*/) const { - return nullptr; + return nullptr; } int StringHasherPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { - return 0; + return 0; } diff --git a/src/App/StringIDPyImp.cpp b/src/App/StringIDPyImp.cpp index 6448b40b11..10b6563185 100644 --- a/src/App/StringIDPyImp.cpp +++ b/src/App/StringIDPyImp.cpp @@ -32,61 +32,69 @@ using namespace App; // returns a string which represent the object e.g. when printed in python std::string StringIDPy::representation() const { - return getStringIDPtr()->toString(_index); + return getStringIDPtr()->toString(this->_index); } PyObject* StringIDPy::isSame(PyObject *args) { - PyObject *other = nullptr; - if (!PyArg_ParseTuple(args, "O!", &StringIDPy::Type, &other)) { - return nullptr; - } + PyObject *other = nullptr; + if (!PyArg_ParseTuple(args, "O!", &StringIDPy::Type, &other)) { + return nullptr; + } - auto *otherPy = static_cast(other); - bool same = (otherPy->getStringIDPtr() == this->getStringIDPtr()) - && (otherPy->_index == this->_index); + auto *otherPy = static_cast(other); + bool same = (otherPy->getStringIDPtr() == this->getStringIDPtr()) + && (otherPy->_index == this->_index); - return PyBool_FromLong(same ? 1 : 0); + return PyBool_FromLong(same ? 1 : 0); } -Py::Int StringIDPy::getValue() const { - return Py::Int(getStringIDPtr()->value()); +Py::Long StringIDPy::getValue() const +{ + return Py::Long(getStringIDPtr()->value()); } -Py::List StringIDPy::getRelated() const { - Py::List list; - for (const auto &id : getStringIDPtr()->relatedIDs()) { - list.append(Py::Long(id.value())); -} - return list; +Py::List StringIDPy::getRelated() const +{ + Py::List list; + for (const auto &id : getStringIDPtr()->relatedIDs()) { + list.append(Py::Long(id.value())); + } + + return list; } -Py::String StringIDPy::getData() const { - return {Py::String(getStringIDPtr()->dataToText(this->_index))}; +Py::String StringIDPy::getData() const +{ + return Py::String(getStringIDPtr()->dataToText(this->_index)); } -Py::Boolean StringIDPy::getIsBinary() const { - return {getStringIDPtr()->isBinary()}; +Py::Boolean StringIDPy::getIsBinary() const +{ + return Py::Boolean(getStringIDPtr()->isBinary()); } -Py::Boolean StringIDPy::getIsHashed() const { - return {getStringIDPtr()->isHashed()}; +Py::Boolean StringIDPy::getIsHashed() const +{ + return Py::Boolean(getStringIDPtr()->isHashed()); } -Py::Int StringIDPy::getIndex() const { - return Py::Int(this->_index); +Py::Long StringIDPy::getIndex() const +{ + return Py::Long(this->_index); } -void StringIDPy::setIndex(Py::Int index) { - this->_index = index; +void StringIDPy::setIndex(Py::Long index) +{ + this->_index = index; } PyObject *StringIDPy::getCustomAttributes(const char* /*attr*/) const { - return nullptr; + return nullptr; } int StringIDPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { - return 0; + return 0; }