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 
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 // Need to use vtkstd_bool type because std: :less requires bool return
78 // type from operators. This example should not be used to justify
79 // using bool elsewhere in VTK.
80 
81 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \
82  inline vtkstd_bool \
83  operator op (const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \
84  { \
85  return (static_cast<void*>(l.GetPointer()) op \
86  static_cast<void*>(r.GetPointer())); \
87  } \
88  inline vtkstd_bool \
89  operator op (vtkObjectBase* l, const vtkWeakPointerBase& r) \
90  { \
91  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
92  } \
93  inline vtkstd_bool \
94  operator op (const vtkWeakPointerBase& l, vtkObjectBase* r) \
95  { \
96  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
97  }
98 
99 
107 
108 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR
109 
111 
112 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
113  const vtkWeakPointerBase& p);
115 
116 #endif
vtkObjectBase * Object
vtkObjectBase * GetPointer() const
Non-templated superclass for vtkWeakPointer.
#define VTK_COMMON_EXPORT
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
#define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op)
VTK_COMMON_EXPORT ostream & operator<<(ostream &os, const vtkWeakPointerBase &p)