Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
object-result.hxx
Go to the documentation of this file.
1 // file : odb/object-result.hxx
2 // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
3 // license : GNU GPL v2; see accompanying LICENSE file
4 
5 #ifndef ODB_OBJECT_RESULT_HXX
6 #define ODB_OBJECT_RESULT_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <cstddef> // std::ptrdiff_t
11 #include <iterator> // iterator categories
12 
13 #include <odb/forward.hxx>
14 #include <odb/traits.hxx>
15 #include <odb/result.hxx>
16 #include <odb/pointer-traits.hxx>
17 
18 namespace odb
19 {
20  //
21  // object_result_impl
22  //
23  template <typename T>
25 
26  template <typename T>
28 
29  template <typename T>
31 
32  //
33  // object_result_impl_selector
34  //
35  template <typename T,
36  typename ID = typename object_traits<T>::id_type,
37  bool polymorphic = object_traits<T>::polymorphic>
39 
40  template <typename T, typename ID>
41  struct object_result_impl_selector<T, ID, false>
42  {
44  };
45 
46  template <typename T, typename ID>
47  struct object_result_impl_selector<T, ID, true>
48  {
50  };
51 
52  template <typename T>
53  struct object_result_impl_selector<T, void, false>
54  {
56  };
57 
58  //
59  // result_iterator
60  //
61 
62  template <typename T, typename ID, bool polymorphic>
64 
65  template <typename T>
67  T,
68  typename object_traits<T>::id_type,
69  object_traits<T>::polymorphic>
70  {
71  public:
72  typedef T value_type;
74  typedef value_type* pointer;
75  typedef std::ptrdiff_t difference_type;
76  typedef std::input_iterator_tag iterator_category;
77 
78  // T can be const T while object_type is always non-const.
79  //
80  typedef
84 
85  public:
86  explicit
87  result_iterator (typename base_type::result_impl_type* res = 0)
88  : base_type (res)
89  {
90  }
91 
92  // Input iterator requirements.
93  //
94  public:
95  reference
96  operator* () const
97  {
98  return pointer_traits::get_ref (this->res_->current ());
99  }
100 
101  // Our value_type is already a pointer so return it instead of
102  // a pointer to it (operator-> will just have to go one deeper
103  // in the latter case).
104  //
105  pointer
106  operator-> () const
107  {
108  return pointer_traits::get_ptr (this->res_->current ());
109  }
110 
112  operator++ ()
113  {
114  this->res_->next ();
115  return *this;
116  }
117 
119  operator++ (int)
120  {
121  // All non-end iterators for a result object move together.
122  //
123  this->res_->next ();
124  return *this;
125  }
126 
127  public:
128  bool
130  {
131  return (this->res_ ? this->res_->end () : true) ==
132  (j.res_ ? j.res_->end () : true);
133  }
134 
135  private:
136  // Use unrestricted pointer traits since that's what is returned by
137  // result_impl.
138  //
139  typedef
141  typename object_traits<
142  typename base_type::object_type>::pointer_type>
144  };
145 
146  //
147  //
148  template <typename T>
150  {
151  public:
153 
154  // T can be const T while object_type is always non-const.
155  //
157  typedef
160  };
161 }
162 
163 #include <odb/post.hxx>
164 
165 #endif // ODB_OBJECT_RESULT_HXX
bool equal(result_iterator j) const
Definition: object-result.hxx:129
object_result_impl_selector< object_type >::type result_impl_type
Definition: object-result.hxx:159
object_result_iterator< T, typename object_traits< T >::id_type, object_traits< T >::polymorphic > base_type
Definition: object-result.hxx:83
result_iterator(typename base_type::result_impl_type *res=0)
Definition: object-result.hxx:87
object_result_impl< T > type
Definition: object-result.hxx:43
polymorphic_object_result_impl< T > type
Definition: object-result.hxx:49
Definition: object-result.hxx:38
Definition: object-result.hxx:24
value_type & reference
Definition: object-result.hxx:73
Definition: pointer-traits.hxx:28
object_traits< T >::object_type object_type
Definition: object-result.hxx:156
Definition: result.hxx:53
Definition: object-result.hxx:63
Definition: forward.hxx:123
std::ptrdiff_t difference_type
Definition: object-result.hxx:75
access::object_traits< T >::object_type object_type
Definition: traits.hxx:115
value_type * pointer
Definition: object-result.hxx:74
Definition: traits.hxx:79
std::input_iterator_tag iterator_category
Definition: object-result.hxx:76
no_id_object_result_impl< T > type
Definition: object-result.hxx:55
Definition: no-id-object-result.hxx:26
Definition: object-result.hxx:27
access::object_traits< T >::pointer_type pointer_type
Definition: traits.hxx:116
object_traits< T >::pointer_type value_type
Definition: object-result.hxx:152
T value_type
Definition: object-result.hxx:72
Definition: result.hxx:56