Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lazy-pointer-traits.hxx
Go to the documentation of this file.
1 // file : odb/lazy-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_LAZY_POINTER_TRAITS_HXX
6 #define ODB_LAZY_POINTER_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/pointer-traits.hxx>
11 #include <odb/lazy-ptr.hxx>
12 #include <odb/details/config.hxx> // ODB_CXX11
13 
14 namespace odb
15 {
16  template <typename T>
18  {
19  public:
20  static const pointer_kind kind = pk_raw;
21  static const bool lazy = true;
22 
23  typedef T element_type;
26 
27  static bool
29  {
30  return !p;
31  }
32 
33  template <class O /* = T */>
34  static typename object_traits<O>::id_type
36  {
37  return p.template object_id<O> ();
38  }
39  };
40 
41  template <typename T>
43  {
44  public:
45  static const pointer_kind kind = pk_unique;
46  static const bool lazy = true;
47 
48  typedef T element_type;
50  typedef std::auto_ptr<element_type> eager_pointer_type;
51 
52  static bool
54  {
55  return !p;
56  }
57 
58  template <class O /* = T */>
59  static typename object_traits<O>::id_type
61  {
62  return p.template object_id<O> ();
63  }
64  };
65 
66 #ifdef ODB_CXX11
67  template <typename T, typename D>
68  class pointer_traits<lazy_unique_ptr<T, D>>
69  {
70  public:
71  static const pointer_kind kind = pk_unique;
72  static const bool lazy = true;
73 
74  typedef T element_type;
75  typedef lazy_unique_ptr<element_type, D> pointer_type;
76  typedef std::unique_ptr<element_type, D> eager_pointer_type;
77 
78  static bool
79  null_ptr (const pointer_type& p)
80  {
81  return !p;
82  }
83 
84  template <class O /* = T */>
85  static typename object_traits<O>::id_type
86  object_id (const pointer_type& p)
87  {
88  return p.template object_id<O> ();
89  }
90  };
91 
92  template <typename T>
93  class pointer_traits<lazy_shared_ptr<T>>
94  {
95  public:
96  static const pointer_kind kind = pk_shared;
97  static const bool lazy = true;
98 
99  typedef T element_type;
100  typedef lazy_shared_ptr<element_type> pointer_type;
101  typedef std::shared_ptr<element_type> eager_pointer_type;
102 
103  static bool
104  null_ptr (const pointer_type& p)
105  {
106  return !p;
107  }
108 
109  template <class O /* = T */>
110  static typename object_traits<O>::id_type
111  object_id (const pointer_type& p)
112  {
113  return p.template object_id<O> ();
114  }
115  };
116 
117  template <typename T>
118  class pointer_traits<lazy_weak_ptr<T>>
119  {
120  public:
121  static const pointer_kind kind = pk_weak;
122  static const bool lazy = true;
123 
124  typedef T element_type;
125  typedef lazy_weak_ptr<element_type> pointer_type;
126  typedef lazy_shared_ptr<element_type> strong_pointer_type;
127  typedef std::weak_ptr<element_type> eager_pointer_type;
128 
129  static strong_pointer_type
130  lock (const pointer_type& p)
131  {
132  return p.lock ();
133  }
134  };
135 #endif // ODB_CXX11
136 }
137 
138 #include <odb/post.hxx>
139 
140 #endif // ODB_LAZY_POINTER_TRAITS_HXX
Definition: lazy-ptr.hxx:23
Definition: pointer-traits.hxx:24
Definition: pointer-traits.hxx:23
static bool null_ptr(const pointer_type &p)
Definition: lazy-pointer-traits.hxx:28
lazy_ptr< element_type > pointer_type
Definition: lazy-pointer-traits.hxx:24
T element_type
Definition: lazy-pointer-traits.hxx:23
static bool null_ptr(const pointer_type &p)
Definition: lazy-pointer-traits.hxx:53
Definition: pointer-traits.hxx:28
T element_type
Definition: lazy-pointer-traits.hxx:48
Definition: forward.hxx:123
lazy_auto_ptr< element_type > pointer_type
Definition: lazy-pointer-traits.hxx:49
std::auto_ptr< element_type > eager_pointer_type
Definition: lazy-pointer-traits.hxx:50
Definition: lazy-ptr.hxx:129
Definition: pointer-traits.hxx:21
static object_traits< O >::id_type object_id(const pointer_type &p)
Definition: lazy-pointer-traits.hxx:60
element_type * eager_pointer_type
Definition: lazy-pointer-traits.hxx:25
static object_traits< O >::id_type object_id(const pointer_type &p)
Definition: lazy-pointer-traits.hxx:35
Definition: pointer-traits.hxx:22
pointer_kind
Definition: pointer-traits.hxx:19