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)))
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 list_node* last_node() { return *last; }
231
inline list_node* first_node() { return first;}
232
inline void *head() { return first->info; }
233
inline void **head_ref() { return first != &end_of_list ? &first->info : 0; }
234
inline bool is_empty() { return first == &end_of_list ; }
235
inline list_node *last_ref() { return &end_of_list; }
230
bool is_empty() { return first == &end_of_list ; }
236
231
friend class base_list_iterator;
238
233
#ifdef LIST_EXTRA_DEBUG
333
321
*new_list.last=current->next;
334
322
current->info=new_list.first->info;
335
323
current->next=new_list.first->next;
336
if ((list->last == ¤t->next) && (new_list.elements > 1))
337
list->last= new_list.last;
324
if (list->last == ¤t->next && new_list.elements > 1)
325
list->last= new_list.last;
338
326
list->elements+=new_list.elements-1;
340
328
return ret_value; // return old element
342
inline void remove(void) // Remove current
330
void remove() // Remove current
344
332
list->remove(prev);
351
339
current=current->next;
352
340
el= ¤t->next;
354
inline void **ref(void) // Get reference pointer
356
return ¤t->info;
358
inline bool is_last(void)
360
return el == &list->last_ref()->next;
364
344
template <class T> class List_iterator;
366
template <class T> class List :public base_list
346
template <class T> class List : public base_list
369
349
typedef List_iterator<T> iterator;
371
351
friend class List_iterator<T>;
373
inline List() :base_list() {}
374
inline List(const List<T> &tmp) :base_list(tmp) {}
375
inline List(const List<T> &tmp, memory::Root *mem_root) :
376
base_list(tmp, mem_root) {}
377
inline bool push_back(T *a) { return base_list::push_back(a); }
378
inline bool push_back(T *a, memory::Root *mem_root)
379
{ return base_list::push_back(a, mem_root); }
380
inline bool push_front(T *a) { return base_list::push_front(a); }
381
inline T* head() {return static_cast<T*>(base_list::head()); }
382
inline T* pop() {return static_cast<T*>(base_list::pop()); }
383
inline void concat(List<T> *list) { base_list::concat(list); }
384
inline void disjoin(List<T> *list) { base_list::disjoin(list); }
385
inline void prepand(List<T> *list) { base_list::prepand(list); }
386
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()
388
366
list_node *element,*next;
389
367
for (element=first; element != &end_of_list; element=next)
414
template <class T> class List_iterator :public base_list_iterator
391
template <class T> class List_iterator : public base_list_iterator
417
394
List_iterator(List<T>& a, list_node** b) : base_list_iterator(a, b) {};
418
395
List_iterator() {};
419
inline T *operator++(int) { return (T*) base_list_iterator::next(); }
420
inline T *replace(T *a) { return (T*) base_list_iterator::replace(a); }
421
inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
422
inline 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;
426
Make a deep copy of each list element.
428
@note A template function and not a template method of class List
429
is employed because of explicit template instantiation:
430
in server code there are explicit instantiations of List<T> and
431
an explicit instantiation of a template requires that any method
432
of the instantiated class used in the template can be resolved.
433
Evidently not all template arguments have clone() method with
436
@return You must query the error state in Session for out-of-memory
437
situation after calling this function.
440
template <typename T>
441
void list_copy_and_replace_each_value(List<T> &list, memory::Root *mem_root)
443
/* Make a deep copy of each element */
444
typename List<T>::iterator it(list.begin());
447
it.replace(el->clone(mem_root));
450
407
} /* namespace drizzled */
452
409
#endif /* DRIZZLED_SQL_LIST_H */