Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
no-op-cache-traits.hxx
Go to the documentation of this file.
1 // file : odb/no-op-cache-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_NO_OP_CACHE_TRAITS_HXX
6 #define ODB_NO_OP_CACHE_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/traits.hxx>
11 #include <odb/forward.hxx>
12 #include <odb/pointer-traits.hxx>
13 
14 namespace odb
15 {
16  // pointer_cache_type
17  //
18  // Used to convert an object pointer to the canonical form (non-const),
19  // suitable for insertion into the cache.
20  //
21  template <typename P,
22  typename E = typename pointer_traits<P>::element_type,
23  typename O = typename object_traits<E>::object_type,
24  pointer_kind pk = pointer_traits<P>::kind>
26  {
28 
29  static pointer_type
30  convert (const P& p)
31  {
33  }
34  };
35 
36  template <typename P, typename T, pointer_kind pk>
37  struct pointer_cache_type<P, T, T, pk>
38  {
39  // If element_type and object_type are the same, then it is already
40  // the canonical pointer.
41  //
42  static const P&
43  convert (const P& p) {return p;}
44  };
45 
46  template <typename P, typename E, typename O>
47  struct pointer_cache_type<P, E, O, pk_unique>
48  {
49  // If the pointer is unique, then casting it can transfer ownership.
50  // In this case we return NULL void*, which will be ignored down the
51  // chain.
52  //
53  static void*
54  convert (const P&) {return 0;}
55  };
56 
57  template <typename P, typename T>
58  struct pointer_cache_type<P, T, T, pk_unique>
59  {
60  static void*
61  convert (const P&) {return 0;}
62  };
63 
64  // reference_cache_type
65  //
66  // Used to convert an object reference to the canonical form (non-const),
67  // suitable for insertion into the cache.
68  //
69  template <typename T,
70  typename O = typename object_traits<T>::object_type>
72  {
73  static O&
74  convert (T& r)
75  {
76  return const_cast<O&> (r);
77  }
78  };
79 
80  template <typename T>
81  struct reference_cache_type<T, T>
82  {
83  // If the types are the same, then it is already the canonical form.
84  //
85  static T&
86  convert (T& r) {return r;}
87  };
88 
89  // pointer_cache_traits
90  //
91  // Caching traits for objects passed by pointer. P should be the canonical
92  // pointer (non-const).
93  //
94  template <typename P>
95  struct no_op_pointer_cache_traits
96  {
97  typedef P pointer_type;
100  struct position_type {};
101 
103  {
106 
108  position () const {return position_type ();}
109 
110  void
111  release () {}
112 
113  void
114  reset (const position_type&) {}
115  };
116 
117  // Cache management.
118  //
119  static position_type
121  {
122  return position_type ();
123  }
124 
125  static position_type
126  insert (odb::database&, const pointer_type&) {return position_type ();}
127 
128  // Special signature for unique pointers.
129  //
130  static position_type
131  insert (odb::database&, void*) {return position_type ();}
132 
133  static pointer_type
134  find (odb::database&, const id_type&) {return pointer_type ();}
135 
136  static void
137  erase (const position_type&) {}
138 
139  // Notifications.
140  //
141  static void
142  persist (const position_type&) {}
143 
144  static void
145  load (const position_type&) {}
146 
147  static void
149 
150  static void
152  };
153 
154  template <typename P>
155  struct no_id_pointer_cache_traits
156  {
157  typedef P pointer_type;
158  struct position_type {};
159 
160  static position_type
162 
163  // Special signature for unique pointers.
164  //
165  static position_type
166  insert (odb::database&, void*) {return position_type ();}
167 
168  static void
169  persist (const position_type&) {}
170 
171  static void
172  load (const position_type&) {}
173  };
174 
175  // reference_cache_traits
176  //
177  // Caching traits for objects passed by reference. T should be the
178  // canonical object type (non-const).
179  //
180  template <typename T>
181  struct no_op_reference_cache_traits
182  {
183  typedef T object_type;
185  struct position_type {};
186 
188  {
191 
193  position () const {return position_type ();}
194 
195  void
196  release () {}
197 
198  void
199  reset () {}
200  };
201 
202  static position_type
204  {
205  return position_type ();
206  }
207 
208  static position_type
210 
211  static void
212  persist (const position_type&) {}
213 
214  static void
215  load (const position_type&) {}
216  };
217 
218  template <typename T>
219  struct no_id_reference_cache_traits
220  {
221  typedef T object_type;
222  struct position_type {};
223 
224  static position_type
226 
227  static void
228  persist (const position_type&) {}
229 
230  static void
231  load (const position_type&) {}
232  };
233 }
234 
235 #include <odb/post.hxx>
236 
237 #endif // ODB_NO_OP_CACHE_TRAITS_HXX
Definition: no-op-cache-traits.hxx:222
Definition: no-op-cache-traits.hxx:25
insert_guard(const position_type &)
Definition: no-op-cache-traits.hxx:190
static const P & convert(const P &p)
Definition: no-op-cache-traits.hxx:43
static pointer_type find(odb::database &, const id_type &)
Definition: no-op-cache-traits.hxx:134
pointer_traits< pointer_type >::element_type object_type
Definition: no-op-cache-traits.hxx:98
static position_type insert(odb::database &, const id_type &, const pointer_type &)
Definition: no-op-cache-traits.hxx:120
static void load(const position_type &)
Definition: no-op-cache-traits.hxx:231
T object_type
Definition: no-op-cache-traits.hxx:221
static position_type insert(odb::database &, const id_type &, object_type &)
Definition: no-op-cache-traits.hxx:203
static void persist(const position_type &)
Definition: no-op-cache-traits.hxx:142
object_traits< object_type >::id_type id_type
Definition: no-op-cache-traits.hxx:184
static void persist(const position_type &)
Definition: no-op-cache-traits.hxx:169
void reset(const position_type &)
Definition: no-op-cache-traits.hxx:114
static void load(const position_type &)
Definition: no-op-cache-traits.hxx:172
static pointer_type convert(const P &p)
Definition: no-op-cache-traits.hxx:30
insert_guard()
Definition: no-op-cache-traits.hxx:189
static void erase(odb::database &, const id_type &)
Definition: no-op-cache-traits.hxx:151
P pointer_type
Definition: no-op-cache-traits.hxx:157
Definition: pointer-traits.hxx:28
insert_guard()
Definition: no-op-cache-traits.hxx:104
static T & convert(T &r)
Definition: no-op-cache-traits.hxx:86
position_type position() const
Definition: no-op-cache-traits.hxx:108
Definition: forward.hxx:123
static void persist(const position_type &)
Definition: no-op-cache-traits.hxx:212
T object_type
Definition: no-op-cache-traits.hxx:183
static position_type insert(odb::database &, object_type &)
Definition: no-op-cache-traits.hxx:209
Definition: no-op-cache-traits.hxx:187
object_traits< O >::pointer_type pointer_type
Definition: no-op-cache-traits.hxx:27
Definition: no-op-cache-traits.hxx:158
static void persist(const position_type &)
Definition: no-op-cache-traits.hxx:228
P pointer_type
Definition: no-op-cache-traits.hxx:97
static void update(odb::database &, const object_type &)
Definition: no-op-cache-traits.hxx:148
Definition: no-op-cache-traits.hxx:100
insert_guard(const position_type &)
Definition: no-op-cache-traits.hxx:105
static position_type insert(odb::database &, object_type &)
Definition: no-op-cache-traits.hxx:225
static O & convert(T &r)
Definition: no-op-cache-traits.hxx:74
Definition: database.hxx:38
void reset()
Definition: no-op-cache-traits.hxx:199
static void load(const position_type &)
Definition: no-op-cache-traits.hxx:215
static void * convert(const P &)
Definition: no-op-cache-traits.hxx:61
static position_type insert(odb::database &, const pointer_type &)
Definition: no-op-cache-traits.hxx:126
Definition: no-op-cache-traits.hxx:102
static position_type insert(odb::database &, void *)
Definition: no-op-cache-traits.hxx:131
static void load(const position_type &)
Definition: no-op-cache-traits.hxx:145
void release()
Definition: no-op-cache-traits.hxx:111
static position_type insert(odb::database &, const pointer_type &)
Definition: no-op-cache-traits.hxx:161
Definition: no-op-cache-traits.hxx:185
static void erase(const position_type &)
Definition: no-op-cache-traits.hxx:137
Definition: no-op-cache-traits.hxx:71
void release()
Definition: no-op-cache-traits.hxx:196
position_type position() const
Definition: no-op-cache-traits.hxx:193
object_traits< object_type >::id_type id_type
Definition: no-op-cache-traits.hxx:99
access::object_traits< T >::pointer_type pointer_type
Definition: traits.hxx:116
Definition: pointer-traits.hxx:22
static void * convert(const P &)
Definition: no-op-cache-traits.hxx:54
pointer_kind
Definition: pointer-traits.hxx:19
static position_type insert(odb::database &, void *)
Definition: no-op-cache-traits.hxx:166