App: Apply clang format (part 1)
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2018 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
****************************************************************************/
|
||||
* Copyright (c) 2018 Zheng Lei (realthunder) <realthunder.dev@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
@@ -38,7 +38,7 @@ std::string StringHasherPy::representation() const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
PyObject *StringHasherPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
PyObject* StringHasherPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
return new StringHasherPy(new StringHasher);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ PyObject *StringHasherPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
|
||||
// constructor method
|
||||
int StringHasherPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
static const std::array<const char *, 1> kwlist {nullptr};
|
||||
static const std::array<const char*, 1> kwlist {nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "", kwlist)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -55,9 +55,9 @@ int StringHasherPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
}
|
||||
|
||||
|
||||
PyObject* StringHasherPy::isSame(PyObject *args)
|
||||
PyObject* StringHasherPy::isSame(PyObject* args)
|
||||
{
|
||||
PyObject *other;
|
||||
PyObject* other;
|
||||
if (!PyArg_ParseTuple(args, "O!", &StringHasherPy::Type, &other)) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -65,16 +65,17 @@ PyObject* StringHasherPy::isSame(PyObject *args)
|
||||
auto otherHasher = static_cast<StringHasherPy*>(other)->getStringHasherPtr();
|
||||
bool same = getStringHasherPtr() == otherHasher;
|
||||
|
||||
return PyBool_FromLong(same ? 1 : 0);
|
||||
return PyBool_FromLong(same ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* StringHasherPy::getID(PyObject *args)
|
||||
PyObject* StringHasherPy::getID(PyObject* args)
|
||||
{
|
||||
long id;
|
||||
int index = 0;
|
||||
if (PyArg_ParseTuple(args, "l|i", &id, &index)) {
|
||||
if (id > 0) {
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
auto sid = getStringHasherPtr()->getID(id, index);
|
||||
if (!sid) {
|
||||
Py_Return;
|
||||
@@ -91,19 +92,20 @@ PyObject* StringHasherPy::getID(PyObject *args)
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
PyObject *value = nullptr;
|
||||
PyObject *base64 = Py_False;
|
||||
PyObject* value = nullptr;
|
||||
PyObject* base64 = Py_False;
|
||||
if (PyArg_ParseTuple(args, "O!|O!", &PyUnicode_Type, &value, &PyBool_Type, &base64)) {
|
||||
PY_TRY {
|
||||
PY_TRY
|
||||
{
|
||||
std::string txt = PyUnicode_AsUTF8(value);
|
||||
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());
|
||||
sid = getStringHasherPtr()->getID(txt.c_str(), txt.size());
|
||||
}
|
||||
|
||||
return sid.getPyObject();
|
||||
@@ -111,8 +113,9 @@ PyObject* StringHasherPy::getID(PyObject *args)
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Positive integer and optional integer or "
|
||||
"string and optional boolean is required");
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Positive integer and optional integer or "
|
||||
"string and optional boolean is required");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -149,14 +152,14 @@ void StringHasherPy::setThreshold(Py::Long value)
|
||||
Py::Dict StringHasherPy::getTable() const
|
||||
{
|
||||
Py::Dict dict;
|
||||
for (const auto &v : getStringHasherPtr()->getIDMap()) {
|
||||
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
|
||||
PyObject* StringHasherPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user