Apply Visual's transform + borderline properties for partial update
[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) 2021 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
25 #include <dali/internal/common/owner-pointer.h>
26 #include <dali/public-api/object/ref-object.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 /**
33  * Template helpers to strip of const reference and reference to prevent anyone
34  * from passing references as message parameters
35  */
36
37 // For basic types, they are always pass by copy
38 template<typename Type>
39 struct BasicType
40 {
41   using HolderType  = Type;
42   using PassingType = Type;
43 };
44
45 // For complex types that are copied into the message,
46 // they are passed as const reference when they don't need to be copied
47 template<typename Type>
48 struct ComplexType
49 {
50   using HolderType  = Type;
51   using PassingType = const Type&;
52 };
53
54 // For complex types that are owned by the message,
55 // They are passed and hold in an OwnerPointer
56 template<typename Type>
57 struct OwnedType
58 {
59   using HolderType  = OwnerPointer<Type>;
60   using PassingType = OwnerPointer<Type>&;
61 };
62
63 // Default for Vector3 and other structures
64 template<class T>
65 struct ParameterType : public ComplexType<T>
66 {
67 };
68
69 // For message owned parameters
70 template<class T>
71 struct ParameterType<OwnerPointer<T> > : public OwnedType<T>
72 {
73 };
74
75 // Basic types types
76 template<typename T>
77 struct ParameterType<T*> : public BasicType<T*>
78 {
79 };
80 template<typename T>
81 struct ParameterType<const T*> : public BasicType<const T*>
82 {
83 };
84 template<>
85 struct ParameterType<int> : public BasicType<int>
86 {
87 };
88 template<>
89 struct ParameterType<unsigned int> : public BasicType<unsigned int>
90 {
91 };
92 template<>
93 struct ParameterType<float> : public BasicType<float>
94 {
95 };
96 template<>
97 struct ParameterType<bool> : public BasicType<bool>
98 {
99 };
100 template<>
101 struct ParameterType<short int> : public BasicType<short int>
102 {
103 };
104
105 #if INT_MAX != LONG_MAX
106 template<>
107 struct ParameterType<long> : public BasicType<long>
108 {
109 };
110 template<>
111 struct ParameterType<unsigned long> : public BasicType<unsigned long>
112 {
113 };
114 #endif
115
116 //TODO: Passing intrusive pointers through messages is potentially dangerous,
117 //      this should be checked
118 template<typename T>
119 struct ParameterType<IntrusivePtr<T> >
120 : public BasicType<IntrusivePtr<T> >
121 {
122 };
123
124 // poorly constructed types, types should not be defined as references
125 // this will trigger a compilation error.
126 template<class U>
127 struct ParameterType<U&>
128 {
129 };
130 template<class U>
131 struct ParameterType<const U&>
132 {
133 };
134
135 } //namespace Internal
136
137 } //namespace Dali
138
139 #endif // DALI_INTERNAL_TYPE_ABSTRACTION_H