vbl_smart_ptr.hxx
Go to the documentation of this file.
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>
16 {
17  if (p)
18  p->ref();
19 }
20 
21 template <class T>
23 {
24  if (p)
25  p->unref();
26 }
27 
28 template <class T>
29 struct vbl_smart_ptr_T_as_string { static char const *str() { return "T"; } };
30 
31 template <class T>
32 std::ostream& operator<< (std::ostream& os, vbl_smart_ptr<T> const& r)
33 {
34  return os << "vbl_smart_ptr<"
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_
T * as_pointer() const
These methods all return the raw/dumb pointer.
static void ref(T *p)
static char const * str()
A templated smart pointer class.
Definition: vbl_fwd.h:18
Contains a templated smart pointer class.
static void unref(T *p)
std::ostream & operator<<(std::ostream &os, vbl_smart_ptr< T > const &r)