2 * Copyright (c) 2014-present, Facebook, Inc.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
8 #include "YGFloatOptional.h"
13 YGFloatOptional::YGFloatOptional(const float& value) {
14 if (YGFloatIsUndefined(value)) {
23 YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {}
25 const float& YGFloatOptional::getValue() const {
27 // Abort, accessing a value of an undefined float optional
28 std::cerr << "Tried to get value of an undefined YGFloatOptional\n";
29 std::exit(EXIT_FAILURE);
34 void YGFloatOptional::setValue(const float& val) {
39 const bool& YGFloatOptional::isUndefined() const {
43 bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
44 if (isUndefined_ == op.isUndefined()) {
45 return isUndefined_ ? true : value_ == op.getValue();
50 bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
51 return !(*this == op);
54 bool YGFloatOptional::operator==(const float& val) const {
55 if (YGFloatIsUndefined(val) == isUndefined_) {
56 return isUndefined_ ? true : val == value_;
61 bool YGFloatOptional::operator!=(const float& val) const {
62 return !(*this == val);
65 YGFloatOptional YGFloatOptional::operator+(const YGFloatOptional& op) {
66 if (!isUndefined_ && !op.isUndefined_) {
67 return YGFloatOptional(value_ + op.value_);
69 return YGFloatOptional();
72 bool YGFloatOptional::operator>(const YGFloatOptional& op) const {
73 if (isUndefined_ || op.isUndefined_) {
76 return value_ > op.value_;
79 bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
80 if (isUndefined_ || op.isUndefined_) {
83 return value_ < op.value_;
86 bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
87 return *this == op ? true : *this > op;
90 bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
91 return *this == op ? true : *this < op;