50
inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
50
void link_in_list(unsigned char *element,unsigned char **next_ptr)
57
inline void save_and_clear(struct st_sql_list *save)
57
void save_and_clear(struct st_sql_list *save)
62
inline void push_front(struct st_sql_list *save)
62
void push_front(struct st_sql_list *save)
64
64
*save->next= first; /* link current list last */
65
65
first= save->first;
66
66
elements+= save->elements;
68
inline void push_back(struct st_sql_list *save)
68
void push_back(struct st_sql_list *save)
115
115
uint32_t elements;
118
inline void clear() { elements=0; first= &end_of_list; last=&first;}
119
inline base_list() { clear(); }
118
void clear() { elements=0; first= &end_of_list; last=&first;}
119
base_list() { clear(); }
121
121
This is a shallow copy constructor that implicitly passes the ownership
122
122
from the source list to the new instance. The old instance is not
126
126
relies on this behaviour. This logic is quite tricky: please do not use
127
127
it in any new code.
129
inline base_list(const base_list &tmp) :memory::SqlAlloc()
129
base_list(const base_list &tmp) :memory::SqlAlloc()
131
131
elements= tmp.elements;
132
132
first= tmp.first;
133
133
last= elements ? tmp.last : &first;
135
inline base_list(bool) { }
136
inline bool push_back(void *info)
136
bool push_back(void *info)
138
138
if (((*last)=new list_node(info, &end_of_list)))
146
inline bool push_back(void *info, memory::Root *mem_root)
146
bool push_back(void *info, memory::Root *mem_root)
148
148
if (((*last)=new (mem_root) list_node(info, &end_of_list)))
224
inline void swap(base_list &rhs)
224
void swap(base_list &rhs)
226
226
std::swap(first, rhs.first);
227
227
std::swap(last, rhs.last);
228
228
std::swap(elements, rhs.elements);
230
inline void **head_ref() { return first != &end_of_list ? &first->info : 0; }
231
inline bool is_empty() { return first == &end_of_list ; }
230
bool is_empty() { return first == &end_of_list ; }
232
231
friend class base_list_iterator;
234
233
#ifdef LIST_EXTRA_DEBUG
329
321
*new_list.last=current->next;
330
322
current->info=new_list.first->info;
331
323
current->next=new_list.first->next;
332
if ((list->last == ¤t->next) && (new_list.elements > 1))
333
list->last= new_list.last;
324
if (list->last == ¤t->next && new_list.elements > 1)
325
list->last= new_list.last;
334
326
list->elements+=new_list.elements-1;
336
328
return ret_value; // return old element
338
inline void remove(void) // Remove current
330
void remove() // Remove current
340
332
list->remove(prev);
347
339
current=current->next;
348
340
el= ¤t->next;
350
inline void **ref(void) // Get reference pointer
352
return ¤t->info;
354
inline bool is_last(void)
356
return el == &end_of_list.next;
360
344
template <class T> class List_iterator;
362
template <class T> class List :public base_list
346
template <class T> class List : public base_list
365
349
typedef List_iterator<T> iterator;
367
351
friend class List_iterator<T>;
370
inline List(const List<T> &tmp) : base_list(tmp) {}
371
inline List(const List<T> &tmp, memory::Root *mem_root) : base_list(tmp, mem_root) {}
372
inline bool push_back(T *a) { return base_list::push_back(a); }
373
inline bool push_back(T *a, memory::Root *mem_root)
374
{ return base_list::push_back(a, mem_root); }
375
inline bool push_front(T *a) { return base_list::push_front(a); }
376
inline T& front() {return *static_cast<T*>(first->info); }
377
inline T* pop() {return static_cast<T*>(base_list::pop()); }
378
inline void concat(List<T> *list) { base_list::concat(list); }
379
inline void disjoin(List<T> *list) { base_list::disjoin(list); }
380
inline void prepand(List<T> *list) { base_list::prepand(list); }
381
void delete_elements(void)
354
List(const List<T> &tmp) : base_list(tmp) {}
355
List(const List<T> &tmp, memory::Root *mem_root) : base_list(tmp, mem_root) {}
356
bool push_back(T *a) { return base_list::push_back(a); }
357
bool push_back(T *a, memory::Root *mem_root) { return base_list::push_back(a, mem_root); }
358
bool push_front(T *a) { return base_list::push_front(a); }
359
T& front() {return *static_cast<T*>(first->info); }
360
T* pop() {return static_cast<T*>(base_list::pop()); }
361
void concat(List<T> *list) { base_list::concat(list); }
362
void disjoin(List<T> *list) { base_list::disjoin(list); }
363
void prepand(List<T> *list) { base_list::prepand(list); }
364
void delete_elements()
383
366
list_node *element,*next;
384
367
for (element=first; element != &end_of_list; element=next)
409
template <class T> class List_iterator :public base_list_iterator
391
template <class T> class List_iterator : public base_list_iterator
412
394
List_iterator(List<T>& a, list_node** b) : base_list_iterator(a, b) {};
413
395
List_iterator() {};
414
T *operator++(int) { return (T*) base_list_iterator::next(); }
415
void replace(T *a) { base_list_iterator::replace(a); }
416
T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
417
T** ref(void) { return (T**) base_list_iterator::ref(); }
396
T *operator++(int) { return (T*) base_list_iterator::next(); }
397
T *replace(T *a) { T* old = (T*) current->info; current->info= a; return old; }
398
void replace(List<T> &a) { base_list_iterator::replace(a); }
399
T** ref() { return (T**) ¤t->info; }
403
return *(T*)current->info;
421
Make a deep copy of each list element.
423
@note A template function and not a template method of class List
424
is employed because of explicit template instantiation:
425
in server code there are explicit instantiations of List<T> and
426
an explicit instantiation of a template requires that any method
427
of the instantiated class used in the template can be resolved.
428
Evidently not all template arguments have clone() method with
431
@return You must query the error state in Session for out-of-memory
432
situation after calling this function.
435
template <typename T>
436
void list_copy_and_replace_each_value(List<T> &list, memory::Root *mem_root)
438
/* Make a deep copy of each element */
439
typename List<T>::iterator it(list.begin());
442
it.replace(el->clone(mem_root));
445
407
} /* namespace drizzled */
447
409
#endif /* DRIZZLED_SQL_LIST_H */