core/vbl/vbl_smart_ptr.txx
Go to the documentation of this file.
00001 // This is core/vbl/vbl_smart_ptr.txx
00002 #ifndef vbl_smart_ptr_txx_
00003 #define vbl_smart_ptr_txx_
00004 
00005 #include "vbl_smart_ptr.h"
00006 #include <vcl_iostream.h>
00007 
00008 // Template definitions for ref() and unref().
00009 // The client can specialize them between including this file and
00010 // calling the instantiation macros.
00011 template <class T>
00012 void vbl_smart_ptr<T>::ref(T *p)
00013 {
00014   if (p)
00015     p->ref();
00016 }
00017 
00018 template <class T>
00019 void vbl_smart_ptr<T>::unref(T *p)
00020 {
00021   if (p)
00022     p->unref();
00023 }
00024 
00025 template <class T>
00026 struct vbl_smart_ptr_T_as_string { static char const *str() { return "T"; } };
00027 
00028 template <class T>
00029 vcl_ostream& operator<< (vcl_ostream& os, vbl_smart_ptr<T> const& r)
00030 {
00031   return os << "vbl_smart_ptr<"
00032             << vbl_smart_ptr_T_as_string<T>::str()
00033             << ">(" << (void*) r.as_pointer() << ')';
00034 }
00035 
00036 //--------------------------------------------------------------------------------
00037 
00038 #undef  VBL_SMART_PTR_INSTANTIATE
00039 #define VBL_SMART_PTR_INSTANTIATE(T) \
00040 template class vbl_smart_ptr<T >; \
00041 VCL_DEFINE_SPECIALIZATION struct vbl_smart_ptr_T_as_string<T > \
00042 { static char const *str() { return #T; } }; \
00043 template vcl_ostream& operator<< (vcl_ostream&, vbl_smart_ptr<T > const&)
00044 
00045 #endif // vbl_smart_ptr_txx_