vil_smart_ptr.hxx
Go to the documentation of this file.
1 // This is core/vil/vil_smart_ptr.hxx
2 #ifndef vil_smart_ptr_hxx_
3 #define vil_smart_ptr_hxx_
4 
5 #include <iostream>
6 #include "vil_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 vil_smart_ptr_T_as_string { static char const *str() { return "T"; } };
30 
31 template <class T>
32 std::ostream& operator<< (std::ostream& os, vil_smart_ptr<T> const& r)
33 {
34  return os << "vil_smart_ptr<"
36  << ">(" << static_cast<const void*>( r.as_pointer()) << ')';
37 }
38 
39 //------------------------------------------------------------------------------
40 
41 #undef VIL_SMART_PTR_INSTANTIATE
42 #define VIL_SMART_PTR_INSTANTIATE(T,...) \
43 template class __VA_ARGS__ vil_smart_ptr<T >; \
44 template <> struct __VA_ARGS__ vil_smart_ptr_T_as_string<T > \
45 { static char const *str() { return #T; } }; \
46 template __VA_ARGS__ std::ostream& operator<< (std::ostream&, vil_smart_ptr<T > const&)
47 
48 #endif // vil_smart_ptr_hxx_
static void ref(T *p)
A templated smart pointer class.
Definition: vil_fwd.h:16
std::ostream & operator<<(std::ostream &os, vil_smart_ptr< T > const &r)
T * as_pointer() const
These methods all return the raw/dumb pointer.
Contains a templated smart pointer class.
static void unref(T *p)
static char const * str()