Dali 3D User Interface Engine
weak-handle.h
Go to the documentation of this file.
1 #ifndef __DALI_WEAK_HANDLE_H__
2 #define __DALI_WEAK_HANDLE_H__
3 
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
24 
25 namespace Dali
26 {
27 
36 {
37 
38 public:
39 
44 
50  WeakHandleBase( Handle& handle );
51 
55  ~WeakHandleBase();
56 
62  WeakHandleBase(const WeakHandleBase& handle);
63 
71  WeakHandleBase& operator=( const WeakHandleBase& rhs );
72 
79  bool operator==(const WeakHandleBase& rhs) const;
80 
87  bool operator!=(const WeakHandleBase& rhs) const;
88 
94  Handle GetBaseHandle() const;
95 
99  void Reset();
100 
101 
102 protected:
103 
104  struct Impl;
105  Impl* mImpl;
106 };
107 
108 
112 template < class T >
114 {
115 public:
116 
121  : WeakHandleBase()
122  {
123  }
124 
128  WeakHandle( T& handle )
129  : WeakHandleBase( handle )
130  {
131  }
132 
137 
141  WeakHandle(const WeakHandle& handle)
142  : WeakHandleBase( handle )
143  {
144  }
145 
150  {
152  return *this;
153  }
154 
158  bool operator==(const WeakHandle& rhs) const
159  {
160  return WeakHandleBase::operator==(rhs);
161  }
162 
166  bool operator!=(const WeakHandle& rhs) const
167  {
168  return WeakHandleBase::operator!=(rhs);
169  }
170 
174  T GetHandle() const
175  {
176  Handle handle( GetBaseHandle() );
177  if( handle )
178  {
179  return DownCast< T >( handle );
180  }
181  else
182  {
183  return T();
184  }
185  }
186 };
187 
188 } // namespace Dali
189 
190 #endif // __DALI_WEAK_HANDLE_H__
Dali Docs Home
Read more about Dali