12 if (enum_type ==
"char")
14 else if (enum_type ==
"bool")
16 else if (strstr(
"long", enum_type.c_str()))
26 if (enum_type ==
"bool") {
33 if (enum_type ==
"char") {
34 char val = (char)llval;
35#if PY_VERSION_HEX < 0x03000000
38 bval = PyUnicode_FromOrdinal((
int)val);
40 }
else if (enum_type ==
"int" || enum_type ==
"unsigned int")
41 bval = PyInt_FromLong((
long)llval);
43 bval = PyLong_FromLongLong(llval);
49 PyTuple_SET_ITEM(args, 0, bval);
50 PyObject*
result = ((PyTypeObject*)btype)->tp_new((PyTypeObject*)pytype, args,
nullptr);
60 PyErr_SetString(PyExc_TypeError,
"enum values are read-only");
70 if (!kls_cppname) PyErr_Clear();
71 PyObject* obj_cppname = PyObject_GetAttr(self, PyStrings::gCppName);
72 if (!obj_cppname) PyErr_Clear();
76 if (kls_cppname && obj_cppname && obj_str) {
82 Py_XDECREF(obj_cppname);
83 Py_XDECREF(kls_cppname);
99 {
"char",
"c_char"}, {
"wchar_t",
"c_wchar"},
100 {
"std::byte",
"c_byte"}, {
"int8_t",
"c_byte"}, {
"uint8_t",
"c_ubyte"},
101 {
"short",
"c_short"}, {
"int16_t",
"c_int16"}, {
"unsigned short",
"c_ushort"}, {
"uint16_t",
"c_uint16"},
102 {
"int",
"c_int"}, {
"unsigned int",
"c_uint"},
103 {
"long",
"c_long"}, {
"unsigned long",
"c_ulong"},
104 {
"long long",
"c_longlong"}, {
"unsigned long long",
"c_ulonglong"}};
112 static PyObject* ctmod = PyImport_ImportModule(
"ctypes");
118 PyErr_Format(PyExc_TypeError,
"Can not find ctypes type for \"%s\"", cppname.c_str());
122 return (PyTypeObject*)PyObject_GetAttrString(ctmod, nn->second.c_str());
128 if (!pyres) PyErr_Clear();
135 return PyType_Type.tp_call((
PyObject*)ct, args, kwds);
154 PyObject* pymetabases = PyTuple_New(1);
157 PyTuple_SET_ITEM(pymetabases, 0, btype);
159 PyObject* args = Py_BuildValue((
char*)
"sO{}", (
name+
"_meta").c_str(), pymetabases);
160 Py_DECREF(pymetabases);
161 PyObject* pymeta = PyType_Type.tp_new(
Py_TYPE(pyside_type), args,
nullptr);
166 Py_INCREF(pyside_type);
167 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)pyside_type);
172 PyDict_SetItem(dct, PyStrings::gCppName, pycppname);
173 Py_DECREF(pycppname);
175 PyDict_SetItem(dct, PyStrings::gUnderlying, pyresolved);
176 Py_DECREF(pyresolved);
179 std::string modname = TypeManip::extract_namespace(ename);
180 TypeManip::cppscope_to_pyscope(modname);
181 if (!modname.empty()) modname =
"."+modname;
183 PyDict_SetItem(dct, PyStrings::gModule, pymodname);
184 Py_DECREF(pymodname);
187 args = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
190 pyenum = ((PyTypeObject*)pymeta)->tp_new((PyTypeObject*)pymeta, args,
nullptr);
195 ((PyTypeObject*)pyenum)->tp_repr =
enum_repr;
196 ((PyTypeObject*)pyenum)->tp_str = ((PyTypeObject*)pyside_type)->tp_repr;
200 bool values_ok =
true;
208 PyObject_SetAttr(pyenum, pydname, val);
209 PyObject_SetAttr(val, PyStrings::gCppName, pydname);
222 if (!PyErr_Occurred())
223 PyErr_SetString(PyExc_ValueError,
"could not set some of the enum values");
230 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)