Dali 3D User Interface Engine
type-abstraction.h
Go to the documentation of this file.
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 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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
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 
21 // EXTERNAL INCLUDES
22 #include <climits>
23 
24 // INTERNAL INCLUDES
27 
28 namespace Dali
29 {
30 
31 namespace Internal
32 {
33 
39 // For basic types, they are always pass by copy
40 template <typename Type>
41 struct BasicType
42 {
43  typedef Type HolderType;
44  typedef Type PassingType;
45  static PassingType PassObject( PassingType object ) { return object; }
46 };
47 
48 // For complex types that are copied into the message,
49 // they are passed as const reference when they don't need to be copied
50 template <typename Type>
52 {
53  typedef Type HolderType;
54  typedef const Type& PassingType;
55  static PassingType PassObject( PassingType object ) { return object; }
56 };
57 
58 // For complex types that are owned by the message,
59 // They are passed as raw pointer and hold in an OwnerPointer
60 template <typename Type>
61 struct OwnedType
62 {
64  typedef Type* PassingType;
65  static PassingType PassObject( HolderType& object ) { return object.Release(); }
66 };
67 
68 // Default for Vector3 and other structures
69 template <class T> struct ParameterType : public ComplexType< T > {};
70 
71 // For message owned parameters
72 template <class T> struct ParameterType< OwnerPointer<T> > : public OwnedType< T > {};
73 
74 // Basic types types
75 template <typename T> struct ParameterType< T* > : public BasicType< T* > {};
76 template <typename T> struct ParameterType< const T* > : public BasicType< const T* > {};
77 template <> struct ParameterType< int > : public BasicType< int > {};
78 template <> struct ParameterType< unsigned int > : public BasicType< unsigned int > {};
79 template <> struct ParameterType< float > : public BasicType< float > {};
80 template <> struct ParameterType< bool > : public BasicType< bool > {};
81 template <> struct ParameterType< short int > : public BasicType< short int > {};
82 
83 #if INT_MAX != LONG_MAX
84 template <> struct ParameterType< long > : public BasicType< long > {};
85 template <> struct ParameterType< unsigned long > : public BasicType< unsigned long > {};
86 #endif
87 
88 //TODO: Passing intrusive pointers through messages is potentially dangerous,
89 // this should be checked
90 template <typename T> struct ParameterType< IntrusivePtr<T> >
91 : public BasicType< IntrusivePtr<T> > {};
92 
93 // poorly constructed types, types should not be defined as references
94 // this will trigger a compilation error.
95 template <class U> struct ParameterType< U& > {};
96 template <class U> struct ParameterType< const U& > {};
97 
98 } //namespace Internal
99 
100 } //namespace Dali
101 
102 #endif // __DALI_INTERNAL_TYPE_ABSTRACTION_H__
Dali Docs Home
Read more about Dali