Summary: Earlier `YGfloatOptional` was plain struct with no privacy around the variables. This diff adds privacy and also enforces checks when one tries to access value of an undefined `YGFloatOptional` This diff also adds a behaviour in which when a value of an undefined YGFloatOptional is accessed, it will normally terminate(Several cleanup steps are performed). Reviewed By: emilsjolander Differential Revision: D7288555 fbshipit-source-id: f61cc92c8fd0d48d2fc1f4d0e6fcef155f19ff8a
27 lines
723 B
C++
27 lines
723 B
C++
/**
|
|
* 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.
|
|
*/
|
|
|
|
struct YGFloatOptional {
|
|
private:
|
|
float value_;
|
|
bool isUndefined_;
|
|
|
|
public:
|
|
YGFloatOptional(const float& value);
|
|
YGFloatOptional();
|
|
|
|
// Program will terminate if the value of an undefined is accessed. Please
|
|
// make sure to check if the optional is defined before calling this function.
|
|
// To check if float optional is defined, use `isUndefined()`.
|
|
float getValue() const;
|
|
|
|
// Sets the value of float optional, and thus isUndefined is assigned false.
|
|
void setValue(const float& val);
|
|
|
|
bool isUndefined() const;
|
|
};
|