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  {
52  copy(rhs);
53  }
54 
55  return *this;
56  }
57 
58  QtMetaPointer& operator=(void* rhs)
59  {
60  this->ptr = rhs;
61  return *this;
62  }
63 
64  ~QtMetaPointer() {}
65 
66  friend bool operator==(const void* fPtr, const QtMetaPointer& ref)
67  {
68  return (fPtr == ref.ptr);
69  }
70 
71  void* operator->()
72  {
73  return ptr;
74  }
75 
76  operator void* () { return ptr; }
77  operator const void* () const { return ptr; }
78 };
79 
80 Q_DECLARE_METATYPE(QtMetaPointer)
81 
82 #endif