From d19da9e528842871e4610066b325c8cd6af0a160 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 6 Dec 2018 07:35:08 -0800 Subject: [PATCH] Move out `YGValue` Summary: @public Creates a single header file for `YGValue`. This is in preparation of a more compact representation of `YGValue` within `YGStyle`. Also fixes the incorrect definition of NAN. Reviewed By: SidharthGuglani Differential Revision: D13172444 fbshipit-source-id: 4250dbcf8fe15ec3ecdee3913360a73bab633ce3 --- yoga/YGValue.cpp | 29 +++++++++++++++++++++++++++++ yoga/YGValue.h | 40 ++++++++++++++++++++++++++++++++++++++++ yoga/Yoga.cpp | 17 ----------------- yoga/Yoga.h | 28 +--------------------------- 4 files changed, 70 insertions(+), 44 deletions(-) create mode 100644 yoga/YGValue.cpp create mode 100644 yoga/YGValue.h diff --git a/yoga/YGValue.cpp b/yoga/YGValue.cpp new file mode 100644 index 00000000..4bfe083d --- /dev/null +++ b/yoga/YGValue.cpp @@ -0,0 +1,29 @@ +/** + * 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 "YGValue.h" + +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 != rhs.unit) { + return false; + } + + switch (lhs.unit) { + case YGUnitUndefined: + case YGUnitAuto: + return true; + default: + return lhs.value == rhs.value; + } +} + +bool operator!=(const YGValue& lhs, const YGValue& rhs) { + return !(lhs == rhs); +} diff --git a/yoga/YGValue.h b/yoga/YGValue.h new file mode 100644 index 00000000..803b8e78 --- /dev/null +++ b/yoga/YGValue.h @@ -0,0 +1,40 @@ +/** + * 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. + */ +#pragma once + +#include +#include "YGEnums.h" +#include "YGMacros.h" + +YG_EXTERN_C_BEGIN + +// Not defined in MSVC++ +#ifndef NAN +static const uint32_t __nan = 0x7fc00000; +#define NAN (*(const float*)__nan) +#endif + +#define YGUndefined NAN + +typedef struct YGValue { + float value; + YGUnit unit; +} YGValue; + +extern const YGValue YGValueAuto; +extern const YGValue YGValueUndefined; +extern const YGValue YGValueZero; + +YG_EXTERN_C_END + +#ifdef __cplusplus + +bool operator==(const YGValue& lhs, const YGValue& rhs); + +bool operator!=(const YGValue& lhs, const YGValue& rhs); + +#endif diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index d5fc12ef..246e0f41 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -39,23 +39,6 @@ static int YGDefaultLog( va_list args); #endif -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/yoga/Yoga.h b/yoga/Yoga.h index 61aae0fe..787af6df 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -17,16 +17,9 @@ #include #endif -// Not defined in MSVC++ -#ifndef NAN -static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; -#define NAN (*(const float*)__nan) -#endif - -#define YGUndefined NAN - #include "YGEnums.h" #include "YGMacros.h" +#include "YGValue.h" YG_EXTERN_C_BEGIN @@ -35,25 +28,6 @@ typedef struct YGSize { float height; } YGSize; -typedef struct YGValue { - float value; - YGUnit unit; -} YGValue; - -extern const YGValue YGValueUndefined; -extern const YGValue YGValueAuto; - -#ifdef __cplusplus - -YG_EXTERN_C_END - -extern bool operator==(const YGValue& lhs, const YGValue& rhs); -extern bool operator!=(const YGValue& lhs, const YGValue& rhs); - -YG_EXTERN_C_BEGIN - -#endif - typedef struct YGConfig* YGConfigRef; typedef struct YGNode* YGNodeRef;