1 #ifndef __DALI_INTERNAL_TYPE_ABSTRACTION_H__
2 #define __DALI_INTERNAL_TYPE_ABSTRACTION_H__
5 * Copyright (c) 2017 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 #include <dali/public-api/object/ref-object.h>
26 #include <dali/internal/common/owner-pointer.h>
35 * Template helpers to strip of const reference and reference to prevent anyone
36 * from passing references as message parameters
39 // For basic types, they are always pass by copy
40 template <typename Type>
43 typedef Type HolderType;
44 typedef Type PassingType;
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>
52 typedef Type HolderType;
53 typedef const Type& PassingType;
56 // For complex types that are owned by the message,
57 // They are passed and hold in an OwnerPointer
58 template <typename Type>
61 typedef OwnerPointer<Type> HolderType;
62 typedef OwnerPointer<Type>& PassingType;
66 // Default for Vector3 and other structures
67 template <class T> struct ParameterType : public ComplexType< T > {};
69 // For message owned parameters
70 template <class T> struct ParameterType< OwnerPointer<T> > : public OwnedType< T > {};
73 template <typename T> struct ParameterType< T* > : public BasicType< T* > {};
74 template <typename T> struct ParameterType< const T* > : public BasicType< const T* > {};
75 template <> struct ParameterType< int > : public BasicType< int > {};
76 template <> struct ParameterType< unsigned int > : public BasicType< unsigned int > {};
77 template <> struct ParameterType< float > : public BasicType< float > {};
78 template <> struct ParameterType< bool > : public BasicType< bool > {};
79 template <> struct ParameterType< short int > : public BasicType< short int > {};
81 #if INT_MAX != LONG_MAX
82 template <> struct ParameterType< long > : public BasicType< long > {};
83 template <> struct ParameterType< unsigned long > : public BasicType< unsigned long > {};
86 //TODO: Passing intrusive pointers through messages is potentially dangerous,
87 // this should be checked
88 template <typename T> struct ParameterType< IntrusivePtr<T> >
89 : public BasicType< IntrusivePtr<T> > {};
91 // poorly constructed types, types should not be defined as references
92 // this will trigger a compilation error.
93 template <class U> struct ParameterType< U& > {};
94 template <class U> struct ParameterType< const U& > {};
96 } //namespace Internal
100 #endif // __DALI_INTERNAL_TYPE_ABSTRACTION_H__