Debian Codegraph @

src/Base/BaseClass.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2011 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 <cassert>
26
27 #include "BaseClass.h"
28 #include "PyObjectBase.h"
29
30 using namespace Base;
31
32 Type BaseClass::classTypeId = Base::Type::BadType;
33
34
35 //**************************************************************************
36 // Construction/Destruction
37
38 /**
39 * A constructor.
40 * A more elaborate description of the constructor.
41 */
42 BaseClass::BaseClass() = default;
43
44 /**
45 * A destructor.
46 * A more elaborate description of the destructor.
47 */
48 BaseClass::~BaseClass() = default;
49
50
51 //**************************************************************************
52 // separator for other implementation aspects
53
54 void BaseClass::init()
55 {
56 assert(BaseClass::classTypeId.isBad() && "don't init() twice!");
57 /* Make sure superclass gets initialized before subclass. */
58 /*assert(strcmp(#_parentclass_), "inherited"));*/
59 /*Type parentType(Type::fromName(#_parentclass_));*/
60 /*assert(!parentType.isBad() && "you forgot init() on parentclass!");*/
61
62 /* Set up entry in the type system. */
63 BaseClass::classTypeId = Type::createType(Type::BadType, "Base::BaseClass", BaseClass::create);
64 }
65
66 Type BaseClass::getClassTypeId()
67 {
68 return BaseClass::classTypeId;
69 }
70
71 Type BaseClass::getTypeId() const
72 {
73 return BaseClass::classTypeId;
74 }
75
76
77 void BaseClass::initSubclass(
78 Base::Type& toInit,
79 const char* ClassName,
80 const char* ParentName,
81 Type::instantiationMethod method
82 )
83 {
84 // don't init twice!
85 assert(toInit.isBad());
86 // get the parent class
87 Base::Type parentType(Base::Type::fromName(ParentName));
88 // forgot init parent!
89 assert(!parentType.isBad());
90
91 // create the new type
92 toInit = Base::Type::createType(parentType, ClassName, method);
93 }
94
95 /**
96 * This method returns the Python wrapper for a C++ object. It's in the responsibility of
97 * the programmer to do the correct reference counting. Basically there are two ways how
98 * to implement that: Either always return a new Python object then reference counting is
99 * not a matter or return always the same Python object then the reference counter must be
100 * incremented by one. However, it's absolutely forbidden to return always the same Python
101 * object without incrementing the reference counter.
102 *
103 * The default implementation returns 'None'.
104 */
105 PyObject* BaseClass::getPyObject()
106 {
107 Py_Return;
108 }
109
110 void BaseClass::setPyObject(PyObject* /*unused*/)
111 {}