core/vil/vil_smart_ptr.txx
Go to the documentation of this file.
00001 // This is core/vil/vil_smart_ptr.txx
00002 #ifndef vil_smart_ptr_txx_
00003 #define vil_smart_ptr_txx_
00004 
00005 #include "vil_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 vil_smart_ptr<T>::ref(T *p)
00013 {
00014   if (p)
00015     p->ref();
00016 }
00017 
00018 template <class T>
00019 void vil_smart_ptr<T>::unref(T *p)
00020 {
00021   if (p)
00022     p->unref();
00023 }
00024 
00025 template <class T>
00026 struct vil_smart_ptr_T_as_string { static char const *str() { return "T"; } };
00027 
00028 template <class T>
00029 vcl_ostream& operator<< (vcl_ostream& os, vil_smart_ptr<T> const& r)
00030 {
00031   return os << "vil_smart_ptr<"
00032             << vil_smart_ptr_T_as_string<T>::str()
00033             << ">(" << static_cast<const void*>( r.as_pointer()) << ')';
00034 }
00035 
00036 //------------------------------------------------------------------------------
00037 
00038 #undef  VIL_SMART_PTR_INSTANTIATE
00039 #define VIL_SMART_PTR_INSTANTIATE(T) \
00040 template class vil_smart_ptr<T >; \
00041 VCL_DEFINE_SPECIALIZATION struct vil_smart_ptr_T_as_string<T > \
00042 { static char const *str() { return #T; } }; \
00043 template vcl_ostream& operator<< (vcl_ostream&, vil_smart_ptr<T > const&)
00044 
00045 #endif // vil_smart_ptr_txx_