1 #ifndef __DALI_INTERNAL_TYPE_ABSTRACTION_H__
2 #define __DALI_INTERNAL_TYPE_ABSTRACTION_H__
5 * Copyright (c) 2014 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;
45 static PassingType PassObject( PassingType object ) { return object; }
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>
53 typedef Type HolderType;
54 typedef const Type& PassingType;
55 static PassingType PassObject( PassingType object ) { return object; }
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>
63 typedef OwnerPointer<Type> HolderType;
64 typedef Type* PassingType;
65 static PassingType PassObject( HolderType& object ) { return object.Release(); }
68 // Default for Vector3 and other structures
69 template <class T> struct ParameterType : public ComplexType< T > {};
71 // For message owned parameters
72 template <class T> struct ParameterType< OwnerPointer<T> > : public OwnedType< T > {};
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 > {};
83 #if INT_MAX != LONG_MAX
84 template <> struct ParameterType< long > : public BasicType< long > {};
85 template <> struct ParameterType< unsigned long > : public BasicType< unsigned long > {};
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> > {};
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& > {};
98 } //namespace Internal
102 #endif // __DALI_INTERNAL_TYPE_ABSTRACTION_H__