summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2013-01-31 11:41:32 +0100
committerBenoit Foucher <benoit@zeroc.com>2013-01-31 11:41:32 +0100
commit755d6c3c698b3d8b343cdcec4de8fb01927d349c (patch)
tree2cfb63498395907a511dfb7de0fedb5e3ff0d1d1 /cpp/src/slice2cpp/Gen.cpp
parentAdded C++11 libraries/binaries to OS X binary distribution (diff)
downloadice-755d6c3c698b3d8b343cdcec4de8fb01927d349c.tar.bz2
ice-755d6c3c698b3d8b343cdcec4de8fb01927d349c.tar.xz
ice-755d6c3c698b3d8b343cdcec4de8fb01927d349c.zip
Fixed ICE-4870 - optional comparison operators on C++ structs
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp92
1 files changed, 48 insertions, 44 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index d5a8956bf92..983f933a7d9 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -1169,58 +1169,62 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
{
params.push_back(fixKwd((*q)->name()));
}
-
- H << sp << nl << "bool operator==(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "if(this == &__rhs)";
- H << sb;
- H << nl << "return true;";
- H << eb;
- for(vector<string>::const_iterator pi = params.begin(); pi != params.end(); ++pi)
+
+ bool containsSequence = false;
+ if((Dictionary::legalKeyType(p, containsSequence) && !containsSequence) || p->hasMetaData("cpp:comparable"))
{
- H << nl << "if(" << *pi << " != __rhs." << *pi << ')';
+ H << sp << nl << "bool operator==(const " << name << "& __rhs) const";
H << sb;
- H << nl << "return false;";
- H << eb;
- }
- H << nl << "return true;";
- H << eb;
- H << sp << nl << "bool operator<(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "if(this == &__rhs)";
- H << sb;
- H << nl << "return false;";
- H << eb;
- for(vector<string>::const_iterator pi = params.begin(); pi != params.end(); ++pi)
- {
- H << nl << "if(" << *pi << " < __rhs." << *pi << ')';
+ H << nl << "if(this == &__rhs)";
H << sb;
H << nl << "return true;";
H << eb;
- H << nl << "else if(__rhs." << *pi << " < " << *pi << ')';
+ for(vector<string>::const_iterator pi = params.begin(); pi != params.end(); ++pi)
+ {
+ H << nl << "if(" << *pi << " != __rhs." << *pi << ')';
+ H << sb;
+ H << nl << "return false;";
+ H << eb;
+ }
+ H << nl << "return true;";
+ H << eb;
+ H << sp << nl << "bool operator<(const " << name << "& __rhs) const";
+ H << sb;
+ H << nl << "if(this == &__rhs)";
H << sb;
H << nl << "return false;";
H << eb;
+ for(vector<string>::const_iterator pi = params.begin(); pi != params.end(); ++pi)
+ {
+ H << nl << "if(" << *pi << " < __rhs." << *pi << ')';
+ H << sb;
+ H << nl << "return true;";
+ H << eb;
+ H << nl << "else if(__rhs." << *pi << " < " << *pi << ')';
+ H << sb;
+ H << nl << "return false;";
+ H << eb;
+ }
+ H << nl << "return false;";
+ H << eb;
+
+ H << sp << nl << "bool operator!=(const " << name << "& __rhs) const";
+ H << sb;
+ H << nl << "return !operator==(__rhs);";
+ H << eb;
+ H << nl << "bool operator<=(const " << name << "& __rhs) const";
+ H << sb;
+ H << nl << "return operator<(__rhs) || operator==(__rhs);";
+ H << eb;
+ H << nl << "bool operator>(const " << name << "& __rhs) const";
+ H << sb;
+ H << nl << "return !operator<(__rhs) && !operator==(__rhs);";
+ H << eb;
+ H << nl << "bool operator>=(const " << name << "& __rhs) const";
+ H << sb;
+ H << nl << "return !operator<(__rhs);";
+ H << eb;
}
- H << nl << "return false;";
- H << eb;
-
- H << sp << nl << "bool operator!=(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return !operator==(__rhs);";
- H << eb;
- H << nl << "bool operator<=(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return operator<(__rhs) || operator==(__rhs);";
- H << eb;
- H << nl << "bool operator>(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return !operator<(__rhs) && !operator==(__rhs);";
- H << eb;
- H << nl << "bool operator>=(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return !operator<(__rhs);";
- H << eb;
H << eb << ';';
if(findMetaData(p->getMetaData()) == "%class")
@@ -6408,7 +6412,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin
{
continue;
}
- if(StructPtr::dynamicCast(cont) && ss.find("class") == 0)
+ if(StructPtr::dynamicCast(cont) && (ss.find("class") == 0 || ss.find("comparable") == 0))
{
continue;
}