Debian Codegraph @

src/Base/BaseClassPyImp.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2007 Jürgen Riegel <[email protected]> *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Library General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Library General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Library General Public *
19 * License along with this library; see the file COPYING.LIB. If not, *
20 * write to the Free Software Foundation, Inc., 59 Temple Place, *
21 * Suite 330, Boston, MA 02111-1307, USA *
22 * *
23 ***************************************************************************/
24
25 #include "Type.h"
26
27 // generated out of BaseClass.pyi
28 #include "BaseClassPy.h"
29 #include "BaseClassPy.cpp"
30
31 using namespace Base;
32
33 // returns a string which represent the object e.g. when printed in python
34 std::string BaseClassPy::representation() const
35 {
36 return {"<binding object>"};
37 }
38
39 PyObject* BaseClassPy::isDerivedFrom(PyObject* args) const
40 {
41 char* name {};
42 if (!PyArg_ParseTuple(args, "s", &name)) {
43 return nullptr;
44 }
45
46 auto type = Type::fromName(name);
47 bool valid = (!type.isBad() && getBaseClassPtr()->isDerivedFrom(type));
48 return PyBool_FromLong(valid ? 1 : 0);
49 }
50
51 PyObject* BaseClassPy::getAllDerivedFrom(PyObject* args) const
52 {
53 if (!PyArg_ParseTuple(args, "")) {
54 return nullptr;
55 }
56
57 std::vector<Base::Type> ary;
58 Type::getAllDerivedFrom(getBaseClassPtr()->getTypeId(), ary);
59 Py::List res;
60 for (const auto& it : ary) {
61 res.append(Py::String(it.getName()));
62 }
63 return Py::new_reference_to(res);
64 }
65
66 Py::String BaseClassPy::getTypeId() const
67 {
68 return {std::string(getBaseClassPtr()->getTypeId().getName())};
69 }
70
71 Py::String BaseClassPy::getModule() const
72 {
73 std::string module(getBaseClassPtr()->getTypeId().getName());
74 std::string::size_type pos = module.find_first_of("::");
75
76 if (pos != std::string::npos) {
77 module = std::string(module, 0, pos);
78 }
79 else {
80 module.clear();
81 }
82
83 return {module};
84 }
85
86 PyObject* BaseClassPy::getCustomAttributes(const char* /*attr*/) const
87 {
88 return nullptr;
89 }
90
91 int BaseClassPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
92 {
93 return 0;
94 }