From b62cc09379bfb11e95dbba1eace9b8afb0131396 Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Thu, 20 Sep 2007 07:00:46 -0700 Subject: changing struct __eq__ to __cmp___; check for None --- cpp/src/Slice/PythonUtil.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'cpp/src/Slice/PythonUtil.cpp') diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index fdc6449285d..1e730598a94 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -1103,16 +1103,24 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p) _out << nl << "return _h % 0x7fffffff"; _out.dec(); - _out << sp << nl << "def __eq__(self, other):"; + _out << sp << nl << "def __cmp__(self, other):"; + _out.inc(); + _out << nl << "if other == None:"; _out.inc(); + _out << nl << "return 1"; + _out.dec(); for(r = memberList.begin(); r != memberList.end(); ++r) { - _out << nl << "if not self." << r->fixedName << " == other." << r->fixedName << ':'; + _out << nl << "if self." << r->fixedName << " < other." << r->fixedName << ':'; + _out.inc(); + _out << nl << "return -1"; + _out.dec(); + _out << nl << "elif self." << r->fixedName << " > other." << r->fixedName << ':'; _out.inc(); - _out << nl << "return False"; + _out << nl << "return 1"; _out.dec(); } - _out << nl << "return True"; + _out << nl << "return 0"; _out.dec(); // -- cgit v1.2.3