Commit c2bb5346 authored by Vincent Castellano's avatar Vincent Castellano

Adding tgl.Peer comparisons, only eq/ne

parent 13c22f3b
...@@ -969,6 +969,38 @@ tgl_Peer_repr(tgl_Peer *self) ...@@ -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 = { ...@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment