Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lazy-ptr-impl.hxx
Go to the documentation of this file.
1 // file : odb/lazy-ptr-impl.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_PTR_IMPL_HXX
6 #define ODB_LAZY_PTR_IMPL_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <utility> // std::move
11 
12 #include <odb/forward.hxx> // odb::database
13 #include <odb/traits.hxx>
14 
15 #include <odb/details/config.hxx> // ODB_CXX11
16 #include <odb/details/export.hxx>
17 
18 namespace odb
19 {
20  struct LIBODB_EXPORT lazy_ptr_impl_ref
21  {
22  void* id_;
24  void* loader_;
25  void (*free_) (void*);
26  void* (*copy_) (const void*);
27  };
28 
29  class LIBODB_EXPORT lazy_ptr_base
30  {
31  public:
33 
34  ~lazy_ptr_base ();
35  lazy_ptr_base ();
38 
40  operator= (const lazy_ptr_base&);
41 
43  operator= (const lazy_ptr_impl_ref&);
44 
45  // C++11 support.
46  //
47  public:
48 #ifdef ODB_CXX11
50 
52  operator= (lazy_ptr_base&&);
53 #endif
54 
55  public:
56  // Reset both the id and database.
57  //
58  void
59  reset ();
60 
61  // Reset the id.
62  //
63  void
64  reset_id ();
65 
66  void
68 
70  database () const;
71 
73  operator unspecified_bool_type () const
74  {
75  return db_ != 0 ? &lazy_ptr_base::id_ : 0;
76  }
77 
78  operator lazy_ptr_impl_ref ();
79 
80  protected:
81  typedef void (*free_func) (void*);
82  typedef void* (*copy_func) (const void*);
83 
84  // Makes a copy of id.
85  //
86  void
87  reset_ (database_type*,
88  void* loader,
89  const void* id,
90  free_func, copy_func);
91 
92  template <typename T>
93  static void
94  free (void*);
95 
96  template <typename T>
97  static void*
98  copy (const void*);
99 
100  template <typename T, typename DB>
101  static typename object_traits<T>::pointer_type
102  loader (database_type&, const typename object_traits<T>::id_type&);
103 
104  protected:
105  void* id_;
107  void* loader_;
108 
109  private:
110  free_func free_;
111  copy_func copy_;
112  };
113 
114  template <typename T>
116  {
117  public:
118  lazy_ptr_impl ();
119 
120  template <typename DB, typename ID>
121  lazy_ptr_impl (DB&, const ID&);
122 
123  lazy_ptr_impl (const lazy_ptr_impl&);
124 
125  template <typename Y>
127 
129 
131  operator= (const lazy_ptr_impl&);
132 
133  template <typename Y>
136 
139 
140  // C++11 support.
141  //
142  public:
143 #ifdef ODB_CXX11
145 
146  template <typename Y>
148 
151 
152  template <typename Y>
155 #endif
156 
157  public:
158  using lazy_ptr_base::reset;
160 
161  template <typename DB, typename ID>
162  void
163  reset (DB&, const ID&);
164 
165  // Reset the id and set the database to the new value.
166  //
167  template <typename DB>
168  void
169  reset_db (DB&);
170 
171  template <typename ID>
172  void
173  reset_id (const ID&);
174 
175  template <typename O /* = T */>
177  load (bool reset_id);
178 
179  template <typename O /* = T */>
181  object_id () const;
182  };
183 }
184 
185 #include <odb/lazy-ptr-impl.ixx>
186 #include <odb/lazy-ptr-impl.txx>
187 
188 #include <odb/post.hxx>
189 
190 #endif // ODB_LAZY_PTR_IMPL_HXX
Definition: lazy-ptr-impl.hxx:115
object_traits< O >::id_type object_id() const
odb::database database_type
Definition: lazy-ptr-impl.hxx:32
void *lazy_ptr_base::* unspecified_bool_type
Definition: lazy-ptr-impl.hxx:72
database_type * db_
Definition: lazy-ptr-impl.hxx:106
void * id_
Definition: lazy-ptr-impl.hxx:22
Definition: forward.hxx:123
void * id_
Definition: lazy-ptr-impl.hxx:105
database * db_
Definition: lazy-ptr-impl.hxx:23
Definition: lazy-ptr-impl.hxx:29
void * loader_
Definition: lazy-ptr-impl.hxx:24
Definition: lazy-ptr-impl.hxx:20
Definition: database.hxx:38
lazy_ptr_impl & operator=(const lazy_ptr_impl &)
void swap(lazy_ptr< T > &, lazy_ptr< T > &)
void reset_db(DB &)
object_traits< O >::pointer_type load(bool reset_id)
void * loader_
Definition: lazy-ptr-impl.hxx:107
access::object_traits< T >::pointer_type pointer_type
Definition: traits.hxx:116