diff options
author | Benoit Foucher <benoit@zeroc.com> | 2013-01-31 11:41:32 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2013-01-31 11:41:32 +0100 |
commit | 755d6c3c698b3d8b343cdcec4de8fb01927d349c (patch) | |
tree | 2cfb63498395907a511dfb7de0fedb5e3ff0d1d1 /cpp | |
parent | Added C++11 libraries/binaries to OS X binary distribution (diff) | |
download | ice-755d6c3c698b3d8b343cdcec4de8fb01927d349c.tar.bz2 ice-755d6c3c698b3d8b343cdcec4de8fb01927d349c.tar.xz ice-755d6c3c698b3d8b343cdcec4de8fb01927d349c.zip |
Fixed ICE-4870 - optional comparison operators on C++ structs
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 92 | ||||
-rw-r--r-- | cpp/test/Ice/custom/Test.ice | 6 | ||||
-rw-r--r-- | cpp/test/Ice/stream/Test.ice | 6 | ||||
-rw-r--r-- | cpp/test/Slice/structure/Test.ice | 1 |
4 files changed, 55 insertions, 50 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; } diff --git a/cpp/test/Ice/custom/Test.ice b/cpp/test/Ice/custom/Test.ice index 8b3f1660bf8..d863050e528 100644 --- a/cpp/test/Ice/custom/Test.ice +++ b/cpp/test/Ice/custom/Test.ice @@ -50,7 +50,7 @@ sequence<Fixed> FixedSeq; sequence<FixedList> FixedListSeq; ["cpp:type:std::list< ::Test::FixedSeq>"] sequence<FixedSeq> FixedSeqList; -struct Variable +["cpp:comparable"] struct Variable { string s; BoolList bl; @@ -103,7 +103,7 @@ sequence<double> DoubleSeq; }; sequence<ClassOtherStruct> ClassOtherStructSeq; -["cpp:class"] struct ClassStruct +["cpp:class", "cpp:comparable"] struct ClassStruct { ClassOtherStructSeq otherSeq; ClassOtherStruct other; @@ -127,7 +127,7 @@ class DictClass ["cpp:type:Test::CustomBuffer<Ice::Float>"] sequence<float> FloatBuffer; ["cpp:type:Test::CustomBuffer<Ice::Double>"] sequence<double> DoubleBuffer; ["cpp:type:Test::CustomBuffer<Ice::Byte>"] sequence<byte> ByteBuffer; -struct BufferStruct +["cpp:comparable"] struct BufferStruct { ByteBuffer byteBuf; BoolBuffer boolBuf; diff --git a/cpp/test/Ice/stream/Test.ice b/cpp/test/Ice/stream/Test.ice index ca981794f5f..60f6004466d 100644 --- a/cpp/test/Ice/stream/Test.ice +++ b/cpp/test/Ice/stream/Test.ice @@ -23,7 +23,7 @@ enum MyEnum class MyClass; -struct SmallStruct +["cpp:comparable"] struct SmallStruct { bool bo; byte by; @@ -108,7 +108,7 @@ module Sub nestedEnum3 }; - struct NestedStruct + ["cpp:comparable"] struct NestedStruct { bool bo; byte by; @@ -144,7 +144,7 @@ module Sub2 nestedEnum6 }; - struct NestedStruct2 + ["cpp:comparable"] struct NestedStruct2 { bool bo; byte by; diff --git a/cpp/test/Slice/structure/Test.ice b/cpp/test/Slice/structure/Test.ice index 173378ab770..13c764a3f36 100644 --- a/cpp/test/Slice/structure/Test.ice +++ b/cpp/test/Slice/structure/Test.ice @@ -27,6 +27,7 @@ struct S1 string name; }; +["cpp:comparable"] struct S2 { bool bo; |