1 #ifndef __DALI_TOOLKIT_INTERNAL_BUILDER_OPTIONAL__
2 #define __DALI_TOOLKIT_INTERNAL_BUILDER_OPTIONAL__
5 * Copyright (c) 2014 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.
26 typedef const T& ReturnType;
27 static ReturnType Get(const ValueType& v) { return v; }
28 static ValueType Set(const ReturnType v) { return v; }
29 static bool Ok(const ValueType& v) { return true; }
33 struct OptionalTypes<T*>
36 typedef const T* ReturnType;
37 static ReturnType Get(const ValueType v) { return v; }
38 static ValueType Set(const ReturnType v) { return v; }
39 static bool Ok(const ReturnType v) { return NULL != v; }
43 struct OptionalTypes<T&>
46 typedef const T& ReturnType;
47 static ReturnType Get(const ValueType v) { return *v; }
48 static ValueType Set(const ReturnType v) { return &v; }
49 static bool Ok(const ReturnType v) { return true; }
56 typedef void ( OptionalValue::*bool_type )() const;
57 typedef typename OptionalTypes<T>::ReturnType ReturnType;
58 typedef typename OptionalTypes<T>::ValueType ValueType;
60 OptionalValue(): mOk(false), mValue() {}
61 OptionalValue( T value ): mOk(OptionalTypes<T>::Ok(value)), mValue(OptionalTypes<T>::Set(value)) {}
62 OptionalValue( bool b, T value ): mOk(b), mValue(OptionalTypes<T>::Set(value)) {}
64 ReturnType operator *() const { return OptionalTypes<T>::Get(mValue); }
67 operator bool_type() const {
68 return mOk == true ? &OptionalValue::this_type_does_not_support_comparisons : 0;
74 void this_type_does_not_support_comparisons() const {}
77 template <typename T, typename U>
78 bool operator==( const OptionalValue<T>& lhs, const OptionalValue<U>& rhs )
80 lhs.this_type_does_not_support_comparisons();
84 template <typename T, typename U>
85 bool operator!=( const OptionalValue<T>& lhs, const OptionalValue<U>& rhs )
87 lhs.this_type_does_not_support_comparisons();