Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tr1/pointer-traits.hxx
Go to the documentation of this file.
1 // file : odb/tr1/pointer-traits.hxx
2 // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
3 // license : GNU GPL v2; see accompanying LICENSE file
4 
5 #ifndef ODB_TR1_POINTER_TRAITS_HXX
6 #define ODB_TR1_POINTER_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/details/config.hxx> // ODB_CXX11
11 
12 // In VC++ std::shared_ptr and std::tr1::shared_ptr is the same class
13 // template. One is just a using-declaration for the other.
14 //
15 #if !(defined(ODB_CXX11) && defined(_MSC_VER))
16 
17 //
18 // This header assumes that the necessary TR1 header has already
19 // been included.
20 //
21 
22 #include <odb/pointer-traits.hxx>
23 #include <odb/details/meta/remove-const.hxx>
24 
25 namespace odb
26 {
27  // Specialization for std::tr1::shared_ptr.
28  //
29  template <typename T>
30  class pointer_traits<std::tr1::shared_ptr<T> >
31  {
32  public:
33  static const pointer_kind kind = pk_shared;
34  static const bool lazy = false;
35 
36  typedef T element_type;
37  typedef std::tr1::shared_ptr<element_type> pointer_type;
38  typedef std::tr1::shared_ptr<const element_type> const_pointer_type;
39  typedef typename odb::details::meta::remove_const<element_type>::result
41  typedef std::tr1::shared_ptr<unrestricted_element_type>
44 
45  static element_type*
46  get_ptr (const pointer_type& p)
47  {
48  return p.get ();
49  }
50 
51  static element_type&
52  get_ref (const pointer_type& p)
53  {
54  return *p;
55  }
56 
57  static bool
59  {
60  return !p;
61  }
62 
63  static unrestricted_pointer_type
65  {
66  return std::tr1::const_pointer_cast<unrestricted_element_type> (p);
67  }
68 
69  template <typename T1>
70  static std::tr1::shared_ptr<T1>
72  {
73  return std::tr1::static_pointer_cast<T1> (p);
74  }
75 
76  template <typename T1>
77  static std::tr1::shared_ptr<T1>
79  {
80  return std::tr1::dynamic_pointer_cast<T1> (p);
81  }
82 
83  public:
84  static void*
85  allocate (std::size_t n)
86  {
87  return operator new (n);
88  }
89 
90  static void
91  free (void* p)
92  {
93  operator delete (p);
94  }
95  };
96 
97  // Specialization for std::tr1::weak_ptr.
98  //
99  template <typename T>
100  class pointer_traits<std::tr1::weak_ptr<T> >
101  {
102  public:
103  static const pointer_kind kind = pk_weak;
104  static const bool lazy = false;
105 
106  typedef T element_type;
107  typedef std::tr1::weak_ptr<element_type> pointer_type;
108  typedef std::tr1::shared_ptr<element_type> strong_pointer_type;
109 
110  static strong_pointer_type
111  lock (const pointer_type& p)
112  {
113  return p.lock ();
114  }
115  };
116 }
117 
118 #endif // !(ODB_CXX11 && _MSC_VER)
119 
120 #include <odb/post.hxx>
121 
122 #endif // ODB_TR1_POINTER_TRAITS_HXX
static std::tr1::shared_ptr< T1 > static_pointer_cast(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:71
static element_type & get_ref(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:52
Definition: pointer-traits.hxx:24
smart_ptr_guard< pointer_type > guard
Definition: tr1/pointer-traits.hxx:43
Definition: pointer-traits.hxx:23
T element_type
Definition: tr1/pointer-traits.hxx:36
static bool null_ptr(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:58
std::tr1::shared_ptr< element_type > strong_pointer_type
Definition: tr1/pointer-traits.hxx:108
static void * allocate(std::size_t n)
Definition: tr1/pointer-traits.hxx:85
std::tr1::shared_ptr< unrestricted_element_type > unrestricted_pointer_type
Definition: tr1/pointer-traits.hxx:42
Definition: pointer-traits.hxx:28
static std::tr1::shared_ptr< T1 > dynamic_pointer_cast(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:78
std::tr1::shared_ptr< element_type > pointer_type
Definition: tr1/pointer-traits.hxx:37
static strong_pointer_type lock(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:111
odb::details::meta::remove_const< element_type >::result unrestricted_element_type
Definition: tr1/pointer-traits.hxx:40
Definition: pointer-traits.hxx:59
std::tr1::shared_ptr< const element_type > const_pointer_type
Definition: tr1/pointer-traits.hxx:38
static unrestricted_pointer_type const_pointer_cast(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:64
T element_type
Definition: tr1/pointer-traits.hxx:106
static void free(void *p)
Definition: tr1/pointer-traits.hxx:91
static element_type * get_ptr(const pointer_type &p)
Definition: tr1/pointer-traits.hxx:46
std::tr1::weak_ptr< element_type > pointer_type
Definition: tr1/pointer-traits.hxx:107
pointer_kind
Definition: pointer-traits.hxx:19