Rebase of facebook flexbox to yoga
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / third-party / yoga / YGFloatOptional.cpp
1 /**
2  * Copyright (c) 2014-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7
8 #include "YGFloatOptional.h"
9 #include <cstdlib>
10 #include <iostream>
11 #include "Yoga.h"
12
13 YGFloatOptional::YGFloatOptional(const float& value) {
14   if (YGFloatIsUndefined(value)) {
15     isUndefined_ = true;
16     value_ = 0;
17   } else {
18     value_ = value;
19     isUndefined_ = false;
20   }
21 }
22
23 YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {}
24
25 const float& YGFloatOptional::getValue() const {
26   if (isUndefined_) {
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);
30   }
31   return value_;
32 }
33
34 void YGFloatOptional::setValue(const float& val) {
35   value_ = val;
36   isUndefined_ = false;
37 }
38
39 const bool& YGFloatOptional::isUndefined() const {
40   return isUndefined_;
41 }
42
43 bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
44   if (isUndefined_ == op.isUndefined()) {
45     return isUndefined_ ? true : value_ == op.getValue();
46   }
47   return false;
48 }
49
50 bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
51   return !(*this == op);
52 }
53
54 bool YGFloatOptional::operator==(const float& val) const {
55   if (YGFloatIsUndefined(val) == isUndefined_) {
56     return isUndefined_ ? true : val == value_;
57   }
58   return false;
59 }
60
61 bool YGFloatOptional::operator!=(const float& val) const {
62   return !(*this == val);
63 }
64
65 YGFloatOptional YGFloatOptional::operator+(const YGFloatOptional& op) {
66   if (!isUndefined_ && !op.isUndefined_) {
67     return YGFloatOptional(value_ + op.value_);
68   }
69   return YGFloatOptional();
70 }
71
72 bool YGFloatOptional::operator>(const YGFloatOptional& op) const {
73   if (isUndefined_ || op.isUndefined_) {
74     return false;
75   }
76   return value_ > op.value_;
77 }
78
79 bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
80   if (isUndefined_ || op.isUndefined_) {
81     return false;
82   }
83   return value_ < op.value_;
84 }
85
86 bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
87   return *this == op ? true : *this > op;
88 }
89
90 bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
91   return *this == op ? true : *this < op;
92 }