Summary: This change is mostly needed to support the new react-native architecture with Swift. Some private yoga headers end up being included in the swift build and result in compilation failure since swift cannot compile c++ modules. See https://github.com/facebook/react-native/pull/33381. The most reliable fix is to include all headers as public headers, and add `#ifdef __cplusplus` to those that include c++. This is already what we do for other headers, this applies this to all headers. Tested in the YogaKitSample, and also in a react-native app. Changelog: [iOS] [Changed] - Make all Yoga headers public and add #ifdef __cplusplus Pull Request resolved: https://github.com/facebook/yoga/pull/1150 Reviewed By: dmitryrykun Differential Revision: D36966687 Pulled By: cortinico fbshipit-source-id: a34a54d56df43ab4934715070bab8e790b9abd39
75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and 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
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include "Yoga-internal.h"
|
|
|
|
struct YGFloatOptional {
|
|
private:
|
|
float value_ = std::numeric_limits<float>::quiet_NaN();
|
|
|
|
public:
|
|
explicit constexpr YGFloatOptional(float value) : value_(value) {}
|
|
constexpr YGFloatOptional() = default;
|
|
|
|
// returns the wrapped value, or a value x with YGIsUndefined(x) == true
|
|
constexpr float unwrap() const { return value_; }
|
|
|
|
bool isUndefined() const { return std::isnan(value_); }
|
|
};
|
|
|
|
// operators take YGFloatOptional by value, as it is a 32bit value
|
|
|
|
inline bool operator==(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs.unwrap() == rhs.unwrap() ||
|
|
(lhs.isUndefined() && rhs.isUndefined());
|
|
}
|
|
inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
inline bool operator==(YGFloatOptional lhs, float rhs) {
|
|
return lhs == YGFloatOptional{rhs};
|
|
}
|
|
inline bool operator!=(YGFloatOptional lhs, float rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
inline bool operator==(float lhs, YGFloatOptional rhs) {
|
|
return rhs == lhs;
|
|
}
|
|
inline bool operator!=(float lhs, YGFloatOptional rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
inline YGFloatOptional operator+(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return YGFloatOptional{lhs.unwrap() + rhs.unwrap()};
|
|
}
|
|
|
|
inline bool operator>(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs.unwrap() > rhs.unwrap();
|
|
}
|
|
|
|
inline bool operator<(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs.unwrap() < rhs.unwrap();
|
|
}
|
|
|
|
inline bool operator>=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs > rhs || lhs == rhs;
|
|
}
|
|
|
|
inline bool operator<=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs < rhs || lhs == rhs;
|
|
}
|
|
|
|
#endif
|