11 if (enum_type ==
"char")
13 else if (enum_type ==
"bool")
15 else if (strstr(
"long", enum_type.c_str()))
25 if (enum_type ==
"bool") {
32 if (enum_type ==
"char") {
33 char val = (char)llval;
35 }
else if (enum_type ==
"int" || enum_type ==
"unsigned int")
36 bval = PyInt_FromLong((
long)llval);
38 bval = PyLong_FromLongLong(llval);
41 PyTuple_SET_ITEM(args, 0, bval);
42 PyObject*
result = ((PyTypeObject*)btype)->tp_new((PyTypeObject*)pytype, args,
nullptr);
52 PyErr_SetString(PyExc_TypeError,
"enum values are read-only");
62 if (!kls_cppname) PyErr_Clear();
63 PyObject* obj_cppname = PyObject_GetAttr(self, PyStrings::gCppName);
64 if (!obj_cppname) PyErr_Clear();
68 if (kls_cppname && obj_cppname && obj_str) {
74 Py_XDECREF(obj_cppname);
75 Py_XDECREF(kls_cppname);
91 {
"char",
"c_char"}, {
"wchar_t",
"c_wchar"},
92 {
"std::byte",
"c_byte"}, {
"int8_t",
"c_byte"}, {
"uint8_t",
"c_ubyte"},
93 {
"short",
"c_short"}, {
"int16_t",
"c_int16"}, {
"unsigned short",
"c_ushort"}, {
"uint16_t",
"c_uint16"},
94 {
"int",
"c_int"}, {
"unsigned int",
"c_uint"},
95 {
"long",
"c_long"}, {
"unsigned long",
"c_ulong"},
96 {
"long long",
"c_longlong"}, {
"unsigned long long",
"c_ulonglong"}};
104 static PyObject* ctmod = PyImport_ImportModule(
"ctypes");
110 PyErr_Format(PyExc_TypeError,
"Can not find ctypes type for \"%s\"", cppname.c_str());
114 return (PyTypeObject*)PyObject_GetAttrString(ctmod, nn->second.c_str());
120 if (!pyres) PyErr_Clear();
127 return PyType_Type.tp_call((
PyObject*)ct, args, kwds);
146 PyObject* pymetabases = PyTuple_New(1);
149 PyTuple_SET_ITEM(pymetabases, 0, btype);
151 PyObject* args = Py_BuildValue((
char*)
"sO{}", (
name+
"_meta").c_str(), pymetabases);
152 Py_DECREF(pymetabases);
153 PyObject* pymeta = PyType_Type.tp_new(
Py_TYPE(pyside_type), args,
nullptr);
158 Py_INCREF(pyside_type);
159 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)pyside_type);
164 PyDict_SetItem(dct, PyStrings::gCppName, pycppname);
165 Py_DECREF(pycppname);
167 PyDict_SetItem(dct, PyStrings::gUnderlying, pyresolved);
168 Py_DECREF(pyresolved);
171 args = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
174 pyenum = ((PyTypeObject*)pymeta)->tp_new((PyTypeObject*)pymeta, args,
nullptr);
179 ((PyTypeObject*)pyenum)->tp_repr =
enum_repr;
180 ((PyTypeObject*)pyenum)->tp_str = ((PyTypeObject*)pyside_type)->tp_repr;
187 PyObject_SetAttr(pyenum, pydname, val);
188 PyObject_SetAttr(val, PyStrings::gCppName, pydname);
202 Py_INCREF(&PyInt_Type);
static PyObject * enum_repr(PyObject *self)
static std::map< std::string, std::string > gCTypesNames
static PyObject * pytype_from_enum_type(const std::string &enum_type)
static PyObject * enum_ctype(PyObject *cls, PyObject *args, PyObject *kwds)
static PyObject * pyval_from_enum(const std::string &enum_type, PyObject *pytype, PyObject *btype, Cppyy::TCppEnum_t etype, Cppyy::TCppIndex_t idata)
static PyTypeObject * GetCTypesType(const std::string &cppname)
static int enum_setattro(PyObject *, PyObject *, PyObject *)
#define CPyCppyy_PyText_FromStringAndSize
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_FromFormat
#define CPyCppyy_PyText_Type
#define CPyCppyy_PyText_FromString
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
CPPEnum * CPPEnum_New(const std::string &name, Cppyy::TCppScope_t scope)
RPY_EXPORTED TCppScope_t gGlobalScope
RPY_EXPORTED std::string ResolveEnum(const std::string &enum_type)
RPY_EXPORTED long long GetEnumDataValue(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED std::string GetEnumDataName(TCppEnum_t, TCppIndex_t idata)
RPY_EXPORTED TCppIndex_t GetNumEnumData(TCppEnum_t)
RPY_EXPORTED TCppEnum_t GetEnum(TCppScope_t scope, const std::string &enum_name)