17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_SQL_LIST_H
21
#define DRIZZLED_SQL_LIST_H
20
#ifndef INCLUDES_DRIZZLE_SQL_LIST_H
21
#define INCLUDES_DRIZZLE_SQL_LIST_H
24
#ifdef USE_PRAGMA_INTERFACE
25
#pragma interface /* gcc class implementation */
26
29
#include <algorithm>
27
#include <drizzled/memory/sql_alloc.h>
28
#include <drizzled/visibility.h>
32
typedef struct st_sql_list
31
/** Struct to handle simple linked lists. */
32
typedef struct st_sql_list {
35
34
unsigned char *first;
36
35
unsigned char **next;
37
st_sql_list() {} /* Remove gcc warning */
73
/* mysql standard class memory allocator */
77
static void *operator new(size_t size) throw ()
79
return sql_alloc(size);
81
static void *operator new[](size_t size)
83
return sql_alloc(size);
85
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
86
{ return alloc_root(mem_root, size); }
87
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
88
{ return alloc_root(mem_root, size); }
89
static void operator delete(void *ptr __attribute__((unused)),
90
size_t size __attribute__((unused)))
92
static void operator delete(void *ptr __attribute__((unused)),
93
MEM_ROOT *mem_root __attribute__((unused)))
94
{ /* never called */ }
95
static void operator delete[](void *ptr __attribute__((unused)),
96
MEM_ROOT *mem_root __attribute__((unused)))
97
{ /* never called */ }
98
static void operator delete[](void *ptr __attribute__((unused)),
99
size_t size __attribute__((unused)))
100
{ TRASH(ptr, size); }
103
inline Sql_alloc() :dummy(0) {}
104
inline ~Sql_alloc() {}
106
inline Sql_alloc() {}
107
inline ~Sql_alloc() {}
74
114
Basic single linked list
75
115
Used for item and item_buffs.
122
162
relies on this behaviour. This logic is quite tricky: please do not use
123
163
it in any new code.
125
inline base_list(const base_list &tmp) :memory::SqlAlloc()
165
inline base_list(const base_list &tmp) :Sql_alloc()
127
167
elements= tmp.elements;
128
168
first= tmp.first;
129
169
last= elements ? tmp.last : &first;
131
inline base_list(bool) { }
172
Construct a deep copy of the argument in memory root mem_root.
173
The elements themselves are copied by pointer. If you also
174
need to copy elements by value, you should employ
175
list_copy_and_replace_each_value after creating a copy.
177
base_list(const base_list &rhs, MEM_ROOT *mem_root);
178
inline base_list(bool error __attribute__((unused))) { }
132
179
inline bool push_back(void *info)
134
181
if (((*last)=new list_node(info, &end_of_list)))
356
422
return el == &list->last_ref()->next;
424
friend class error_list_iterator;
360
template <class T> class List_iterator;
362
427
template <class T> class List :public base_list
365
typedef List_iterator<T> iterator;
367
friend class List_iterator<T>;
369
430
inline List() :base_list() {}
370
431
inline List(const List<T> &tmp) :base_list(tmp) {}
371
inline List(const List<T> &tmp, memory::Root *mem_root) :
432
inline List(const List<T> &tmp, MEM_ROOT *mem_root) :
372
433
base_list(tmp, mem_root) {}
373
434
inline bool push_back(T *a) { return base_list::push_back(a); }
374
inline bool push_back(T *a, memory::Root *mem_root)
435
inline bool push_back(T *a, MEM_ROOT *mem_root)
375
436
{ return base_list::push_back(a, mem_root); }
376
437
inline bool push_front(T *a) { return base_list::push_front(a); }
377
inline T* head() {return static_cast<T*>(base_list::head()); }
378
inline T* pop() {return static_cast<T*>(base_list::pop()); }
438
inline T* head() {return (T*) base_list::head(); }
439
inline T** head_ref() {return (T**) base_list::head_ref(); }
440
inline T* pop() {return (T*) base_list::pop(); }
379
441
inline void concat(List<T> *list) { base_list::concat(list); }
380
442
inline void disjoin(List<T> *list) { base_list::disjoin(list); }
381
443
inline void prepand(List<T> *list) { base_list::prepand(list); }
400
457
template <class T> class List_iterator :public base_list_iterator
403
List_iterator(List<T>& a, list_node** b) : base_list_iterator(a, b) {};
460
List_iterator(List<T> &a) : base_list_iterator(a) {}
461
List_iterator() : base_list_iterator() {}
462
inline void init(List<T> &a) { base_list_iterator::init(a); }
405
463
inline T* operator++(int) { return (T*) base_list_iterator::next(); }
406
464
inline T *replace(T *a) { return (T*) base_list_iterator::replace(a); }
407
465
inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
466
inline void rewind(void) { base_list_iterator::rewind(); }
467
inline void remove() { base_list_iterator::remove(); }
468
inline void after(T *a) { base_list_iterator::after(a); }
408
469
inline T** ref(void) { return (T**) base_list_iterator::ref(); }
473
template <class T> class List_iterator_fast :public base_list_iterator
476
inline T *replace(T *a __attribute__((unused))) { return (T*) 0; }
477
inline T *replace(List<T> &a __attribute__((unused))) { return (T*) 0; }
478
inline void remove(void) { }
479
inline void after(T *a __attribute__((unused))) { }
480
inline T** ref(void) { return (T**) 0; }
483
inline List_iterator_fast(List<T> &a) : base_list_iterator(a) {}
484
inline List_iterator_fast() : base_list_iterator() {}
485
inline void init(List<T> &a) { base_list_iterator::init(a); }
486
inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
487
inline void rewind(void) { base_list_iterator::rewind(); }
488
void sublist(List<T> &list_arg, uint32_t el_arg)
490
base_list_iterator::sublist(list_arg, el_arg);
496
A simple intrusive list which automaticly removes element from list
497
on delete (for THD element)
502
struct ilink **prev,*next;
503
static void *operator new(size_t size)
505
return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
507
static void operator delete(void* ptr_arg,
508
size_t size __attribute__((unused)))
510
free((unsigned char*)ptr_arg);
519
/* Extra tests because element doesn't have to be linked */
520
if (prev) *prev= next;
521
if (next) next->prev=prev;
524
virtual ~ilink() { unlink(); } /*lint -e1740 */
528
/* Needed to be able to have an I_List of char* strings in mysqld.cc. */
530
class i_string: public ilink
534
i_string():ptr(0) { }
535
i_string(const char* s) : ptr(s) {}
538
/* needed for linked list of two strings for replicate-rewrite-db */
539
class i_string_pair: public ilink
544
i_string_pair():key(0),val(0) { }
545
i_string_pair(const char* key_arg, const char* val_arg) :
546
key(key_arg),val(val_arg) {}
550
template <class T> class I_List_iterator;
553
WARNING: copy constructor of this class does not create a usable
554
copy, as its members may point at each other.
560
struct ilink *first,last;
561
inline void empty() { first= &last; last.prev= &first; }
562
base_ilist() { empty(); }
563
inline bool is_empty() { return first == &last; }
564
inline void append(ilink *a)
566
first->prev= &a->next;
567
a->next=first; a->prev= &first; first=a;
569
inline void push_back(ilink *a)
576
inline struct ilink *get()
578
struct ilink *first_link=first;
579
if (first_link == &last)
581
first_link->unlink(); // Unlink from list
584
inline struct ilink *head()
586
return (first != &last) ? first : 0;
588
friend class base_list_iterator;
592
class base_ilist_iterator
595
struct ilink **el,*current;
597
base_ilist_iterator(base_ilist &list_par) :list(&list_par),
598
el(&list_par.first),current(0) {}
601
/* This is coded to allow push_back() while iterating */
603
if (current == &list->last) return 0;
611
class I_List :private base_ilist
614
I_List() :base_ilist() {}
615
inline void empty() { base_ilist::empty(); }
616
inline bool is_empty() { return base_ilist::is_empty(); }
617
inline void append(T* a) { base_ilist::append(a); }
618
inline void push_back(T* a) { base_ilist::push_back(a); }
619
inline T* get() { return (T*) base_ilist::get(); }
620
inline T* head() { return (T*) base_ilist::head(); }
622
friend class I_List_iterator<T>;
627
template <class T> class I_List_iterator :public base_ilist_iterator
630
I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
631
inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
412
635
Make a deep copy of each list element.