Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / renderer / system / FUiEffects_RendererSystemSmartPtrDefaultStoragePolicy.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file       FUiEffects_RendererSystemSmartPtrDefaultStoragePolicy.h
20  * @brief      The SmartPtrDefaultStoragePolicy template
21  *
22  */
23
24 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_SYSTEM_SMARTPTR_DEFAULT_STORAGE_POLICY_H_
25 #define _FUI_EFFECTS_INTERNAL_RENDERER_SYSTEM_SMARTPTR_DEFAULT_STORAGE_POLICY_H_
26
27 #include <algorithm>
28
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace System
30 {
31
32 /**
33  *  @brief              SmartPtrDefaultStoragePolicy
34  */
35 template <typename ValueType>
36 class SmartPtrDefaultStoragePolicy
37 {
38 public:
39         typedef ValueType* StoredType;
40         typedef ValueType* InitPointerType;
41         typedef ValueType* PointerType;
42         typedef ValueType& ReferenceType;
43
44         inline SmartPtrDefaultStoragePolicy(void);
45         inline SmartPtrDefaultStoragePolicy(const SmartPtrDefaultStoragePolicy& smartPtrDefaultStoragePolicy);
46         inline SmartPtrDefaultStoragePolicy(const StoredType& pObject);
47
48         template <typename ValueType2>
49         inline SmartPtrDefaultStoragePolicy(const SmartPtrDefaultStoragePolicy<ValueType2>& smartPtrDefaultStoragePolicy);
50
51         PointerType operator->(void) const;
52         ReferenceType operator*(void) const;
53         SmartPtrDefaultStoragePolicy<ValueType>& operator=(const SmartPtrDefaultStoragePolicy<ValueType>& rhs);
54
55         void Swap(SmartPtrDefaultStoragePolicy& smartPtrDefaultStoragePolicy);
56
57         template <typename ValueType1>
58         friend typename SmartPtrDefaultStoragePolicy<ValueType1>::PointerType GetImpl(const SmartPtrDefaultStoragePolicy<ValueType1>& smartPtrDefaultStoragePolicy);
59
60         template <typename ValueType1>
61         friend typename SmartPtrDefaultStoragePolicy<ValueType1>::StoredType& GetImplRef(SmartPtrDefaultStoragePolicy<ValueType1>& smartPtrDefaultStoragePolicy);
62
63         template <typename ValueType1>
64         friend const typename SmartPtrDefaultStoragePolicy<ValueType1>::StoredType& GetImplRef(const SmartPtrDefaultStoragePolicy<ValueType1>& smartPtrDefaultStoragePolicy);
65
66 protected:
67         void Destroy(void);
68
69 private:
70         StoredType __pObject;
71 };
72
73 template <typename ValueType>
74 inline typename SmartPtrDefaultStoragePolicy<ValueType>::PointerType GetImpl(const SmartPtrDefaultStoragePolicy<ValueType>& smartPtrDefaultStoragePolicy);
75
76 template <typename ValueType>
77 inline typename SmartPtrDefaultStoragePolicy<ValueType>::StoredType& GetImplRef(SmartPtrDefaultStoragePolicy<ValueType>& smartPtrDefaultStoragePolicy);
78
79 template <typename ValueType>
80 inline const typename SmartPtrDefaultStoragePolicy<ValueType>::StoredType& GetImplRef(const SmartPtrDefaultStoragePolicy<ValueType>& smartPtrDefaultStoragePolicy);
81
82 template <typename ValueType>
83 SmartPtrDefaultStoragePolicy<ValueType>::SmartPtrDefaultStoragePolicy(void) :
84         __pObject(null)
85 {
86
87 }
88
89 // OwnershipPolicy must init objectPtr
90 template <typename ValueType>
91 SmartPtrDefaultStoragePolicy<ValueType>::SmartPtrDefaultStoragePolicy(const SmartPtrDefaultStoragePolicy& smartPtrDefaultStoragePolicy) :
92         __pObject(null)
93 {
94
95 }
96
97 template <typename ValueType>
98 SmartPtrDefaultStoragePolicy<ValueType>::SmartPtrDefaultStoragePolicy(const StoredType& pObject) :
99         __pObject(pObject)
100 {
101
102 }
103
104 // OwnershipPolicy must init objectPtr
105 template <typename ValueType>
106 template <typename ValueType2>
107 SmartPtrDefaultStoragePolicy<ValueType>::SmartPtrDefaultStoragePolicy(const SmartPtrDefaultStoragePolicy<ValueType2>& smartPtrDefaultStoragePolicy) :
108         __pObject(null)
109 {
110
111 }
112
113 template <typename ValueType>
114 typename SmartPtrDefaultStoragePolicy<ValueType>::PointerType SmartPtrDefaultStoragePolicy<ValueType>::operator->(void) const
115 {
116         return __pObject;
117 }
118
119 template <typename ValueType>
120 typename SmartPtrDefaultStoragePolicy<ValueType>::ReferenceType SmartPtrDefaultStoragePolicy<ValueType>::operator*(void) const
121 {
122         return *__pObject;
123 }
124
125 template <typename ValueType>
126 SmartPtrDefaultStoragePolicy<ValueType>& SmartPtrDefaultStoragePolicy<ValueType>::operator=(const SmartPtrDefaultStoragePolicy<ValueType>& rhs)
127 {
128         if (this != &rhs)
129         {
130                 SmartPtrDefaultStoragePolicy<ValueType> temp(rhs);
131                 temp.Swap(*this);
132         }
133         return *this;
134 }
135
136 template <typename ValueType>
137 void SmartPtrDefaultStoragePolicy<ValueType>::Swap(SmartPtrDefaultStoragePolicy& smartPtrDefaultStoragePolicy)
138 {
139         std::swap(__pObject, smartPtrDefaultStoragePolicy.__pObject);
140 }
141
142 template <typename ValueType>
143 void SmartPtrDefaultStoragePolicy<ValueType>::Destroy(void)
144 {
145         if (__pObject != null)
146         {
147                 delete __pObject;
148         }
149         __pObject = null;
150 }
151
152 template <typename ValueType>
153 typename SmartPtrDefaultStoragePolicy<ValueType>::PointerType GetImpl(const SmartPtrDefaultStoragePolicy<ValueType>& smartPtrDefaultStoragePolicy)
154 {
155         return smartPtrDefaultStoragePolicy.__pObject;
156 }
157
158 template <typename ValueType>
159 typename SmartPtrDefaultStoragePolicy<ValueType>::StoredType& GetImplRef(SmartPtrDefaultStoragePolicy<ValueType>& smartPtrDefaultStoragePolicy)
160 {
161         return smartPtrDefaultStoragePolicy.__pObject;
162 }
163
164 template <typename ValueType>
165 const typename SmartPtrDefaultStoragePolicy<ValueType>::StoredType& GetImplRef(const SmartPtrDefaultStoragePolicy<ValueType>& smartPtrDefaultStoragePolicy)
166 {
167         return smartPtrDefaultStoragePolicy.__pObject;
168 }
169
170 }}}}} //Tizen::Ui::Effects::_Renderer::System
171
172 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_SYSTEM_SMARTPTR_DEFAULT_STORAGE_POLICY_H_