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 "vtkObjectBase.h"
29 
31 {
32 public:
35 
38 
42 
45 
47 
49  vtkSmartPointerBase& operator=(vtkObjectBase* r);
50  vtkSmartPointerBase& operator=(const vtkSmartPointerBase& 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 
64  void Report(vtkGarbageCollector* collector, const char* desc);
65 
66 protected:
67 
68  // Initialize smart pointer to given object, but do not increment
69  // reference count. The destructor will still decrement the count.
70  // This effectively makes it an auto-ptr.
71  class NoReference {};
73 
74  // Pointer to the actual object.
76 
77 private:
78  // Internal utility methods.
79  void Swap(vtkSmartPointerBase& r);
80  void Register();
81 };
82 
83 //----------------------------------------------------------------------------
84 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
85  inline bool \
86  operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
87  { \
88  return (static_cast<void*>(l.GetPointer()) op \
89  static_cast<void*>(r.GetPointer())); \
90  } \
91  inline bool \
92  operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
93  { \
94  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
95  } \
96  inline bool \
97  operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
98  { \
99  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
100  }
101 
102 
110 
111 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
112 
114 
115 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
116  const vtkSmartPointerBase& p);
118 
119 #endif