1 #ifndef DALI_TOOLKIT_INTERNAL_BUILDER_OPTIONAL_H
2 #define DALI_TOOLKIT_INTERNAL_BUILDER_OPTIONAL_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 typedef const T& ReturnType;
26 static ReturnType Get(const ValueType& v)
30 static ValueType Set(const ReturnType v)
34 static bool Ok(const ValueType& v)
41 struct OptionalTypes<T*>
44 typedef const T* ReturnType;
45 static ReturnType Get(const ValueType v)
49 static ValueType Set(const ReturnType v)
53 static bool Ok(const ReturnType v)
60 struct OptionalTypes<T&>
63 typedef const T& ReturnType;
64 static ReturnType Get(const ValueType v)
68 static ValueType Set(const ReturnType v)
72 static bool Ok(const ReturnType v)
82 typedef void (OptionalValue::*bool_type)() const;
83 typedef typename OptionalTypes<T>::ReturnType ReturnType;
84 typedef typename OptionalTypes<T>::ValueType ValueType;
91 OptionalValue(T value)
92 : mOk(OptionalTypes<T>::Ok(value)),
93 mValue(OptionalTypes<T>::Set(value))
96 OptionalValue(bool b, T value)
98 mValue(OptionalTypes<T>::Set(value))
102 ReturnType operator*() const
104 return OptionalTypes<T>::Get(mValue);
108 operator bool_type() const
110 return mOk == true ? &OptionalValue::this_type_does_not_support_comparisons : 0;
116 void this_type_does_not_support_comparisons() const
121 template<typename T, typename U>
122 bool operator==(const OptionalValue<T>& lhs, const OptionalValue<U>& rhs)
124 lhs.this_type_does_not_support_comparisons();
128 template<typename T, typename U>
129 bool operator!=(const OptionalValue<T>& lhs, const OptionalValue<U>& rhs)
131 lhs.this_type_does_not_support_comparisons();
135 #endif // DALI_TOOLKIT_INTERNAL_BUILDER_OPTIONAL_H