1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// add some useful builtin functions for ResourceId
%feature("python:tp_str") ResourceId "resid_str";
%feature("python:tp_repr") ResourceId "resid_str";
%feature("python:nb_int") ResourceId "resid_int";
%feature("python:tp_hash") ResourceId "resid_hash";
%ignore ResourceId::operator <;
%extend ResourceId {
PyObject *__lt__(PyObject *other)
{
bool result = false;
void *resptr = NULL;
ResourceId *id = NULL;
if(other && other != Py_None)
{
int res = SWIG_ConvertPtr(other, &resptr, SWIGTYPE_p_ResourceId, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "incorrect comparison type");
}
id = (ResourceId *)resptr;
result = (*$self < *id);
}
return PyBool_FromLong(result ? 1 : 0);
fail:
return NULL;
}
} // %extend ResourceId
%wrapper %{
static PyObject *resid_str(PyObject *resid)
{
void *resptr = NULL;
unsigned long long *id = NULL;
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
}
// cast as unsigned long long
id = (unsigned long long *)resptr;
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
return PyUnicode_FromFormat("<ResourceId %llu>", *id);
fail:
return NULL;
}
static Py_hash_t resid_hash(PyObject *resid)
{
void *resptr = NULL;
unsigned long long *id = NULL;
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
}
// cast as unsigned long long
id = (unsigned long long *)resptr;
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
return Py_hash_t(*id);
fail:
return 0;
}
static PyObject *resid_int(PyObject *resid)
{
void *resptr = NULL;
unsigned long long *id = NULL;
int res = SWIG_ConvertPtr(resid, &resptr, SWIGTYPE_p_ResourceId, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method 'ResourceId.str', ResourceId is not correct type");
}
// cast as unsigned long long
id = (unsigned long long *)resptr;
static_assert(sizeof(unsigned long long) == sizeof(ResourceId), "Wrong size");
return PyLong_FromUnsignedLongLong(*id);
fail:
return NULL;
}
%}
// macro to define safe == and != operators for classes, that don't throw an exception comparing to
// None
%define DEFINE_SAFE_EQUALITY(Class)
%ignore Class::operator ==;
%ignore Class::operator !=;
%extend Class {
PyObject *__eq__(PyObject *other)
{
bool result = false;
void *resptr = NULL;
Class *id = NULL;
if(other && other != Py_None)
{
int res = SWIG_ConvertPtr(other, &resptr, SWIGTYPE_p_##Class, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "incorrect comparison type");
}
id = (Class *)resptr;
result = (*$self == *id);
}
return PyBool_FromLong(result ? 1 : 0);
fail:
return NULL;
}
PyObject *__ne__(PyObject *other)
{
bool result = true;
void *resptr = NULL;
Class *id = NULL;
if(other && other != Py_None)
{
int res = SWIG_ConvertPtr(other, &resptr, SWIGTYPE_p_##Class, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "incorrect comparison type");
}
id = (Class *)resptr;
result = !(*$self == *id);
}
return PyBool_FromLong(result ? 1 : 0);
fail:
return NULL;
}
} // %extend Class
%enddef // %define DEFINE_SAFE_COMPARISONS
DEFINE_SAFE_EQUALITY(DrawcallDescription)
DEFINE_SAFE_EQUALITY(CounterResult)
DEFINE_SAFE_EQUALITY(APIEvent)
DEFINE_SAFE_EQUALITY(Bindpoint)
DEFINE_SAFE_EQUALITY(BufferDescription)
DEFINE_SAFE_EQUALITY(CaptureFileFormat)
DEFINE_SAFE_EQUALITY(ConstantBlock)
DEFINE_SAFE_EQUALITY(DebugMessage)
DEFINE_SAFE_EQUALITY(EnvironmentModification)
DEFINE_SAFE_EQUALITY(EventUsage)
DEFINE_SAFE_EQUALITY(PathEntry)
DEFINE_SAFE_EQUALITY(PixelModification)
DEFINE_SAFE_EQUALITY(ResourceDescription)
DEFINE_SAFE_EQUALITY(ResourceId)
DEFINE_SAFE_EQUALITY(LineColumnInfo)
DEFINE_SAFE_EQUALITY(ShaderCompileFlag)
DEFINE_SAFE_EQUALITY(ShaderConstant)
DEFINE_SAFE_EQUALITY(ShaderDebugState)
DEFINE_SAFE_EQUALITY(ShaderResource)
DEFINE_SAFE_EQUALITY(ShaderSampler)
DEFINE_SAFE_EQUALITY(ShaderSourceFile)
DEFINE_SAFE_EQUALITY(ShaderVariable)
DEFINE_SAFE_EQUALITY(RegisterRange)
DEFINE_SAFE_EQUALITY(LocalVariableMapping)
DEFINE_SAFE_EQUALITY(SigParameter)
DEFINE_SAFE_EQUALITY(TextureDescription)
DEFINE_SAFE_EQUALITY(ShaderEntryPoint)
DEFINE_SAFE_EQUALITY(Viewport)
DEFINE_SAFE_EQUALITY(Scissor)
DEFINE_SAFE_EQUALITY(ColorBlend)
DEFINE_SAFE_EQUALITY(BoundVBuffer)
DEFINE_SAFE_EQUALITY(VertexInputAttribute)
DEFINE_SAFE_EQUALITY(BoundResource)
DEFINE_SAFE_EQUALITY(BoundResourceArray)
|