From 6bf9024107b56081ad616981706062ec5ecdee26 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 23 Jul 2018 13:24:21 -0700 Subject: [PATCH] Implementation of `operator==` for YGValue Summary: @public It's very useful sometimes for product code to compare `YGValue`s (e.g. in Fabric). Reviewed By: priteshrnandgaonkar Differential Revision: D8937594 fbshipit-source-id: b93e1ab4a6419ada6746f233b587e8c9cb32c6d4 --- ReactCommon/yoga/yoga/Yoga.cpp | 13 +++++++++++++ ReactCommon/yoga/yoga/Yoga.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index c9799c3cc..b9a5f781e 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -48,6 +48,19 @@ const YGValue YGValueZero = {0, YGUnitPoint}; const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; +bool operator==(const YGValue& lhs, const YGValue& rhs) { + if ((lhs.unit == YGUnitUndefined && rhs.unit == YGUnitUndefined) || + (lhs.unit == YGUnitAuto && rhs.unit == YGUnitAuto)) { + return true; + } + + return lhs.unit == rhs.unit && lhs.value == rhs.value; +} + +bool operator!=(const YGValue& lhs, const YGValue& rhs) { + return !(lhs == rhs); +} + #ifdef ANDROID #include static int YGAndroidLog( diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index d6b12d29a..5bcbe2ab6 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -45,6 +45,13 @@ typedef struct YGValue { extern const YGValue YGValueUndefined; extern const YGValue YGValueAuto; +#ifdef __cplusplus + +extern bool operator==(const YGValue& lhs, const YGValue& rhs); +extern bool operator!=(const YGValue& lhs, const YGValue& rhs); + +#endif + typedef struct YGConfig* YGConfigRef; typedef struct YGNode* YGNodeRef;