@@ -71,11 +71,44 @@ CONTAINER_TYPEMAPS(rdctype::array)
71
71
72
72
// add __str__ functions
73
73
%feature(" python:tp_str" ) ResourceId " resid_str" ;
74
+ %feature(" python:tp_repr" ) ResourceId " resid_str" ;
75
+ %feature(" python:nb_int" ) ResourceId " resid_int" ;
74
76
75
77
%wrapper %{
76
78
static PyObject *resid_str (PyObject *resid)
77
79
{
78
- return PyUnicode_FromFormat (" <ResourceId %S>" , PyObject_GetAttrString (resid, " id" ));
80
+ void *resptr = NULL ;
81
+ unsigned long long *id = NULL ;
82
+ int res = SWIG_ConvertPtr (resid, &resptr, SWIGTYPE_p_ResourceId, 0 );
83
+ if (!SWIG_IsOK (res)) {
84
+ SWIG_exception_fail (SWIG_ArgError (res), " in method 'ResourceId.str', ResourceId is not correct type" );
85
+ }
86
+
87
+ // cast as unsigned long long
88
+ id = (unsigned long long *)resptr;
89
+ static_assert (sizeof (unsigned long long ) == sizeof (ResourceId), " Wrong size" );
90
+
91
+ return PyUnicode_FromFormat (" <ResourceId %llu>" , *id);
92
+ fail:
93
+ return NULL ;
94
+ }
95
+
96
+ static PyObject *resid_int (PyObject *resid)
97
+ {
98
+ void *resptr = NULL ;
99
+ unsigned long long *id = NULL ;
100
+ int res = SWIG_ConvertPtr (resid, &resptr, SWIGTYPE_p_ResourceId, 0 );
101
+ if (!SWIG_IsOK (res)) {
102
+ SWIG_exception_fail (SWIG_ArgError (res), " in method 'ResourceId.str', ResourceId is not correct type" );
103
+ }
104
+
105
+ // cast as unsigned long long
106
+ id = (unsigned long long *)resptr;
107
+ static_assert (sizeof (unsigned long long ) == sizeof (ResourceId), " Wrong size" );
108
+
109
+ return PyLong_FromUnsignedLongLong (*id);
110
+ fail:
111
+ return NULL ;
79
112
}
80
113
%}
81
114
0 commit comments