1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
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
27
#include <drizzled/memory/sql_alloc.h>
28
#include <drizzled/visibility.h>
32
typedef struct st_sql_list
1
#ifndef INCLUDES_MYSQL_SQL_LIST_H
2
#define INCLUDES_MYSQL_SQL_LIST_H
3
/* Copyright (C) 2000-2003 MySQL AB
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
#ifdef USE_PRAGMA_INTERFACE
20
#pragma interface /* gcc class implementation */
23
/* mysql standard class memory allocator */
44
inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
51
inline void save_and_clear(struct st_sql_list *save)
56
inline void push_front(struct st_sql_list *save)
58
*save->next= first; /* link current list last */
60
elements+= save->elements;
62
inline void push_back(struct st_sql_list *save)
68
elements+= save->elements;
28
static void *operator new(size_t size) throw ()
30
return sql_alloc(size);
32
static void *operator new[](size_t size)
34
return sql_alloc(size);
36
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
37
{ return alloc_root(mem_root, size); }
38
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
39
{ return alloc_root(mem_root, size); }
40
static void operator delete(void *ptr __attribute__((__unused__)),
41
size_t size __attribute__((__unused__)))
43
static void operator delete(void *ptr __attribute__((__unused__)),
44
MEM_ROOT *mem_root __attribute__((__unused__)))
45
{ /* never called */ }
46
static void operator delete[](void *ptr __attribute__((__unused__)),
47
MEM_ROOT *mem_root __attribute__((__unused__)))
48
{ /* never called */ }
49
static void operator delete[](void *ptr __attribute__((__unused__)),
50
size_t size __attribute__((__unused__)))
54
inline Sql_alloc() :dummy(0) {}
55
inline ~Sql_alloc() {}
58
inline ~Sql_alloc() {}
74
65
Basic single linked list
122
113
relies on this behaviour. This logic is quite tricky: please do not use
123
114
it in any new code.
125
inline base_list(const base_list &tmp) :memory::SqlAlloc()
116
inline base_list(const base_list &tmp) :Sql_alloc()
127
118
elements= tmp.elements;
128
119
first= tmp.first;
129
120
last= elements ? tmp.last : &first;
131
inline base_list(bool) { }
123
Construct a deep copy of the argument in memory root mem_root.
124
The elements themselves are copied by pointer. If you also
125
need to copy elements by value, you should employ
126
list_copy_and_replace_each_value after creating a copy.
128
base_list(const base_list &rhs, MEM_ROOT *mem_root);
129
inline base_list(bool error __attribute__((__unused__))) { }
132
130
inline bool push_back(void *info)
134
132
if (((*last)=new list_node(info, &end_of_list)))
356
373
return el == &list->last_ref()->next;
375
friend class error_list_iterator;
360
template <class T> class List_iterator;
362
378
template <class T> class List :public base_list
365
typedef List_iterator<T> iterator;
367
friend class List_iterator<T>;
369
381
inline List() :base_list() {}
370
382
inline List(const List<T> &tmp) :base_list(tmp) {}
371
inline List(const List<T> &tmp, memory::Root *mem_root) :
383
inline List(const List<T> &tmp, MEM_ROOT *mem_root) :
372
384
base_list(tmp, mem_root) {}
373
385
inline bool push_back(T *a) { return base_list::push_back(a); }
374
inline bool push_back(T *a, memory::Root *mem_root)
386
inline bool push_back(T *a, MEM_ROOT *mem_root)
375
387
{ return base_list::push_back(a, mem_root); }
376
388
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()); }
389
inline T* head() {return (T*) base_list::head(); }
390
inline T** head_ref() {return (T**) base_list::head_ref(); }
391
inline T* pop() {return (T*) base_list::pop(); }
379
392
inline void concat(List<T> *list) { base_list::concat(list); }
380
393
inline void disjoin(List<T> *list) { base_list::disjoin(list); }
381
394
inline void prepand(List<T> *list) { base_list::prepand(list); }
400
408
template <class T> class List_iterator :public base_list_iterator
403
List_iterator(List<T>& a, list_node** b) : base_list_iterator(a, b) {};
411
List_iterator(List<T> &a) : base_list_iterator(a) {}
412
List_iterator() : base_list_iterator() {}
413
inline void init(List<T> &a) { base_list_iterator::init(a); }
405
414
inline T* operator++(int) { return (T*) base_list_iterator::next(); }
406
415
inline T *replace(T *a) { return (T*) base_list_iterator::replace(a); }
407
416
inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
417
inline void rewind(void) { base_list_iterator::rewind(); }
418
inline void remove() { base_list_iterator::remove(); }
419
inline void after(T *a) { base_list_iterator::after(a); }
408
420
inline T** ref(void) { return (T**) base_list_iterator::ref(); }
424
template <class T> class List_iterator_fast :public base_list_iterator
427
inline T *replace(T *a __attribute__((__unused__))) { return (T*) 0; }
428
inline T *replace(List<T> &a __attribute__((__unused__))) { return (T*) 0; }
429
inline void remove(void) { }
430
inline void after(T *a __attribute__((__unused__))) { }
431
inline T** ref(void) { return (T**) 0; }
434
inline List_iterator_fast(List<T> &a) : base_list_iterator(a) {}
435
inline List_iterator_fast() : base_list_iterator() {}
436
inline void init(List<T> &a) { base_list_iterator::init(a); }
437
inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
438
inline void rewind(void) { base_list_iterator::rewind(); }
439
void sublist(List<T> &list_arg, uint el_arg)
441
base_list_iterator::sublist(list_arg, el_arg);
447
A simple intrusive list which automaticly removes element from list
448
on delete (for THD element)
453
struct ilink **prev,*next;
454
static void *operator new(size_t size)
456
return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
458
static void operator delete(void* ptr_arg,
459
size_t size __attribute__((__unused__)))
461
my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
470
/* Extra tests because element doesn't have to be linked */
471
if (prev) *prev= next;
472
if (next) next->prev=prev;
475
virtual ~ilink() { unlink(); } /*lint -e1740 */
479
/* Needed to be able to have an I_List of char* strings in mysqld.cc. */
481
class i_string: public ilink
485
i_string():ptr(0) { }
486
i_string(const char* s) : ptr(s) {}
489
/* needed for linked list of two strings for replicate-rewrite-db */
490
class i_string_pair: public ilink
495
i_string_pair():key(0),val(0) { }
496
i_string_pair(const char* key_arg, const char* val_arg) :
497
key(key_arg),val(val_arg) {}
501
template <class T> class I_List_iterator;
504
WARNING: copy constructor of this class does not create a usable
505
copy, as its members may point at each other.
511
struct ilink *first,last;
512
inline void empty() { first= &last; last.prev= &first; }
513
base_ilist() { empty(); }
514
inline bool is_empty() { return first == &last; }
515
inline void append(ilink *a)
517
first->prev= &a->next;
518
a->next=first; a->prev= &first; first=a;
520
inline void push_back(ilink *a)
527
inline struct ilink *get()
529
struct ilink *first_link=first;
530
if (first_link == &last)
532
first_link->unlink(); // Unlink from list
535
inline struct ilink *head()
537
return (first != &last) ? first : 0;
539
friend class base_list_iterator;
543
class base_ilist_iterator
546
struct ilink **el,*current;
548
base_ilist_iterator(base_ilist &list_par) :list(&list_par),
549
el(&list_par.first),current(0) {}
552
/* This is coded to allow push_back() while iterating */
554
if (current == &list->last) return 0;
562
class I_List :private base_ilist
565
I_List() :base_ilist() {}
566
inline void empty() { base_ilist::empty(); }
567
inline bool is_empty() { return base_ilist::is_empty(); }
568
inline void append(T* a) { base_ilist::append(a); }
569
inline void push_back(T* a) { base_ilist::push_back(a); }
570
inline T* get() { return (T*) base_ilist::get(); }
571
inline T* head() { return (T*) base_ilist::head(); }
573
friend class I_List_iterator<T>;
578
template <class T> class I_List_iterator :public base_ilist_iterator
581
I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
582
inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
412
586
Make a deep copy of each list element.