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 "YGFloatOptional.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Yoga.h"
|
#include "Yoga.h"
|
||||||
|
|
||||||
YGFloatOptional::YGFloatOptional(const float& value) {
|
YGFloatOptional::YGFloatOptional(float value) {
|
||||||
if (YGFloatIsUndefined(value)) {
|
if (YGFloatIsUndefined(value)) {
|
||||||
isUndefined_ = true;
|
isUndefined_ = true;
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
|
@ -31,18 +31,9 @@ const float& YGFloatOptional::getValue() const {
|
||||||
return value_;
|
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 {
|
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
|
||||||
if (isUndefined_ == op.isUndefined()) {
|
if (isUndefined_ == op.isUndefined()) {
|
||||||
return isUndefined_ ? true : value_ == op.getValue();
|
return isUndefined_ || value_ == op.getValue();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -51,14 +42,14 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
|
||||||
return !(*this == op);
|
return !(*this == op);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator==(const float& val) const {
|
bool YGFloatOptional::operator==(float val) const {
|
||||||
if (YGFloatIsUndefined(val) == isUndefined_) {
|
if (YGFloatIsUndefined(val) == isUndefined_) {
|
||||||
return isUndefined_ ? true : val == value_;
|
return isUndefined_ || val == value_;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator!=(const float& val) const {
|
bool YGFloatOptional::operator!=(float val) const {
|
||||||
return !(*this == val);
|
return !(*this == val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +75,9 @@ bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
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
|
#pragma once
|
||||||
|
|
||||||
struct YGFloatOptional {
|
struct YGFloatOptional {
|
||||||
|
@ -13,7 +13,7 @@ struct YGFloatOptional {
|
||||||
bool isUndefined_;
|
bool isUndefined_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit YGFloatOptional(const float& value);
|
explicit YGFloatOptional(float value);
|
||||||
explicit YGFloatOptional();
|
explicit YGFloatOptional();
|
||||||
|
|
||||||
// Program will terminate if the value of an undefined is accessed. Please
|
// Program will terminate if the value of an undefined is accessed. Please
|
||||||
|
@ -22,9 +22,14 @@ struct YGFloatOptional {
|
||||||
const float& getValue() const;
|
const float& getValue() const;
|
||||||
|
|
||||||
// Sets the value of float optional, and thus isUndefined is assigned false.
|
// 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);
|
YGFloatOptional operator+(const YGFloatOptional& op);
|
||||||
bool operator>(const YGFloatOptional& op) const;
|
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 YGFloatOptional& op) const;
|
bool operator!=(const YGFloatOptional& op) const;
|
||||||
|
|
||||||
bool operator==(const float& val) const;
|
bool operator==(float val) const;
|
||||||
bool operator!=(const float& val) const;
|
bool operator!=(float val) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue