Files
yoga/yoga/YGStyle.cpp
David Aurelio 3645f43cea 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
2019-02-04 10:25:18 -08:00

52 lines
2.1 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#include "YGStyle.h"
// Yoga specific properties, not compatible with flexbox specification
bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
bool areNonFloatValuesEqual = lhs.direction == rhs.direction &&
lhs.flexDirection == rhs.flexDirection &&
lhs.justifyContent == rhs.justifyContent &&
lhs.alignContent == rhs.alignContent &&
lhs.alignItems == rhs.alignItems && lhs.alignSelf == rhs.alignSelf &&
lhs.positionType == rhs.positionType && lhs.flexWrap == rhs.flexWrap &&
lhs.overflow == rhs.overflow && lhs.display == rhs.display &&
YGValueEqual(lhs.flexBasis, rhs.flexBasis) && lhs.margin == rhs.margin &&
lhs.position == rhs.position && lhs.padding == rhs.padding &&
lhs.border == rhs.border && lhs.dimensions == rhs.dimensions &&
lhs.minDimensions == rhs.minDimensions &&
lhs.maxDimensions == rhs.maxDimensions;
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flex.isUndefined() == rhs.flex.isUndefined();
if (areNonFloatValuesEqual && !lhs.flex.isUndefined() &&
!rhs.flex.isUndefined()) {
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex == rhs.flex;
}
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flexGrow.isUndefined() == rhs.flexGrow.isUndefined();
if (areNonFloatValuesEqual && !lhs.flexGrow.isUndefined()) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.flexGrow == rhs.flexGrow;
}
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flexShrink.isUndefined() == rhs.flexShrink.isUndefined();
if (areNonFloatValuesEqual && !rhs.flexShrink.isUndefined()) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.flexShrink == rhs.flexShrink;
}
if (!(lhs.aspectRatio.isUndefined() && rhs.aspectRatio.isUndefined())) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.aspectRatio == rhs.aspectRatio;
}
return areNonFloatValuesEqual;
}