YGFloatOptional.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2014-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the LICENSE
  5. * file in the root directory of this source tree.
  6. *
  7. */
  8. #pragma once
  9. struct YGFloatOptional {
  10. private:
  11. float value_;
  12. bool isUndefined_;
  13. public:
  14. explicit YGFloatOptional(float value);
  15. explicit YGFloatOptional();
  16. // Program will terminate if the value of an undefined is accessed. Please
  17. // make sure to check if the optional is defined before calling this function.
  18. // To check if float optional is defined, use `isUndefined()`.
  19. const float& getValue() const;
  20. // Sets the value of float optional, and thus isUndefined is assigned false.
  21. void setValue(float val) {
  22. value_ = val;
  23. isUndefined_ = false;
  24. }
  25. bool isUndefined() const {
  26. return isUndefined_;
  27. }
  28. YGFloatOptional operator+(const YGFloatOptional& op);
  29. bool operator>(const YGFloatOptional& op) const;
  30. bool operator<(const YGFloatOptional& op) const;
  31. bool operator>=(const YGFloatOptional& op) const;
  32. bool operator<=(const YGFloatOptional& op) const;
  33. bool operator==(const YGFloatOptional& op) const;
  34. bool operator!=(const YGFloatOptional& op) const;
  35. bool operator==(float val) const;
  36. bool operator!=(float val) const;
  37. };