Commit 099d7e69 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

Merge from main tree, fix for smart pointer

parent ab54fa77
......@@ -29,16 +29,16 @@ public:
// Description:
// Initialize smart pointer to NULL.
vtkSmartPointer() {}
// Description:
// Initialize smart pointer to given object.
vtkSmartPointer(T* r): vtkSmartPointerBase(r) {}
// Description:
// Initialize smart pointer with a new reference to the same object
// referenced by given smart pointer.
vtkSmartPointer(const vtkSmartPointerBase& r): vtkSmartPointerBase(r) {}
// Description:
// Assign object to reference. This removes any reference to an old
// object.
......@@ -47,7 +47,7 @@ public:
this->vtkSmartPointerBase::operator=(r);
return *this;
}
// Description:
// Assign object to reference. This removes any reference to an old
// object.
......@@ -55,15 +55,22 @@ public:
{
this->vtkSmartPointerBase::operator=(r);
return *this;
}
}
// Description:
// Get the contained pointer.
T* GetPointer() const
{
return static_cast<T*>(this->Object);
}
// Description:
// Get the contained pointer.
operator T* () const
{
return static_cast<T*>(this->Object);
}
// Description:
// Dereference the pointer and return a reference to the contained
// object.
......@@ -71,7 +78,7 @@ public:
{
return *static_cast<T*>(this->Object);
}
// Description:
// Provides normal pointer target member access using operator ->.
T* operator->() const
......@@ -89,4 +96,40 @@ protected:
vtkSmartPointer(T* r, const NoReference& n): vtkSmartPointerBase(r, n) {}
};
#define VTK_SMART_POINTER_DEFINE_OPERATOR(op) \
template <class T> \
inline vtkstd_bool \
operator op (const vtkSmartPointer<T>& l, const vtkSmartPointer<T>& r) \
{ \
return (l.GetPointer() op r.GetPointer()); \
} \
template <class T> \
inline vtkstd_bool operator op (T* l, const vtkSmartPointer<T>& r) \
{ \
return (l op r.GetPointer()); \
} \
template <class T> \
inline vtkstd_bool operator op (const vtkSmartPointer<T>& l, T* r) \
{ \
return (l.GetPointer() op r); \
}
// Description:
// Compare smart pointer values.
VTK_SMART_POINTER_DEFINE_OPERATOR(==)
VTK_SMART_POINTER_DEFINE_OPERATOR(!=)
VTK_SMART_POINTER_DEFINE_OPERATOR(<)
VTK_SMART_POINTER_DEFINE_OPERATOR(<=)
VTK_SMART_POINTER_DEFINE_OPERATOR(>)
VTK_SMART_POINTER_DEFINE_OPERATOR(>=)
#undef VTK_SMART_POINTER_DEFINE_OPERATOR
// Description:
// Streaming operator to print smart pointer like regular pointers.
template <class T>
inline ostream& operator << (ostream& os, const vtkSmartPointer<T>& p)
{
return os << static_cast<const vtkSmartPointerBase&>(p);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment