Adding tgl.Peer comparisons, only eq/ne
This commit is contained in:
parent
13c22f3b06
commit
c2bb5346df
@ -969,6 +969,38 @@ tgl_Peer_repr(tgl_Peer *self)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
tgl_Peer_RichCompare(PyObject *self, PyObject *other, int cmp)
|
||||||
|
{
|
||||||
|
PyObject *result = NULL;
|
||||||
|
|
||||||
|
if(!PyObject_TypeCheck(other, &tgl_PeerType)) {
|
||||||
|
result = Py_False;
|
||||||
|
} else {
|
||||||
|
if(((tgl_Peer*)self)->peer == NULL ||
|
||||||
|
((tgl_Peer*)other)->peer == NULL) {
|
||||||
|
result = Py_False; // If either object is not properly instantiated, compare is false
|
||||||
|
} else {
|
||||||
|
switch (cmp) {
|
||||||
|
case Py_EQ:
|
||||||
|
result = ((tgl_Peer*)self)->peer->id.id == ((tgl_Peer*)other)->peer->id.id ? Py_True : Py_False;
|
||||||
|
break;
|
||||||
|
case Py_NE:
|
||||||
|
result = ((tgl_Peer*)self)->peer->id.id == ((tgl_Peer*)other)->peer->id.id ? Py_False : Py_True;
|
||||||
|
break;
|
||||||
|
case Py_LE:
|
||||||
|
case Py_GE:
|
||||||
|
case Py_GT:
|
||||||
|
case Py_LT:
|
||||||
|
default:
|
||||||
|
Py_RETURN_NOTIMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Py_XINCREF(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PyTypeObject tgl_PeerType = {
|
PyTypeObject tgl_PeerType = {
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
@ -994,7 +1026,7 @@ PyTypeObject tgl_PeerType = {
|
|||||||
"tgl Peer", /* tp_doc */
|
"tgl Peer", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
0, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
(richcmpfunc)tgl_Peer_RichCompare, /* tp_richcompare */
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user