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
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
28
#include "drizzled/memory/sql_alloc.h"
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 */
33
/** Struct to handle simple linked lists. */
34
typedef struct st_sql_list {
39
st_sql_list() {} /* Remove gcc warning */
46
inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
53
inline void save_and_clear(struct st_sql_list *save)
58
inline void push_front(struct st_sql_list *save)
60
*save->next= first; /* link current list last */
62
elements+= save->elements;
64
inline void push_back(struct st_sql_list *save)
70
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() {}
76
65
Basic single linked list
124
113
relies on this behaviour. This logic is quite tricky: please do not use
125
114
it in any new code.
127
inline base_list(const base_list &tmp) :memory::SqlAlloc()
116
inline base_list(const base_list &tmp) :Sql_alloc()
129
118
elements= tmp.elements;
130
119
first= tmp.first;
131
120
last= elements ? tmp.last : &first;
133
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__))) { }
134
130
inline bool push_back(void *info)
136
132
if (((*last)=new list_node(info, &end_of_list)))
222
218
inline void swap(base_list &rhs)
224
std::swap(first, rhs.first);
225
std::swap(last, rhs.last);
226
std::swap(elements, rhs.elements);
220
swap_variables(list_node *, first, rhs.first);
221
swap_variables(list_node **, last, rhs.last);
222
swap_variables(uint, elements, rhs.elements);
228
224
inline list_node* last_node() { return *last; }
229
225
inline list_node* first_node() { return first;}
385
381
inline List() :base_list() {}
386
382
inline List(const List<T> &tmp) :base_list(tmp) {}
387
inline List(const List<T> &tmp, memory::Root *mem_root) :
383
inline List(const List<T> &tmp, MEM_ROOT *mem_root) :
388
384
base_list(tmp, mem_root) {}
389
385
inline bool push_back(T *a) { return base_list::push_back(a); }
390
inline bool push_back(T *a, memory::Root *mem_root)
386
inline bool push_back(T *a, MEM_ROOT *mem_root)
391
387
{ return base_list::push_back(a, mem_root); }
392
388
inline bool push_front(T *a) { return base_list::push_front(a); }
393
389
inline T* head() {return (T*) base_list::head(); }
440
436
inline void init(List<T> &a) { base_list_iterator::init(a); }
441
437
inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
442
438
inline void rewind(void) { base_list_iterator::rewind(); }
443
void sublist(List<T> &list_arg, uint32_t el_arg)
439
void sublist(List<T> &list_arg, uint el_arg)
445
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(); }
451
586
Make a deep copy of each list element.