Common ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
container-traits.hxx
Go to the documentation of this file.
1 // file : odb/container-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_CONTAINER_TRAITS_HXX
6 #define ODB_CONTAINER_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/forward.hxx>
11 #include <odb/details/config.hxx> // ODB_CXX11
12 
13 namespace odb
14 {
15  // Keep this enum synchronized with the one in odb/odb/context.hxx.
16  //
18  {
24  };
25 
26  //
27  // Container API provided by the generated code.
28  //
29 
30  // Ordered containers.
31  //
32  template <typename I, typename V>
34  {
35  typedef I index_type;
36  typedef V value_type;
37 
38  // Return true if the order is preserved in the database. If the
39  // order is not preserved, then the index argument in the functions
40  // below is not used.
41  //
42  bool
43  ordered () const
44  {
45  return ordered_;
46  }
47 
48  void
49  insert (I index, const V& value) const
50  {
51  insert_ (index, value, data_);
52  }
53 
54  bool
55  select (I& next_index, V& next_value) const
56  {
57  return select_ (next_index, next_value, data_);
58  }
59 
60  void
61  delete_ () const
62  {
63  delete__ (data_);
64  }
65 
66  // Implementation details.
67  //
68  public:
69  ordered_functions (void* data): data_ (data) {}
70 
71  public:
72  void* data_;
73  bool ordered_;
74 
75  void (*insert_) (I, const V&, void*);
76  bool (*select_) (I&, V&, void*);
77  void (*delete__) (void*);
78  };
79 
80  template <typename I, typename V>
82  {
83  typedef I index_type;
84  typedef V value_type;
85 
86  void
87  insert (I index, const V& value) const
88  {
89  insert_ (index, value, data_);
90  }
91 
92  bool
93  select (I& next_index, V& next_value) const
94  {
95  return select_ (next_index, next_value, data_);
96  }
97 
98  void
99  update (I index, const V& value) const
100  {
101  update_ (index, value, data_);
102  }
103 
104  // Delete all the elements starting with the specified index. To
105  // delete everything, pass 0.
106  //
107  void
108  delete_ (I start_index) const
109  {
110  delete__ (start_index, data_);
111  }
112 
113  // Implementation details.
114  //
115  public:
116  smart_ordered_functions (void* data) : data_ (data) {}
117 
118  public:
119  void* data_;
120 
121  void (*insert_) (I, const V&, void*);
122  bool (*select_) (I&, V&, void*);
123  void (*update_) (I, const V&, void*);
124  void (*delete__) (I, void*);
125  };
126 
127  // Set/multiset containers.
128  //
129  template <typename V>
131  {
132  typedef V value_type;
133 
134  void
135  insert (const V& value) const
136  {
137  insert_ (value, data_);
138  }
139 
140  bool
141  select (V& next_value) const
142  {
143  return select_ (next_value, data_);
144  }
145 
146  void
147  delete_ () const
148  {
149  delete__ (data_);
150  }
151 
152  // Implementation details.
153  //
154  public:
155  set_functions (void* data): data_ (data) {}
156 
157  public:
158  void* data_;
159 
160  void (*insert_) (const V&, void*);
161  bool (*select_) (V&, void*);
162  void (*delete__) (void*);
163  };
164 
165  // Map/multimap containers.
166  //
167  template <typename K, typename V>
169  {
170  typedef K key_type;
171  typedef V value_type;
172 
173  void
174  insert (const K& key, const V& value) const
175  {
176  insert_ (key, value, data_);
177  }
178 
179  bool
180  select (K& next_key, V& next_value) const
181  {
182  return select_ (next_key, next_value, data_);
183  }
184 
185  void
186  delete_ () const
187  {
188  delete__ (data_);
189  }
190 
191  // Implementation details.
192  //
193  public:
194  map_functions (void* data): data_ (data) {}
195 
196  public:
197  void* data_;
198 
199  void (*insert_) (const K&, const V&, void*);
200  bool (*select_) (K&, V&, void*);
201  void (*delete__) (void*);
202  };
203 }
204 
205 #include <odb/post.hxx>
206 
207 #include <odb/std-map-traits.hxx>
208 #include <odb/std-set-traits.hxx>
209 #include <odb/std-list-traits.hxx>
210 #include <odb/std-vector-traits.hxx>
211 
212 #ifdef ODB_CXX11
213 # include <odb/std-array-traits.hxx>
217 #endif
218 
219 #endif // ODB_CONTAINER_TRAITS_HXX
Definition: container-traits.hxx:130
bool(* select_)(I &, V &, void *)
Definition: container-traits.hxx:122
ordered_functions(void *data)
Definition: container-traits.hxx:69
void insert(I index, const V &value) const
Definition: container-traits.hxx:49
void(* delete__)(void *)
Definition: container-traits.hxx:77
void insert(const K &key, const V &value) const
Definition: container-traits.hxx:174
void(* update_)(I, const V &, void *)
Definition: container-traits.hxx:123
void(* insert_)(const K &, const V &, void *)
Definition: container-traits.hxx:199
void delete_() const
Definition: container-traits.hxx:147
bool(* select_)(V &, void *)
Definition: container-traits.hxx:161
Definition: container-traits.hxx:21
K key_type
Definition: container-traits.hxx:170
Definition: container-traits.hxx:168
bool(* select_)(I &, V &, void *)
Definition: container-traits.hxx:76
map_functions(void *data)
Definition: container-traits.hxx:194
Definition: container-traits.hxx:20
bool select(I &next_index, V &next_value) const
Definition: container-traits.hxx:93
I index_type
Definition: container-traits.hxx:35
V value_type
Definition: container-traits.hxx:132
void(* insert_)(I, const V &, void *)
Definition: container-traits.hxx:75
bool select(I &next_index, V &next_value) const
Definition: container-traits.hxx:55
void insert(I index, const V &value) const
Definition: container-traits.hxx:87
void update(I index, const V &value) const
Definition: container-traits.hxx:99
void * data_
Definition: container-traits.hxx:119
void(* insert_)(const V &, void *)
Definition: container-traits.hxx:160
container_kind
Definition: container-traits.hxx:17
bool(* select_)(K &, V &, void *)
Definition: container-traits.hxx:200
void(* delete__)(I, void *)
Definition: container-traits.hxx:124
void(* insert_)(I, const V &, void *)
Definition: container-traits.hxx:121
smart_ordered_functions(void *data)
Definition: container-traits.hxx:116
void(* delete__)(void *)
Definition: container-traits.hxx:162
void * data_
Definition: container-traits.hxx:72
void * data_
Definition: container-traits.hxx:158
void delete_(I start_index) const
Definition: container-traits.hxx:108
void * data_
Definition: container-traits.hxx:197
Definition: container-traits.hxx:81
void delete_() const
Definition: container-traits.hxx:186
Definition: container-traits.hxx:19
Definition: container-traits.hxx:23
set_functions(void *data)
Definition: container-traits.hxx:155
V value_type
Definition: container-traits.hxx:171
bool select(V &next_value) const
Definition: container-traits.hxx:141
V value_type
Definition: container-traits.hxx:84
void delete_() const
Definition: container-traits.hxx:61
V value_type
Definition: container-traits.hxx:36
void(* delete__)(void *)
Definition: container-traits.hxx:201
void insert(const V &value) const
Definition: container-traits.hxx:135
I index_type
Definition: container-traits.hxx:83
bool ordered() const
Definition: container-traits.hxx:43
Definition: container-traits.hxx:33
Definition: container-traits.hxx:22
bool ordered_
Definition: container-traits.hxx:73
bool select(K &next_key, V &next_value) const
Definition: container-traits.hxx:180