Debian Codegraph @

src/App/StringIDPyImp.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2018 Zheng Lei (realthunder) <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ****************************************************************************/
22
23
24 #include "StringHasher.h"
25
26 #include "StringIDPy.h"
27 #include "StringIDPy.cpp"
28
29 using namespace App;
30
31 // returns a string which represent the object e.g. when printed in python
32 std::string StringIDPy::representation() const
33 {
34 return getStringIDPtr()->toString(this->_index);
35 }
36
37 PyObject* StringIDPy::isSame(PyObject* args) const
38 {
39 PyObject* other = nullptr;
40 if (!PyArg_ParseTuple(args, "O!", &StringIDPy::Type, &other)) {
41 return nullptr;
42 }
43
44 auto* otherPy = static_cast<StringIDPy*>(other);
45 bool same =
46 (otherPy->getStringIDPtr() == this->getStringIDPtr()) && (otherPy->_index == this->_index);
47
48 return PyBool_FromLong(same ? 1 : 0);
49 }
50
51 Py::Long StringIDPy::getValue() const
52 {
53 return Py::Long(getStringIDPtr()->value());
54 }
55
56 Py::List StringIDPy::getRelated() const
57 {
58 Py::List list;
59 for (const auto& id : getStringIDPtr()->relatedIDs()) {
60 list.append(Py::Long(id.value()));
61 }
62
63 return list;
64 }
65
66 Py::String StringIDPy::getData() const
67 {
68 return {getStringIDPtr()->dataToText(this->_index)};
69 }
70
71 Py::Boolean StringIDPy::getIsBinary() const
72 {
73 return {getStringIDPtr()->isBinary()};
74 }
75
76 Py::Boolean StringIDPy::getIsHashed() const
77 {
78 return {getStringIDPtr()->isHashed()};
79 }
80
81 Py::Long StringIDPy::getIndex() const
82 {
83 return Py::Long(this->_index);
84 }
85
86 void StringIDPy::setIndex(Py::Long index)
87 {
88 this->_index = index;
89 }
90
91 PyObject* StringIDPy::getCustomAttributes(const char* /*attr*/) const
92 {
93 return nullptr;
94 }
95
96 int StringIDPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
97 {
98 return 0;
99 }