1 // This is core/vbl/vbl_smart_ptr.hxx
2 #ifndef vbl_smart_ptr_hxx_
3 #define vbl_smart_ptr_hxx_
4 
5 #include <iostream>
6 #include "vbl_smart_ptr.h"
7 #ifdef _MSC_VER
8 #  include <vcl_msvc_warnings.h>
9 #endif
10 
11 // Template definitions for ref() and unref().
12 // The client can specialize them between including this file and
13 // calling the instantiation macros.
14 template <class T>
ref(T * p)15 void vbl_smart_ptr<T>::ref(T *p)
16 {
17   if (p)
18     p->ref();
19 }
20 
21 template <class T>
unref(T * p)22 void vbl_smart_ptr<T>::unref(T *p)
23 {
24   if (p)
25     p->unref();
26 }
27 
28 template <class T>
strvbl_smart_ptr_T_as_string29 struct vbl_smart_ptr_T_as_string { static char const *str() { return "T"; } };
30 
31 template <class T>
operator <<(std::ostream & os,vbl_smart_ptr<T> const & r)32 std::ostream& operator<< (std::ostream& os, vbl_smart_ptr<T> const& r)
33 {
34   return os << "vbl_smart_ptr<"
35             << vbl_smart_ptr_T_as_string<T>::str()
36             << ">(" << (void*) r.as_pointer() << ')';
37 }
38 
39 //--------------------------------------------------------------------------------
40 
41 #undef  VBL_SMART_PTR_INSTANTIATE
42 #define VBL_SMART_PTR_INSTANTIATE(T) \
43 template class vbl_smart_ptr<T >; \
44 template <> struct vbl_smart_ptr_T_as_string<T > \
45 { static char const *str() { return #T; } }; \
46 template std::ostream& operator<< (std::ostream&, vbl_smart_ptr<T > const&)
47 
48 #endif // vbl_smart_ptr_hxx_
49