slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
FloatOptional.h
浏览该文件的文档.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
11#include <limits>
12
13namespace facebook::yoga {
14
16 private:
17 float value_ = std::numeric_limits<float>::quiet_NaN();
18
19 public:
20 explicit constexpr FloatOptional(float value) : value_(value) {}
21 constexpr FloatOptional() = default;
22
23 // returns the wrapped value, or a value x with YGIsUndefined(x) == true
24 constexpr float unwrap() const {
25 return value_;
26 }
27
28 constexpr float unwrapOrDefault(float defaultValue) const {
29 return isUndefined() ? defaultValue : value_;
30 }
31
32 constexpr bool isUndefined() const {
34 }
35
36 constexpr bool isDefined() const {
37 return yoga::isDefined(value_);
38 }
39};
40
41// operators take FloatOptional by value, as it is a 32bit value
42
43constexpr bool operator==(FloatOptional lhs, FloatOptional rhs) {
44 return lhs.unwrap() == rhs.unwrap() ||
45 (lhs.isUndefined() && rhs.isUndefined());
46}
47
48constexpr bool operator==(FloatOptional lhs, float rhs) {
49 return lhs == FloatOptional{rhs};
50}
51
52constexpr bool operator==(float lhs, FloatOptional rhs) {
53 return rhs == lhs;
54}
55
57 return FloatOptional{lhs.unwrap() + rhs.unwrap()};
58}
59
60constexpr bool operator>(FloatOptional lhs, FloatOptional rhs) {
61 return lhs.unwrap() > rhs.unwrap();
62}
63
64constexpr bool operator<(FloatOptional lhs, FloatOptional rhs) {
65 return lhs.unwrap() < rhs.unwrap();
66}
67
68constexpr bool operator>=(FloatOptional lhs, FloatOptional rhs) {
69 return lhs > rhs || lhs == rhs;
70}
71
72constexpr bool operator<=(FloatOptional lhs, FloatOptional rhs) {
73 return lhs < rhs || lhs == rhs;
74}
75
79
81 return yoga::inexactEquals(lhs.unwrap(), rhs.unwrap());
82}
83
84} // namespace facebook::yoga
Definition Benchmark.cpp:19
constexpr bool isDefined(std::floating_point auto value)
Definition Comparison.h:23
static bool isUndefined(json &j)
Definition TreeDeserialization.cpp:24
constexpr bool operator>(FloatOptional lhs, FloatOptional rhs)
Definition FloatOptional.h:60
constexpr auto maxOrDefined(std::floating_point auto a, std::floating_point auto b)
Definition Comparison.h:35
constexpr FloatOptional operator+(FloatOptional lhs, FloatOptional rhs)
Definition FloatOptional.h:56
bool inexactEquals(float a, float b)
Definition Comparison.h:56
constexpr bool operator>=(FloatOptional lhs, FloatOptional rhs)
Definition FloatOptional.h:68
constexpr bool operator==(FloatOptional lhs, FloatOptional rhs)
Definition FloatOptional.h:43
constexpr bool operator<(FloatOptional lhs, FloatOptional rhs)
Definition FloatOptional.h:64
constexpr bool operator<=(FloatOptional lhs, FloatOptional rhs)
Definition FloatOptional.h:72
Definition FloatOptional.h:15
constexpr FloatOptional(float value)
Definition FloatOptional.h:20
float value_
Definition FloatOptional.h:17
constexpr bool isUndefined() const
Definition FloatOptional.h:32
constexpr float unwrapOrDefault(float defaultValue) const
Definition FloatOptional.h:28
constexpr FloatOptional()=default
constexpr bool isDefined() const
Definition FloatOptional.h:36
constexpr float unwrap() const
Definition FloatOptional.h:24