VTK
vtkWeakPointerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkWeakPointerBase.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
24 #ifndef __vtkWeakPointerBase_h
25 #define __vtkWeakPointerBase_h
26 
27 #include "vtkObjectBase.h"
28 
29 class vtkObjectBaseToWeakPointerBaseFriendship;
30 
32 {
33 public:
35  vtkWeakPointerBase() : Object(0) {};
36 
39 
42 
45 
47 
49  vtkWeakPointerBase& operator=(vtkObjectBase* r);
50  vtkWeakPointerBase& operator=(const vtkWeakPointerBase& r);
52 
54 
55  vtkObjectBase* GetPointer() const
56  {
57  // Inline implementation so smart pointer comparisons can be fully
58  // inlined.
59  return this->Object;
60  }
62 
63 private:
64  friend class vtkObjectBaseToWeakPointerBaseFriendship;
65 
66 protected:
67 
68  // Initialize weak pointer to given object.
69  class NoReference {};
71 
72  // Pointer to the actual object.
74 };
75 
76 //----------------------------------------------------------------------------
77 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \
78  inline bool \
79  operator op (const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \
80  { \
81  return (static_cast<void*>(l.GetPointer()) op \
82  static_cast<void*>(r.GetPointer())); \
83  } \
84  inline bool \
85  operator op (vtkObjectBase* l, const vtkWeakPointerBase& r) \
86  { \
87  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
88  } \
89  inline bool \
90  operator op (const vtkWeakPointerBase& l, vtkObjectBase* r) \
91  { \
92  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
93  }
94 
95 
103 
104 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR
105 
107 
108 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
109  const vtkWeakPointerBase& p);
111 
112 #endif