8 #define _IS_FINAL(T) (__is_sealed(T)) 9 #elif defined(__GNUC__) 10 #define _IS_FINAL(T) (__is_final(T)) 12 #define _IS_FINAL(T) (0) 19 template<
class T> INLINE
bool 21 if (DtoolInstance_Check(
self)) {
22 Dtool_PyTypedObject *target_class = (Dtool_PyTypedObject *)get_type_handle(T).get_python_type();
23 if (target_class !=
nullptr) {
25 if (DtoolInstance_TYPE(
self) == target_class) {
26 into = (T *)DtoolInstance_VOID_PTR(
self);
31 into = (T *)DtoolInstance_UPCAST(
self, *target_class);
33 return (into !=
nullptr);
44 template<
class T> INLINE
bool 46 if (DtoolInstance_Check(
self)) {
48 if (DtoolInstance_TYPE(
self) == &target_class) {
49 into = (T *)DtoolInstance_VOID_PTR(
self);
54 into = (T *)DtoolInstance_UPCAST(
self, target_class);
56 return (into !=
nullptr);
66 if (
self !=
nullptr && DtoolInstance_Check(
self)) {
67 return (Py_hash_t)(intptr_t)DtoolInstance_VOID_PTR(
self);
76 void *v1_this = DtoolInstance_Check(v1) ? DtoolInstance_VOID_PTR(v1) :
nullptr;
77 void *v2_this = DtoolInstance_Check(v2) ? DtoolInstance_VOID_PTR(v2) :
nullptr;
78 if (v1_this !=
nullptr && v2_this !=
nullptr) {
79 return (v1_this > v2_this) - (v1_this < v2_this);
81 return (v1 > v2) - (v1 < v2);
90 Py_RETURN_RICHCOMPARE(cmpval, 0, op);
97 PyObject *val = PyObject_GetAttrString(value,
"value");
99 long as_long = PyLongOrInt_AS_LONG(val);
110 template<
class T> INLINE PyObject *
112 Dtool_PyTypedObject *known_class = (Dtool_PyTypedObject *)get_type_handle(T).get_python_type();
113 nassertr(known_class !=
nullptr,
nullptr);
117 template<
class T> INLINE PyObject *
119 Dtool_PyTypedObject *known_class = (Dtool_PyTypedObject *)get_type_handle(T).get_python_type();
120 nassertr(known_class !=
nullptr,
nullptr);
124 template<
class T> INLINE PyObject *
125 DTool_CreatePyInstanceTyped(
const T *obj,
bool memory_rules) {
126 Dtool_PyTypedObject *known_class = (Dtool_PyTypedObject *)get_type_handle(T).get_python_type();
127 nassertr(known_class !=
nullptr,
nullptr);
128 return DTool_CreatePyInstanceTyped((
void*) obj, *known_class, memory_rules,
true, obj->get_type().get_index());
131 template<
class T> INLINE PyObject *
132 DTool_CreatePyInstanceTyped(T *obj,
bool memory_rules) {
133 Dtool_PyTypedObject *known_class = (Dtool_PyTypedObject *)get_type_handle(T).get_python_type();
134 nassertr(known_class !=
nullptr,
nullptr);
135 return DTool_CreatePyInstanceTyped((
void*) obj, *known_class, memory_rules,
false, obj->get_type().get_index());
142 DTool_PyInit_Finalize(PyObject *
self,
void *local_this, Dtool_PyTypedObject *type,
bool memory_rules,
bool is_const) {
143 ((Dtool_PyInstDef *)
self)->_My_Type = type;
144 ((Dtool_PyInstDef *)
self)->_ptr_to_object = local_this;
145 ((Dtool_PyInstDef *)
self)->_memory_rules = memory_rules;
146 ((Dtool_PyInstDef *)
self)->_is_const = is_const;
155 return PyTuple_GET_SIZE(args) == 0;
163 return PyTuple_GET_SIZE(args) == 0 &&
164 (kwds ==
nullptr || PyDict_GET_SIZE(kwds) == 0);
171 #if PY_MAJOR_VERSION >= 3 172 return PyLong_FromLong((
long)value);
174 return PyInt_FromLong((
long)value);
179 #if PY_MAJOR_VERSION >= 3 && SIZEOF_INT < SIZEOF_LONG 180 return PyLong_FromLong((
long)value);
181 #elif PY_MAJOR_VERSION >= 3 182 return PyLong_FromUnsignedLong((
unsigned long)value);
183 #elif SIZEOF_INT < SIZEOF_LONG 184 return PyInt_FromLong((
long)value);
186 return (value > LONG_MAX)
187 ? PyLong_FromUnsignedLong((
unsigned long)value)
188 : PyInt_FromLong((long)value);
193 #if PY_MAJOR_VERSION >= 3 194 return PyLong_FromLong(value);
196 return PyInt_FromLong(value);
201 #if PY_MAJOR_VERSION >= 3 202 return PyLong_FromUnsignedLong(value);
204 return (value > LONG_MAX)
205 ? PyLong_FromUnsignedLong(value)
206 : PyInt_FromLong((long)value);
211 return PyLong_FromLongLong(value);
217 #if PY_MAJOR_VERSION >= 3 218 return PyLong_FromUnsignedLongLong(value);
220 return (value > LONG_MAX)
221 ? PyLong_FromUnsignedLongLong(value)
222 : PyInt_FromLong((long)value);
227 PyObject *result = (value ? Py_True : Py_False);
233 return PyFloat_FromDouble(value);
237 if (value ==
nullptr) {
241 #if PY_MAJOR_VERSION >= 3 242 return PyUnicode_FromString(value);
244 return PyString_FromString(value);
250 if (value ==
nullptr) {
254 return PyUnicode_FromWideChar(value, (Py_ssize_t)wcslen(value));
259 #if PY_MAJOR_VERSION >= 3 260 return PyUnicode_FromStringAndSize(value.data(), (Py_ssize_t)value.length());
262 return PyString_FromStringAndSize(value.data(), (Py_ssize_t)value.length());
267 return PyUnicode_FromWideChar(value.data(), (Py_ssize_t)value.length());
271 if (value ==
nullptr) {
275 #if PY_MAJOR_VERSION >= 3 276 return PyUnicode_FromStringAndSize(value->data(), (Py_ssize_t)value->length());
278 return PyString_FromStringAndSize(value->data(), (Py_ssize_t)value->length());
284 if (value ==
nullptr) {
288 return PyUnicode_FromWideChar(value->data(), (Py_ssize_t)value->length());
293 #if PY_MAJOR_VERSION >= 3 294 return PyUnicode_FromStringAndSize(&value, 1);
296 return PyString_FromStringAndSize(&value, 1);
301 return PyUnicode_FromWideChar(&value, 1);
314 #if PY_MAJOR_VERSION >= 3 315 return PyBytes_FromStringAndSize((
char *)value.data(), (Py_ssize_t)value.size());
317 return PyString_FromStringAndSize((
char *)value.data(), (Py_ssize_t)value.size());
321 #if PY_MAJOR_VERSION >= 0x02060000 323 if (value ==
nullptr) {
326 return PyMemoryView_FromBuffer(value);
331 template<
class T1,
class T2>
332 ALWAYS_INLINE PyObject *
Dtool_WrapValue(
const std::pair<T1, T2> &value) {
333 PyObject *tuple = PyTuple_New(2);
Py_hash_t DtoolInstance_HashPointer(PyObject *self)
Function to create a hash from a wrapped Python object.
bool Dtool_CheckNoArgs(PyObject *args)
Checks that the tuple is empty.
long Dtool_EnumValue_AsLong(PyObject *value)
Converts the enum value to a C long.
PyObject * DtoolInstance_RichComparePointers(PyObject *v1, PyObject *v2, int op)
Rich comparison function that compares objects by pointer.
PyObject * Dtool_WrapValue(int value)
The following functions wrap an arbitrary C++ value into a PyObject.
PyObject * DTool_CreatePyInstance(const T *obj, bool memory_rules)
These functions wrap a pointer for a class that defines get_type_handle().
int DtoolInstance_ComparePointers(PyObject *v1, PyObject *v2)
Python 2-style comparison function that compares objects by pointer.
int DTool_PyInit_Finalize(PyObject *self, void *local_this, Dtool_PyTypedObject *type, bool memory_rules, bool is_const)
Finishes initializing the Dtool_PyInstDef.
bool DtoolInstance_GetPointer(PyObject *self, T *&into)
Template function that can be used to extract any TypedObject pointer from a wrapped Python object.