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.
25 typedef const T& ReturnType;
26 static ReturnType Get(const ValueType& v) { return v; }
27 static ValueType Set(const ReturnType v) { return v; }
28 static bool Ok(const ValueType& v) { return true; }
32 struct OptionalTypes<T*>
35 typedef const T* ReturnType;
36 static ReturnType Get(const ValueType v) { return v; }
37 static ValueType Set(const ReturnType v) { return v; }
38 static bool Ok(const ReturnType v) { return NULL != v; }
42 struct OptionalTypes<T&>
45 typedef const T& ReturnType;
46 static ReturnType Get(const ValueType v) { return *v; }
47 static ValueType Set(const ReturnType v) { return &v; }
48 static bool Ok(const ReturnType v) { return true; }
55 typedef void ( OptionalValue::*bool_type )() const;
56 typedef typename OptionalTypes<T>::ReturnType ReturnType;
57 typedef typename OptionalTypes<T>::ValueType ValueType;
59 OptionalValue(): mOk(false), mValue() {}
60 OptionalValue( T value ): mOk(OptionalTypes<T>::Ok(value)), mValue(OptionalTypes<T>::Set(value)) {}
61 OptionalValue( bool b, T value ): mOk(b), mValue(OptionalTypes<T>::Set(value)) {}
63 ReturnType operator *() const { return OptionalTypes<T>::Get(mValue); }
66 operator bool_type() const {
67 return mOk == true ? &OptionalValue::this_type_does_not_support_comparisons : 0;
73 void this_type_does_not_support_comparisons() const {}
76 template <typename T, typename U>
77 bool operator==( const OptionalValue<T>& lhs, const OptionalValue<U>& rhs )
79 lhs.this_type_does_not_support_comparisons();
83 template <typename T, typename U>
84 bool operator!=( const OptionalValue<T>& lhs, const OptionalValue<U>& rhs )
86 lhs.this_type_does_not_support_comparisons();