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
27
25
#include <algorithm>
28
#include "drizzled/memory/sql_alloc.h"
33
27
/** Struct to handle simple linked lists. */
34
28
typedef struct st_sql_list {
69
/* mysql standard class memory allocator */
73
static void *operator new(size_t size) throw ()
75
return sql_alloc(size);
77
static void *operator new[](size_t size)
79
return sql_alloc(size);
81
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
82
{ return alloc_root(mem_root, size); }
83
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
84
{ return alloc_root(mem_root, size); }
85
static void operator delete(void *ptr __attribute__((unused)),
86
size_t size __attribute__((unused)))
88
static void operator delete(void *ptr __attribute__((unused)),
89
MEM_ROOT *mem_root __attribute__((unused)))
90
{ /* never called */ }
91
static void operator delete[](void *ptr __attribute__((unused)),
92
MEM_ROOT *mem_root __attribute__((unused)))
93
{ /* never called */ }
94
static void operator delete[](void *ptr __attribute__((unused)),
95
size_t size __attribute__((unused)))
99
inline Sql_alloc() :dummy(0) {}
100
inline ~Sql_alloc() {}
102
inline Sql_alloc() {}
103
inline ~Sql_alloc() {}
76
110
Basic single linked list
77
111
Used for item and item_buffs.
124
158
relies on this behaviour. This logic is quite tricky: please do not use
125
159
it in any new code.
127
inline base_list(const base_list &tmp) :memory::SqlAlloc()
161
inline base_list(const base_list &tmp) :Sql_alloc()
129
163
elements= tmp.elements;
130
164
first= tmp.first;
131
165
last= elements ? tmp.last : &first;
133
inline base_list(bool) { }
168
Construct a deep copy of the argument in memory root mem_root.
169
The elements themselves are copied by pointer. If you also
170
need to copy elements by value, you should employ
171
list_copy_and_replace_each_value after creating a copy.
173
base_list(const base_list &rhs, MEM_ROOT *mem_root);
174
inline base_list(bool error __attribute__((unused))) { }
134
175
inline bool push_back(void *info)
136
177
if (((*last)=new list_node(info, &end_of_list)))
385
426
inline List() :base_list() {}
386
427
inline List(const List<T> &tmp) :base_list(tmp) {}
387
inline List(const List<T> &tmp, memory::Root *mem_root) :
428
inline List(const List<T> &tmp, MEM_ROOT *mem_root) :
388
429
base_list(tmp, mem_root) {}
389
430
inline bool push_back(T *a) { return base_list::push_back(a); }
390
inline bool push_back(T *a, memory::Root *mem_root)
431
inline bool push_back(T *a, MEM_ROOT *mem_root)
391
432
{ return base_list::push_back(a, mem_root); }
392
433
inline bool push_front(T *a) { return base_list::push_front(a); }
393
434
inline T* head() {return (T*) base_list::head(); }
428
469
template <class T> class List_iterator_fast :public base_list_iterator
431
inline T *replace(T *) { return (T*) 0; }
432
inline T *replace(List<T> &) { return (T*) 0; }
472
inline T *replace(T *a __attribute__((unused))) { return (T*) 0; }
473
inline T *replace(List<T> &a __attribute__((unused))) { return (T*) 0; }
433
474
inline void remove(void) { }
434
inline void after(T *) { }
475
inline void after(T *a __attribute__((unused))) { }
435
476
inline T** ref(void) { return (T**) 0; }
492
A simple intrusive list which automaticly removes element from list
493
on delete (for Session element)
498
struct ilink **prev,*next;
499
static void *operator new(size_t size)
501
return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
503
static void operator delete(void* ptr_arg,
504
size_t size __attribute__((unused)))
506
free((unsigned char*)ptr_arg);
515
/* Extra tests because element doesn't have to be linked */
516
if (prev) *prev= next;
517
if (next) next->prev=prev;
520
virtual ~ilink() { unlink(); } /*lint -e1740 */
524
/* Needed to be able to have an I_List of char* strings in mysqld.cc. */
526
class i_string: public ilink
530
i_string():ptr(0) { }
531
i_string(const char* s) : ptr(s) {}
534
/* needed for linked list of two strings for replicate-rewrite-db */
535
class i_string_pair: public ilink
540
i_string_pair():key(0),val(0) { }
541
i_string_pair(const char* key_arg, const char* val_arg) :
542
key(key_arg),val(val_arg) {}
546
template <class T> class I_List_iterator;
549
WARNING: copy constructor of this class does not create a usable
550
copy, as its members may point at each other.
556
struct ilink *first,last;
557
inline void empty() { first= &last; last.prev= &first; }
558
base_ilist() { empty(); }
559
inline bool is_empty() { return first == &last; }
560
inline void append(ilink *a)
562
first->prev= &a->next;
563
a->next=first; a->prev= &first; first=a;
565
inline void push_back(ilink *a)
572
inline struct ilink *get()
574
struct ilink *first_link=first;
575
if (first_link == &last)
577
first_link->unlink(); // Unlink from list
580
inline struct ilink *head()
582
return (first != &last) ? first : 0;
584
friend class base_list_iterator;
588
class base_ilist_iterator
591
struct ilink **el,*current;
593
base_ilist_iterator(base_ilist &list_par) :list(&list_par),
594
el(&list_par.first),current(0) {}
597
/* This is coded to allow push_back() while iterating */
599
if (current == &list->last) return 0;
607
class I_List :private base_ilist
610
I_List() :base_ilist() {}
611
inline void empty() { base_ilist::empty(); }
612
inline bool is_empty() { return base_ilist::is_empty(); }
613
inline void append(T* a) { base_ilist::append(a); }
614
inline void push_back(T* a) { base_ilist::push_back(a); }
615
inline T* get() { return (T*) base_ilist::get(); }
616
inline T* head() { return (T*) base_ilist::head(); }
618
friend class I_List_iterator<T>;
623
template <class T> class I_List_iterator :public base_ilist_iterator
626
I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
627
inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
451
631
Make a deep copy of each list element.