rename StructEqualityResult to Equality

parent 6ad2e914
......@@ -274,43 +274,43 @@ TEST(Any, Equals) {
auto anyB = builderB.getRoot<AnyPointer>();
initTestMessage(rootB);
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
rootA.setBoolField(false);
EXPECT_EQ(StructEqualityResult::NOT_EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::NOT_EQUAL, anyA.equals(anyB));
rootB.setBoolField(false);
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
rootB.setEnumField(test::TestEnum::GARPLY);
EXPECT_EQ(StructEqualityResult::NOT_EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::NOT_EQUAL, anyA.equals(anyB));
rootA.setEnumField(test::TestEnum::GARPLY);
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
rootA.getStructField().setTextField("buzz");
EXPECT_EQ(StructEqualityResult::NOT_EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::NOT_EQUAL, anyA.equals(anyB));
rootB.getStructField().setTextField("buzz");
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
rootA.initVoidList(3);
EXPECT_EQ(StructEqualityResult::NOT_EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::NOT_EQUAL, anyA.equals(anyB));
rootB.initVoidList(3);
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
rootA.getBoolList().set(2, true);
EXPECT_EQ(StructEqualityResult::NOT_EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::NOT_EQUAL, anyA.equals(anyB));
rootB.getBoolList().set(2, true);
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
rootB.getStructList()[1].setTextField("my NEW structlist 2");
EXPECT_EQ(StructEqualityResult::NOT_EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::NOT_EQUAL, anyA.equals(anyB));
rootA.getStructList()[1].setTextField("my NEW structlist 2");
EXPECT_EQ(StructEqualityResult::EQUAL, anyA.equals(anyB));
EXPECT_EQ(Equality::EQUAL, anyA.equals(anyB));
}
} // namespace
......
......@@ -79,7 +79,7 @@ kj::Own<ClientHook> AnyPointer::Pipeline::asCap() {
#endif // !CAPNP_LITE
StructEqualityResult AnyStruct::Reader::equals(AnyStruct::Reader right) {
Equality AnyStruct::Reader::equals(AnyStruct::Reader right) {
auto dataL = getDataSection();
size_t dataSizeL = dataL.size();
while(dataSizeL > 0 && dataL[dataSizeL - 1] == 0) {
......@@ -93,11 +93,11 @@ StructEqualityResult AnyStruct::Reader::equals(AnyStruct::Reader right) {
}
if(dataSizeL != dataSizeR) {
return StructEqualityResult::NOT_EQUAL;
return Equality::NOT_EQUAL;
}
if(0 != memcmp(dataL.begin(), dataR.begin(), dataSizeL)) {
return StructEqualityResult::NOT_EQUAL;
return Equality::NOT_EQUAL;
}
auto ptrsL = getPointerSection();
......@@ -105,17 +105,17 @@ StructEqualityResult AnyStruct::Reader::equals(AnyStruct::Reader right) {
size_t i = 0;
auto eqResult = StructEqualityResult::EQUAL;
auto eqResult = Equality::EQUAL;
for(; i < kj::min(ptrsL.size(), ptrsR.size()); i++) {
auto l = ptrsL[i];
auto r = ptrsR[i];
switch(l.equals(r)) {
case StructEqualityResult::EQUAL:
case Equality::EQUAL:
break;
case StructEqualityResult::NOT_EQUAL:
return StructEqualityResult::NOT_EQUAL;
case StructEqualityResult::UNKNOWN_CONTAINS_CAPS:
eqResult = StructEqualityResult::UNKNOWN_CONTAINS_CAPS;
case Equality::NOT_EQUAL:
return Equality::NOT_EQUAL;
case Equality::UNKNOWN_CONTAINS_CAPS:
eqResult = Equality::UNKNOWN_CONTAINS_CAPS;
break;
default:
KJ_UNREACHABLE;
......@@ -125,24 +125,24 @@ StructEqualityResult AnyStruct::Reader::equals(AnyStruct::Reader right) {
return eqResult;
}
kj::StringPtr KJ_STRINGIFY(StructEqualityResult res) {
kj::StringPtr KJ_STRINGIFY(Equality res) {
switch(res) {
case StructEqualityResult::NOT_EQUAL:
case Equality::NOT_EQUAL:
return "NOT_EQUAL";
case StructEqualityResult::EQUAL:
case Equality::EQUAL:
return "EQUAL";
case StructEqualityResult::UNKNOWN_CONTAINS_CAPS:
case Equality::UNKNOWN_CONTAINS_CAPS:
return "UNKNOWN_CONTAINS_CAPS";
default:
KJ_UNREACHABLE;
}
}
StructEqualityResult AnyList::Reader::equals(AnyList::Reader right) {
Equality AnyList::Reader::equals(AnyList::Reader right) {
if(size() != right.size()) {
return StructEqualityResult::NOT_EQUAL;
return Equality::NOT_EQUAL;
}
auto eqResult = StructEqualityResult::EQUAL;
auto eqResult = Equality::EQUAL;
switch(getElementSize()) {
case ElementSize::VOID:
case ElementSize::BIT:
......@@ -152,12 +152,12 @@ StructEqualityResult AnyList::Reader::equals(AnyList::Reader right) {
case ElementSize::EIGHT_BYTES:
if(getElementSize() == right.getElementSize()) {
if(memcmp(getRawBytes().begin(), right.getRawBytes().begin(), getRawBytes().size()) == 0) {
return StructEqualityResult::EQUAL;
return Equality::EQUAL;
} else {
return StructEqualityResult::NOT_EQUAL;
return Equality::NOT_EQUAL;
}
} else {
return StructEqualityResult::NOT_EQUAL;
return Equality::NOT_EQUAL;
}
case ElementSize::POINTER:
case ElementSize::INLINE_COMPOSITE: {
......@@ -165,12 +165,12 @@ StructEqualityResult AnyList::Reader::equals(AnyList::Reader right) {
auto rlist = right.as<List<AnyStruct>>();
for(size_t i = 0; i < size(); i++) {
switch(llist[i].equals(rlist[i])) {
case StructEqualityResult::EQUAL:
case Equality::EQUAL:
break;
case StructEqualityResult::NOT_EQUAL:
return StructEqualityResult::NOT_EQUAL;
case StructEqualityResult::UNKNOWN_CONTAINS_CAPS:
eqResult = StructEqualityResult::UNKNOWN_CONTAINS_CAPS;
case Equality::NOT_EQUAL:
return Equality::NOT_EQUAL;
case Equality::UNKNOWN_CONTAINS_CAPS:
eqResult = Equality::UNKNOWN_CONTAINS_CAPS;
break;
default:
KJ_UNREACHABLE;
......@@ -183,19 +183,19 @@ StructEqualityResult AnyList::Reader::equals(AnyList::Reader right) {
}
}
StructEqualityResult AnyPointer::Reader::equals(AnyPointer::Reader right) {
Equality AnyPointer::Reader::equals(AnyPointer::Reader right) {
if(getPointerType() != right.getPointerType()) {
return StructEqualityResult::NOT_EQUAL;
return Equality::NOT_EQUAL;
}
switch(getPointerType()) {
case PointerType::NULL_:
return StructEqualityResult::EQUAL;
return Equality::EQUAL;
case PointerType::STRUCT:
return getAs<AnyStruct>().equals(right.getAs<AnyStruct>());
case PointerType::LIST:
return getAs<AnyList>().equals(right.getAs<AnyList>());
case PointerType::CAPABILITY:
return StructEqualityResult::UNKNOWN_CONTAINS_CAPS;
return Equality::UNKNOWN_CONTAINS_CAPS;
default:
// There aren't currently any other types of pointers
KJ_UNREACHABLE;
......@@ -204,11 +204,11 @@ StructEqualityResult AnyPointer::Reader::equals(AnyPointer::Reader right) {
bool AnyPointer::Reader::operator ==(AnyPointer::Reader right) {
switch(equals(right)) {
case StructEqualityResult::EQUAL:
case Equality::EQUAL:
return true;
case StructEqualityResult::NOT_EQUAL:
case Equality::NOT_EQUAL:
return false;
case StructEqualityResult::UNKNOWN_CONTAINS_CAPS:
case Equality::UNKNOWN_CONTAINS_CAPS:
KJ_FAIL_REQUIRE(
"operator== cannot determine equality of capabilities; use equals() instead if you need to handle this case");
default:
......@@ -218,11 +218,11 @@ bool AnyPointer::Reader::operator ==(AnyPointer::Reader right) {
bool AnyStruct::Reader::operator ==(AnyStruct::Reader right) {
switch(equals(right)) {
case StructEqualityResult::EQUAL:
case Equality::EQUAL:
return true;
case StructEqualityResult::NOT_EQUAL:
case Equality::NOT_EQUAL:
return false;
case StructEqualityResult::UNKNOWN_CONTAINS_CAPS:
case Equality::UNKNOWN_CONTAINS_CAPS:
KJ_FAIL_REQUIRE(
"operator== cannot determine equality of capabilities; use equals() instead if you need to handle this case");
default:
......@@ -232,11 +232,11 @@ bool AnyStruct::Reader::operator ==(AnyStruct::Reader right) {
bool AnyList::Reader::operator ==(AnyList::Reader right) {
switch(equals(right)) {
case StructEqualityResult::EQUAL:
case Equality::EQUAL:
return true;
case StructEqualityResult::NOT_EQUAL:
case Equality::NOT_EQUAL:
return false;
case StructEqualityResult::UNKNOWN_CONTAINS_CAPS:
case Equality::UNKNOWN_CONTAINS_CAPS:
KJ_FAIL_REQUIRE(
"operator== cannot determine equality of capabilities; use equals() instead if you need to handle this case");
default:
......
......@@ -74,13 +74,13 @@ template <> struct Kind_<AnyList> { static constexpr Kind kind = Kind::OTHER; };
// =======================================================================================
// AnyPointer!
enum class StructEqualityResult {
enum class Equality {
NOT_EQUAL,
EQUAL,
UNKNOWN_CONTAINS_CAPS
};
kj::StringPtr KJ_STRINGIFY(StructEqualityResult res);
kj::StringPtr KJ_STRINGIFY(Equality res);
struct AnyPointer {
// Reader/Builder for the `AnyPointer` field type, i.e. a pointer that can point to an arbitrary
......@@ -105,7 +105,7 @@ struct AnyPointer {
inline bool isList() const { return getPointerType() == PointerType::LIST; }
inline bool isCapability() const { return getPointerType() == PointerType::CAPABILITY; }
StructEqualityResult equals(AnyPointer::Reader right);
Equality equals(AnyPointer::Reader right);
bool operator ==(AnyPointer::Reader right);
inline bool operator !=(AnyPointer::Reader right) {
return !(*this == right);
......@@ -158,7 +158,7 @@ struct AnyPointer {
inline bool isList() { return getPointerType() == PointerType::LIST; }
inline bool isCapability() { return getPointerType() == PointerType::CAPABILITY; }
inline StructEqualityResult equals(AnyPointer::Reader right) {
inline Equality equals(AnyPointer::Reader right) {
return asReader().equals(right);
}
inline bool operator ==(AnyPointer::Reader right) {
......@@ -458,7 +458,7 @@ public:
return List<AnyPointer>::Reader(_reader.getPointerSectionAsList());
}
StructEqualityResult equals(AnyStruct::Reader right);
Equality equals(AnyStruct::Reader right);
bool operator ==(AnyStruct::Reader right);
inline bool operator !=(AnyStruct::Reader right) {
return !(*this == right);
......@@ -494,7 +494,7 @@ public:
return List<AnyPointer>::Builder(_builder.getPointerSectionAsList());
}
inline StructEqualityResult equals(AnyStruct::Reader right) {
inline Equality equals(AnyStruct::Reader right) {
return asReader().equals(right);
}
inline bool operator ==(AnyStruct::Reader right) {
......@@ -613,7 +613,7 @@ public:
inline kj::ArrayPtr<const byte> getRawBytes() { return _reader.asRawBytes(); }
StructEqualityResult equals(AnyList::Reader right);
Equality equals(AnyList::Reader right);
inline bool operator ==(AnyList::Reader right);
inline bool operator !=(AnyList::Reader right) {
return !(*this == right);
......@@ -644,7 +644,7 @@ public:
inline ElementSize getElementSize() { return _builder.getElementSize(); }
inline uint size() { return _builder.size() / ELEMENTS; }
StructEqualityResult equals(AnyList::Reader right);
Equality equals(AnyList::Reader right);
inline bool operator ==(AnyList::Reader right) {
return asReader() == right;
}
......
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