VTK
vtkSmartPointerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSmartPointerBase.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 =========================================================================*/
25 #ifndef vtkSmartPointerBase_h
26 #define vtkSmartPointerBase_h
27 
28 #include "vtkCommonCoreModule.h" // For export macro
29 #include "vtkObjectBase.h"
30 
32 {
33 public:
36 
39 
43 
46 
48 
50  vtkSmartPointerBase& operator=(vtkObjectBase* r);
51  vtkSmartPointerBase& operator=(const vtkSmartPointerBase& r);
53 
55 
57  {
58  // Inline implementation so smart pointer comparisons can be fully
59  // inlined.
60  return this->Object;
61  }
63 
65  void Report(vtkGarbageCollector* collector, const char* desc);
66 
67 protected:
68 
69  // Initialize smart pointer to given object, but do not increment
70  // reference count. The destructor will still decrement the count.
71  // This effectively makes it an auto-ptr.
72  class NoReference {};
74 
75  // Pointer to the actual object.
77 
78 private:
79  // Internal utility methods.
80  void Swap(vtkSmartPointerBase& r);
81  void Register();
82 };
83 
84 //----------------------------------------------------------------------------
85 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
86  inline bool \
87  operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
88  { \
89  return (static_cast<void*>(l.GetPointer()) op \
90  static_cast<void*>(r.GetPointer())); \
91  } \
92  inline bool \
93  operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
94  { \
95  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
96  } \
97  inline bool \
98  operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
99  { \
100  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
101  }
102 
103 
111 
112 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
113 
115 
116 VTKCOMMONCORE_EXPORT ostream& operator << (ostream& os,
117  const vtkSmartPointerBase& p);
119 
120 #endif
121 // VTK-HeaderTest-Exclude: vtkSmartPointerBase.h
#define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op)
#define VTKCOMMONCORE_EXPORT
Detect and break reference loops.
vtkObjectBase * GetPointer() const
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
Non-templated superclass for vtkSmartPointer.
vtkObjectBase * Object
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkSmartPointerBase &p)