qtmetapointer.h
1 //------------------------------------------------------------------------------
2 // qtmetapointer.h
3 //------------------------------------------------------------------------------
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301 USA
18 //------------------------------------------------------------------------------
19 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
20 //------------------------------------------------------------------------------
21 #ifndef __QTMETAPOINTER_H__
22 #define __QTMETAPOINTER_H__
23 
24 #include <Qt>
25 
27 {
28 private:
29  void copy(const QtMetaPointer &copyin)
30  {
31  ptr = copyin.ptr;
32  }
33 
34  void *ptr;
35 
36 public:
37  QtMetaPointer() {}
38  QtMetaPointer(void *ptr)
39  {
40  this->ptr = ptr;
41  }
42 
43  QtMetaPointer(const QtMetaPointer &copyin)
44  {
45  copy(copyin);
46  }
47 
48  QtMetaPointer &operator=(const QtMetaPointer &rhs)
49  {
50  if (this != &rhs)
51  copy(rhs);
52 
53  return *this;
54  }
55 
56  QtMetaPointer &operator=(void *rhs)
57  {
58  this->ptr = rhs;
59  return *this;
60  }
61 
62  ~QtMetaPointer() {}
63 
64  friend bool operator==(const void *fPtr, const QtMetaPointer &ref)
65  {
66  return fPtr == ref.ptr;
67  }
68 
69  void *operator->()
70  {
71  return ptr;
72  }
73 
74  operator void *()
75  {
76  return ptr;
77  }
78  operator const void *() const { return ptr; }
79 };
80 
81 Q_DECLARE_METATYPE(QtMetaPointer)
82 
83 #endif