Make `==` operator for `YGStyle` free function
Summary: @public Makes it work nicely with gtest. Also allows rhs *and* lhs to offer `operator(YGStyle)()`. Reviewed By: SidharthGuglani Differential Revision: D13942573 fbshipit-source-id: ff8b3a9aa6f05ca1b0572eb97d0ad23b09d77871
This commit is contained in:
parent
5184f0d7a3
commit
0e1d4ecbb7
|
@ -7,43 +7,44 @@
|
||||||
#include "YGStyle.h"
|
#include "YGStyle.h"
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
bool YGStyle::operator==(const YGStyle& style) {
|
bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
|
||||||
bool areNonFloatValuesEqual = direction == style.direction &&
|
bool areNonFloatValuesEqual = lhs.direction == rhs.direction &&
|
||||||
flexDirection == style.flexDirection &&
|
lhs.flexDirection == rhs.flexDirection &&
|
||||||
justifyContent == style.justifyContent &&
|
lhs.justifyContent == rhs.justifyContent &&
|
||||||
alignContent == style.alignContent && alignItems == style.alignItems &&
|
lhs.alignContent == rhs.alignContent &&
|
||||||
alignSelf == style.alignSelf && positionType == style.positionType &&
|
lhs.alignItems == rhs.alignItems && lhs.alignSelf == rhs.alignSelf &&
|
||||||
flexWrap == style.flexWrap && overflow == style.overflow &&
|
lhs.positionType == rhs.positionType && lhs.flexWrap == rhs.flexWrap &&
|
||||||
display == style.display && YGValueEqual(flexBasis, style.flexBasis) &&
|
lhs.overflow == rhs.overflow && lhs.display == rhs.display &&
|
||||||
margin == style.margin && position == style.position &&
|
YGValueEqual(lhs.flexBasis, rhs.flexBasis) && lhs.margin == rhs.margin &&
|
||||||
padding == style.padding && border == style.border &&
|
lhs.position == rhs.position && lhs.padding == rhs.padding &&
|
||||||
dimensions == style.dimensions && minDimensions == style.minDimensions &&
|
lhs.border == rhs.border && lhs.dimensions == rhs.dimensions &&
|
||||||
maxDimensions == style.maxDimensions;
|
lhs.minDimensions == rhs.minDimensions &&
|
||||||
|
lhs.maxDimensions == rhs.maxDimensions;
|
||||||
|
|
||||||
areNonFloatValuesEqual =
|
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||||
areNonFloatValuesEqual && flex.isUndefined() == style.flex.isUndefined();
|
lhs.flex.isUndefined() == rhs.flex.isUndefined();
|
||||||
if (areNonFloatValuesEqual && !flex.isUndefined() &&
|
if (areNonFloatValuesEqual && !lhs.flex.isUndefined() &&
|
||||||
!style.flex.isUndefined()) {
|
!rhs.flex.isUndefined()) {
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual && flex == style.flex;
|
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex == rhs.flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||||
flexGrow.isUndefined() == style.flexGrow.isUndefined();
|
lhs.flexGrow.isUndefined() == rhs.flexGrow.isUndefined();
|
||||||
if (areNonFloatValuesEqual && !flexGrow.isUndefined()) {
|
if (areNonFloatValuesEqual && !lhs.flexGrow.isUndefined()) {
|
||||||
areNonFloatValuesEqual =
|
areNonFloatValuesEqual =
|
||||||
areNonFloatValuesEqual && flexGrow == style.flexGrow;
|
areNonFloatValuesEqual && lhs.flexGrow == rhs.flexGrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
areNonFloatValuesEqual = areNonFloatValuesEqual &&
|
||||||
flexShrink.isUndefined() == style.flexShrink.isUndefined();
|
lhs.flexShrink.isUndefined() == rhs.flexShrink.isUndefined();
|
||||||
if (areNonFloatValuesEqual && !style.flexShrink.isUndefined()) {
|
if (areNonFloatValuesEqual && !rhs.flexShrink.isUndefined()) {
|
||||||
areNonFloatValuesEqual =
|
areNonFloatValuesEqual =
|
||||||
areNonFloatValuesEqual && flexShrink == style.flexShrink;
|
areNonFloatValuesEqual && lhs.flexShrink == rhs.flexShrink;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) {
|
if (!(lhs.aspectRatio.isUndefined() && rhs.aspectRatio.isUndefined())) {
|
||||||
areNonFloatValuesEqual =
|
areNonFloatValuesEqual =
|
||||||
areNonFloatValuesEqual && aspectRatio == style.aspectRatio;
|
areNonFloatValuesEqual && lhs.aspectRatio == rhs.aspectRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
return areNonFloatValuesEqual;
|
return areNonFloatValuesEqual;
|
||||||
|
|
|
@ -66,10 +66,10 @@ public:
|
||||||
flexWrap(YGWrapNoWrap),
|
flexWrap(YGWrapNoWrap),
|
||||||
overflow(YGOverflowVisible),
|
overflow(YGOverflowVisible),
|
||||||
display(YGDisplayFlex) {}
|
display(YGDisplayFlex) {}
|
||||||
bool operator==(const YGStyle& style);
|
|
||||||
|
|
||||||
bool operator!=(YGStyle style) {
|
|
||||||
return !(*this == style);
|
|
||||||
}
|
|
||||||
~YGStyle() = default;
|
~YGStyle() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator==(const YGStyle& lhs, const YGStyle& rhs);
|
||||||
|
inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue