[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / common / type-abstraction.h
1 #ifndef __DALI_INTERNAL_TYPE_ABSTRACTION_H__
2 #define __DALI_INTERNAL_TYPE_ABSTRACTION_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // EXTERNAL INCLUDES
21 #include <climits>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/internal/common/owner-pointer.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 /**
34  * Template helpers to strip of const reference and reference to prevent anyone
35  * from passing references as message parameters
36  */
37
38 // For basic types, they are always pass by copy
39 template <typename Type>
40 struct BasicType
41 {
42   typedef Type HolderType;
43   typedef Type PassingType;
44   static PassingType PassObject( PassingType object ) { return object; }
45 };
46
47 // For complex types that are copied into the message,
48 // they are passed as const reference when they don't need to be copied
49 template <typename Type>
50 struct ComplexType
51 {
52   typedef Type HolderType;
53   typedef const Type& PassingType;
54   static PassingType PassObject( PassingType object ) { return object; }
55 };
56
57 // For complex types that are owned by the message,
58 // They are passed as raw pointer and hold in an OwnerPointer
59 template <typename Type>
60 struct OwnedType
61 {
62   typedef OwnerPointer<Type> HolderType;
63   typedef Type* PassingType;
64   static PassingType PassObject( HolderType& object ) { return object.Release(); }
65 };
66
67 // Default for Vector3 and other structures
68 template <class T> struct ParameterType : public ComplexType< T > {};
69
70 // For message owned parameters
71 template <class T> struct ParameterType< OwnerPointer<T> > : public OwnedType< T > {};
72
73 // Basic types types
74 template <typename T> struct ParameterType< T* > : public BasicType< T* > {};
75 template <typename T> struct ParameterType< const T* > : public BasicType< const T* > {};
76 template <> struct ParameterType< int > : public BasicType< int > {};
77 template <> struct ParameterType< unsigned int > : public BasicType< unsigned int > {};
78 template <> struct ParameterType< float > : public BasicType< float > {};
79 template <> struct ParameterType< bool > : public BasicType< bool > {};
80 template <> struct ParameterType< short int > : public BasicType< short int > {};
81
82 #if INT_MAX != LONG_MAX
83 template <> struct ParameterType< long > : public BasicType< long > {};
84 template <> struct ParameterType< unsigned long > : public BasicType< unsigned long > {};
85 #endif
86
87 //TODO: Passing intrusive pointers through messages is potentially dangerous,
88 //      this should be checked
89 template <typename T> struct ParameterType< IntrusivePtr<T> >
90 : public BasicType< IntrusivePtr<T> > {};
91
92 // poorly constructed types, types should not be defined as references
93 // this will trigger a compilation error.
94 template <class U> struct ParameterType< U& > {};
95 template <class U> struct ParameterType< const U& > {};
96
97 } //namespace Internal
98
99 } //namespace Dali
100
101 #endif // __DALI_INTERNAL_TYPE_ABSTRACTION_H__