summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2009-10-29 21:02:24 -0230
committerMatthew Newhook <matthew@zeroc.com>2009-10-29 21:02:24 -0230
commit2ebd2ea2bad7b150b96049e2b2f17b4d30dd285d (patch)
tree13c20c753b1eec656e9147fe93740ef7f61d9bd7 /cpp/src/Slice/PythonUtil.cpp
parentFixed bug 4247 - untabify of src/Ice/Reference.cpp (diff)
downloadice-2ebd2ea2bad7b150b96049e2b2f17b4d30dd285d.tar.bz2
ice-2ebd2ea2bad7b150b96049e2b2f17b4d30dd285d.tar.xz
ice-2ebd2ea2bad7b150b96049e2b2f17b4d30dd285d.zip
http://bugzilla/bugzilla/show_bug.cgi?id=4342 - bug 4342
Python struct don't define rich operators
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp62
1 files changed, 45 insertions, 17 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 1f1be440704..905cd2769b4 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -1169,29 +1169,57 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
_out << nl << "return _h % 0x7fffffff";
_out.dec();
- _out << sp << nl << "def __cmp__(self, other):";
- _out.inc();
- _out << nl << "if isinstance(other, _M_" << abs << "):";
- _out.inc();
- for(r = memberList.begin(); r != memberList.end(); ++r)
+ //
+ // Rich operators. __lt__, __le__, __eq__, __ne__, __gt__, __ge__
+ //
+ static const char* richOps[] = {
+ "__lt__", "<",
+ "__le__", "<=",
+ "__eq__", "==",
+ "__ne__", "!=",
+ "__gt__", ">",
+ "__ge__", ">="
+ };
+ for(int opIndex = 0; opIndex != sizeof(richOps)/sizeof(richOps[0]); opIndex += 2)
{
- _out << nl << "if self." << r->fixedName << " < other." << r->fixedName << ':';
+ const char* opName = richOps[opIndex];
+ const char* opSymbol = richOps[opIndex+1];
+
+ _out << sp << nl << "def " << opName << "(self, other):";
+ _out.inc();
+ _out << nl << "if isinstance(other, _M_" << abs << "):";
_out.inc();
- _out << nl << "return -1";
+ if(!memberList.empty())
+ {
+ _out << nl << "return ";
+ for(r = memberList.begin(); r != memberList.end(); ++r)
+ {
+ if(r != memberList.begin())
+ {
+ if(opName == "__eq__")
+ {
+ _out << " and ";
+ }
+ else
+ {
+ _out << " or ";
+ }
+ }
+ _out << "self." << r->fixedName << " " << opSymbol << " other." << r->fixedName;
+ }
+ }
+ else
+ {
+ _out << nl << "return False";
+ }
_out.dec();
- _out << nl << "elif self." << r->fixedName << " > other." << r->fixedName << ':';
+ _out << nl << "elif other == None:";
_out.inc();
- _out << nl << "return 1";
+ _out << nl << "return False";
+ _out.dec();
+ _out << nl << "return NotImplemented";
_out.dec();
}
- _out << nl << "return 0";
- _out.dec();
- _out << nl << "elif other == None:";
- _out.inc();
- _out << nl << "return 1";
- _out.dec();
- _out << nl << "return NotImplemented";
- _out.dec();
//
// __str__