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;
36 }
else if (enum_type ==
"int" || enum_type ==
"unsigned int")
37 bval = PyInt_FromLong((
long)llval);
39 bval = PyLong_FromLongLong(llval);
42 PyTuple_SET_ITEM(args, 0, bval);
43 PyObject*
result = ((PyTypeObject*)btype)->tp_new((PyTypeObject*)pytype, args,
nullptr);
53 PyErr_SetString(PyExc_TypeError,
"enum values are read-only");
63 if (!kls_cppname) PyErr_Clear();
64 PyObject* obj_cppname = PyObject_GetAttr(self, PyStrings::gCppName);
65 if (!obj_cppname) PyErr_Clear();
69 if (kls_cppname && obj_cppname && obj_str) {
75 Py_XDECREF(obj_cppname);
76 Py_XDECREF(kls_cppname);
92 {
"char",
"c_char"}, {
"wchar_t",
"c_wchar"},
93 {
"std::byte",
"c_byte"}, {
"int8_t",
"c_byte"}, {
"uint8_t",
"c_ubyte"},
94 {
"short",
"c_short"}, {
"int16_t",
"c_int16"}, {
"unsigned short",
"c_ushort"}, {
"uint16_t",
"c_uint16"},
95 {
"int",
"c_int"}, {
"unsigned int",
"c_uint"},
96 {
"long",
"c_long"}, {
"unsigned long",
"c_ulong"},
97 {
"long long",
"c_longlong"}, {
"unsigned long long",
"c_ulonglong"}};
105 static PyObject* ctmod = PyImport_ImportModule(
"ctypes");
111 PyErr_Format(PyExc_TypeError,
"Can not find ctypes type for \"%s\"", cppname.c_str());
115 return (PyTypeObject*)PyObject_GetAttrString(ctmod, nn->second.c_str());
121 if (!pyres) PyErr_Clear();
128 return PyType_Type.tp_call((
PyObject*)ct, args, kwds);
147 PyObject* pymetabases = PyTuple_New(1);
150 PyTuple_SET_ITEM(pymetabases, 0, btype);
152 PyObject* args = Py_BuildValue((
char*)
"sO{}", (
name+
"_meta").c_str(), pymetabases);
153 Py_DECREF(pymetabases);
154 PyObject* pymeta = PyType_Type.tp_new(
Py_TYPE(pyside_type), args,
nullptr);
159 Py_INCREF(pyside_type);
160 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)pyside_type);
165 PyDict_SetItem(dct, PyStrings::gCppName, pycppname);
166 Py_DECREF(pycppname);
168 PyDict_SetItem(dct, PyStrings::gUnderlying, pyresolved);
169 Py_DECREF(pyresolved);
172 std::string modname = TypeManip::extract_namespace(ename);
173 TypeManip::cppscope_to_pyscope(modname);
174 if (!modname.empty()) modname =
"."+modname;
176 PyDict_SetItem(dct, PyStrings::gModule, pymodname);
177 Py_DECREF(pymodname);
180 args = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
183 pyenum = ((PyTypeObject*)pymeta)->tp_new((PyTypeObject*)pymeta, args,
nullptr);
188 ((PyTypeObject*)pyenum)->tp_repr =
enum_repr;
189 ((PyTypeObject*)pyenum)->tp_str = ((PyTypeObject*)pyside_type)->tp_repr;
196 PyObject_SetAttr(pyenum, pydname, val);
197 PyObject_SetAttr(val, PyStrings::gCppName, pydname);
211 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)