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 
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 // Need to use vtkstd_bool type because std: :less requires bool return
85 // type from operators. This example should not be used to justify
86 // using bool elsewhere in VTK.
87 
88 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
89  inline vtkstd_bool \
90  operator op (const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
91  { \
92  return (static_cast<void*>(l.GetPointer()) op \
93  static_cast<void*>(r.GetPointer())); \
94  } \
95  inline vtkstd_bool \
96  operator op (vtkObjectBase* l, const vtkSmartPointerBase& r) \
97  { \
98  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
99  } \
100  inline vtkstd_bool \
101  operator op (const vtkSmartPointerBase& l, vtkObjectBase* r) \
102  { \
103  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
104  }
105 
106 
114 
115 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
116 
118 
119 VTK_COMMON_EXPORT ostream& operator << (ostream& os,
120  const vtkSmartPointerBase& p);
122 
123 #endif
#define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op)
Detect and break reference loops.
vtkObjectBase * GetPointer() const
#define VTK_COMMON_EXPORT
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
Non-templated superclass for vtkSmartPointer.
vtkObjectBase * Object
VTK_COMMON_EXPORT ostream & operator<<(ostream &os, const vtkSmartPointerBase &p)