20#include <structmember.h>
41 for (
auto it = cache.begin(); it != cache.end(); ++it) {
44 Py_INCREF(it->second);
57 dm->
fFlags &= ~kIsEnumPrep;
67 PyObject* pyEnumType = PyObject_GetAttrString(
70 PyObject* pyval = PyObject_GetAttrString(
72 Py_DECREF(pyEnumType);
94 nullptr,
nullptr, dm->
fScope);
106 if (!address || (intptr_t)address == -1 )
140 PyErr_Format(PyExc_NotImplementedError,
"no converter available for \"%s\"",
148 const int errret = -1;
154 PyErr_SetString(PyExc_TypeError,
"data member deletion is not supported");
167 PyErr_SetString(PyExc_TypeError,
"assignment to const data not allowed");
174 for (
auto it = cache.begin(); it != cache.end(); ++it) {
175 if (it->first == dm->
fOffset) {
176 Py_XDECREF(it->second);
183 intptr_t address = (intptr_t)dm->
GetAddress(pyobj);
184 if (!address || address == -1 )
188 void* ptr = (
void*)address;
197 if (!PyErr_Occurred())
198 PyErr_SetString(PyExc_RuntimeError,
199 "property type mismatch or assignment not allowed");
229 Py_XDECREF(dm->
fDoc);
233 Py_TYPE(dm)->tp_free((
PyObject*)dm);
237 {(
char*)
"__doc__", T_OBJECT, offsetof(
CPPDataMember, fDoc), 0,
238 (
char*)
"writable documentation"},
239 {NULL, 0, 0, 0,
nullptr}
247 if (!PyArg_ParseTuple(args,
const_cast<char*
>(
"i|i:__cpp_reflex__"), &request,
254 return PyUnicode_FromString(dm->
fFullType.c_str());
257 return PyLong_FromLong(dm->
fOffset);
260 PyErr_Format(PyExc_ValueError,
"unsupported reflex request %d or format %d",
267 {(
char*)
"__cpp_reflex__", (PyCFunction)
dm_reflex, METH_VARARGS,
268 (
char*)
"C++ datamember reflection information"},
269 {(
char*)
nullptr,
nullptr, 0,
nullptr}};
273 PyVarObject_HEAD_INIT(&PyType_Type,
274 0)(
char*)
"cppjit.CPPDataMember",
293 (
char*)
"cppjit data member (internal)",
340 "__cppjit_internal_wrap_g"));
350 if (
fFullType.find(
"(anonymous)") == std::string::npos &&
351 fFullType.find(
"(unnamed)") == std::string::npos) {
371 std::vector<dim_t> dims(ldims.begin(), ldims.end());
387 const std::string&
name,
void* address) {
388 fEnclosingScope = scope;
389 fDescription = PyUnicode_FromString(
name.c_str());
390 fOffset = (intptr_t)address;
393 fFullType =
"unsigned int";
400 return (
void*)fOffset;
404 PyErr_SetString(PyExc_AttributeError,
405 "attribute access requires an instance");
411 PyErr_Format(PyExc_TypeError,
412 "object instance required for access to property \"%s\"",
417 void* obj = pyobj->GetObject();
419 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
426 if (oisa != fEnclosingScope)
430 return (
void*)((intptr_t)obj +
offset + fOffset);
436 PyObject* repr = PyObject_Repr(fDescription);
438 std::string res = PyUnicode_AsUTF8(repr);
445 std::string fullName = PyUnicode_AsUTF8(fDescription);
446 return fullName.substr(fullName.rfind(
"::") + 2, std::string::npos);
449 return PyUnicode_AsUTF8(fDescription);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
PyObject_HEAD intptr_t fOffset
void Set(interop::TCppScope_t scope, interop::TCppScope_t var)
interop::TCppScope_t fEnclosingScope
void * GetAddress(CPPInstance *pyobj)
interop::TCppScope_t fScope
CI_DatamemberCache_t & GetDatamemberCache()
virtual PyObject * FromMemory(void *address)
virtual bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr)
#define CPYRT_PYTYPE_TAIL
static CPPDataMember * dm_new(PyTypeObject *pytype, PyObject *, PyObject *)
CPYRT_EXTERN Converter * CreateConverter(const std::string &name, cdims_t=0)
PyTypeObject CPPDataMember_Type
static PyObject * dm_reflex(CPPDataMember *dm, PyObject *args)
bool LowLevelView_CheckExact(T *object)
PyObject * pyval_from_enum(const std::string &enum_type, PyObject *pytype, PyObject *btype, interop::TCppScope_t enum_constant)
static PyObject * dm_get(CPPDataMember *dm, CPPInstance *pyobj, PyObject *)
PyObject * CreateScopeProxy(PyObject *, PyObject *args)
std::vector< std::pair< ptrdiff_t, PyObject * > > CI_DatamemberCache_t
static int dm_set(CPPDataMember *dm, CPPInstance *pyobj, PyObject *value)
bool CPPInstance_Check(T *object)
static PyMemberDef dm_members[]
static void dm_dealloc(CPPDataMember *dm)
static PyMethodDef dm_methods[]
const FormatId_t AS_STRING
bool IsConstVar(TCppScope_t var)
std::string GetTypeAsString(TCppType_t type)
TCppType_t GetDatamemberType(TCppScope_t data)
TCppScope_t WrapLambdaFromVariable(TCppScope_t var)
TCppScope_t GetParentScope(TCppScope_t scope)
bool IsStaticDatamember(TCppScope_t var)
intptr_t GetDatamemberOffset(TCppScope_t var, TCppScope_t klass=nullptr)
TCppType_t ResolveType(TCppType_t cppitem_name)
std::string ResolveEnum(TCppScope_t enum_scope)
bool IsNamespace(TCppScope_t scope)
TCppScope_t GetScope(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
TCppType_t GetEnumConstantType(TCppScope_t scope)
bool IsEnumConstant(TCppScope_t scope)
std::string GetFinalName(TCppScope_t type)
bool IsLambdaClass(TCppType_t type)
ptrdiff_t GetBaseOffset(TCppScope_t derived, TCppScope_t base, TCppObject_t address, int direction, bool rerror=false)
std::vector< long int > GetDimensions(TCppType_t type)
bool IsEnumType(TCppType_t type)