Tidy up YGFloatOptional
Summary: Just some convention/weird style things. `float` should be passed by value, weird use of ?: operator instead of ||. Reviewed By: priteshrnandgaonkar Differential Revision: D8804407 fbshipit-source-id: e0d67363ccde36ec5bccec7497ed0ffd364b3fcf
This commit is contained in:
parent
d756d94b3a
commit
7eb419d4bf
|
@ -1,16 +1,16 @@
|
|||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
/*
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "YGFloatOptional.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "Yoga.h"
|
||||
|
||||
YGFloatOptional::YGFloatOptional(const float& value) {
|
||||
YGFloatOptional::YGFloatOptional(float value) {
|
||||
if (YGFloatIsUndefined(value)) {
|
||||
isUndefined_ = true;
|
||||
value_ = 0;
|
||||
|
@ -31,18 +31,9 @@ const float& YGFloatOptional::getValue() const {
|
|||
return value_;
|
||||
}
|
||||
|
||||
void YGFloatOptional::setValue(const float& val) {
|
||||
value_ = val;
|
||||
isUndefined_ = false;
|
||||
}
|
||||
|
||||
const bool& YGFloatOptional::isUndefined() const {
|
||||
return isUndefined_;
|
||||
}
|
||||
|
||||
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
|
||||
if (isUndefined_ == op.isUndefined()) {
|
||||
return isUndefined_ ? true : value_ == op.getValue();
|
||||
return isUndefined_ || value_ == op.getValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -51,14 +42,14 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
|
|||
return !(*this == op);
|
||||
}
|
||||
|
||||
bool YGFloatOptional::operator==(const float& val) const {
|
||||
bool YGFloatOptional::operator==(float val) const {
|
||||
if (YGFloatIsUndefined(val) == isUndefined_) {
|
||||
return isUndefined_ ? true : val == value_;
|
||||
return isUndefined_ || val == value_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool YGFloatOptional::operator!=(const float& val) const {
|
||||
bool YGFloatOptional::operator!=(float val) const {
|
||||
return !(*this == val);
|
||||
}
|
||||
|
||||
|
@ -84,9 +75,9 @@ bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
|
|||
}
|
||||
|
||||
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
|
||||
return *this == op ? true : *this > op;
|
||||
return *this == op || *this > op;
|
||||
}
|
||||
|
||||
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
|
||||
return *this == op ? true : *this < op;
|
||||
return *this == op || *this < op;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
/*
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct YGFloatOptional {
|
||||
|
@ -13,7 +13,7 @@ struct YGFloatOptional {
|
|||
bool isUndefined_;
|
||||
|
||||
public:
|
||||
explicit YGFloatOptional(const float& value);
|
||||
explicit YGFloatOptional(float value);
|
||||
explicit YGFloatOptional();
|
||||
|
||||
// Program will terminate if the value of an undefined is accessed. Please
|
||||
|
@ -22,9 +22,14 @@ struct YGFloatOptional {
|
|||
const float& getValue() const;
|
||||
|
||||
// Sets the value of float optional, and thus isUndefined is assigned false.
|
||||
void setValue(const float& val);
|
||||
void setValue(float val) {
|
||||
value_ = val;
|
||||
isUndefined_ = false;
|
||||
}
|
||||
|
||||
const bool& isUndefined() const;
|
||||
bool isUndefined() const {
|
||||
return isUndefined_;
|
||||
}
|
||||
|
||||
YGFloatOptional operator+(const YGFloatOptional& op);
|
||||
bool operator>(const YGFloatOptional& op) const;
|
||||
|
@ -34,6 +39,6 @@ struct YGFloatOptional {
|
|||
bool operator==(const YGFloatOptional& op) const;
|
||||
bool operator!=(const YGFloatOptional& op) const;
|
||||
|
||||
bool operator==(const float& val) const;
|
||||
bool operator!=(const float& val) const;
|
||||
bool operator==(float val) const;
|
||||
bool operator!=(float val) const;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue