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 Flora License, Version 1.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://floralicense.org/license/
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;
70 template <typename OT>
71 bool operator!=( const OT& rhs )
73 this->this_type_does_not_support_comparisons();
77 template <typename OT>
78 bool operator==( const OT& rhs )
80 this->this_type_does_not_support_comparisons();
87 void this_type_does_not_support_comparisons() const {}
88 // todo operator=() ? use OptionalTypes<T>::Ok(mValue)