1
#ifndef INCLUDES_DRIZZLE_SQL_LIST_H
2
#define INCLUDES_DRIZZLE_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 */
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"
23
33
/** Struct to handle simple linked lists. */
24
34
typedef struct st_sql_list {
29
39
st_sql_list() {} /* Remove gcc warning */
30
40
inline void empty()
65
/* mysql standard class memory allocator */
69
static void *operator new(size_t size) throw ()
71
return sql_alloc(size);
73
static void *operator new[](size_t size)
75
return sql_alloc(size);
77
static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
78
{ return alloc_root(mem_root, size); }
79
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
80
{ return alloc_root(mem_root, size); }
81
static void operator delete(void *ptr __attribute__((unused)),
82
size_t size __attribute__((unused)))
84
static void operator delete(void *ptr __attribute__((unused)),
85
MEM_ROOT *mem_root __attribute__((unused)))
86
{ /* never called */ }
87
static void operator delete[](void *ptr __attribute__((unused)),
88
MEM_ROOT *mem_root __attribute__((unused)))
89
{ /* never called */ }
90
static void operator delete[](void *ptr __attribute__((unused)),
91
size_t size __attribute__((unused)))
95
inline Sql_alloc() :dummy(0) {}
96
inline ~Sql_alloc() {}
99
inline ~Sql_alloc() {}
106
76
Basic single linked list
107
77
Used for item and item_buffs.
154
124
relies on this behaviour. This logic is quite tricky: please do not use
155
125
it in any new code.
157
inline base_list(const base_list &tmp) :Sql_alloc()
127
inline base_list(const base_list &tmp) :memory::SqlAlloc()
159
129
elements= tmp.elements;
160
130
first= tmp.first;
161
131
last= elements ? tmp.last : &first;
164
Construct a deep copy of the argument in memory root mem_root.
165
The elements themselves are copied by pointer. If you also
166
need to copy elements by value, you should employ
167
list_copy_and_replace_each_value after creating a copy.
169
base_list(const base_list &rhs, MEM_ROOT *mem_root);
170
inline base_list(bool error __attribute__((unused))) { }
133
inline base_list(bool) { }
171
134
inline bool push_back(void *info)
173
136
if (((*last)=new list_node(info, &end_of_list)))
259
222
inline void swap(base_list &rhs)
261
swap_variables(list_node *, first, rhs.first);
262
swap_variables(list_node **, last, rhs.last);
263
swap_variables(uint, elements, rhs.elements);
224
std::swap(first, rhs.first);
225
std::swap(last, rhs.last);
226
std::swap(elements, rhs.elements);
265
228
inline list_node* last_node() { return *last; }
266
229
inline list_node* first_node() { return first;}
422
385
inline List() :base_list() {}
423
386
inline List(const List<T> &tmp) :base_list(tmp) {}
424
inline List(const List<T> &tmp, MEM_ROOT *mem_root) :
387
inline List(const List<T> &tmp, memory::Root *mem_root) :
425
388
base_list(tmp, mem_root) {}
426
389
inline bool push_back(T *a) { return base_list::push_back(a); }
427
inline bool push_back(T *a, MEM_ROOT *mem_root)
390
inline bool push_back(T *a, memory::Root *mem_root)
428
391
{ return base_list::push_back(a, mem_root); }
429
392
inline bool push_front(T *a) { return base_list::push_front(a); }
430
393
inline T* head() {return (T*) base_list::head(); }
477
440
inline void init(List<T> &a) { base_list_iterator::init(a); }
478
441
inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
479
442
inline void rewind(void) { base_list_iterator::rewind(); }
480
void sublist(List<T> &list_arg, uint el_arg)
443
void sublist(List<T> &list_arg, uint32_t el_arg)
482
445
base_list_iterator::sublist(list_arg, el_arg);
488
A simple intrusive list which automaticly removes element from list
489
on delete (for THD element)
494
struct ilink **prev,*next;
495
static void *operator new(size_t size)
497
return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
499
static void operator delete(void* ptr_arg,
500
size_t size __attribute__((unused)))
502
my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
511
/* Extra tests because element doesn't have to be linked */
512
if (prev) *prev= next;
513
if (next) next->prev=prev;
516
virtual ~ilink() { unlink(); } /*lint -e1740 */
520
/* Needed to be able to have an I_List of char* strings in mysqld.cc. */
522
class i_string: public ilink
526
i_string():ptr(0) { }
527
i_string(const char* s) : ptr(s) {}
530
/* needed for linked list of two strings for replicate-rewrite-db */
531
class i_string_pair: public ilink
536
i_string_pair():key(0),val(0) { }
537
i_string_pair(const char* key_arg, const char* val_arg) :
538
key(key_arg),val(val_arg) {}
542
template <class T> class I_List_iterator;
545
WARNING: copy constructor of this class does not create a usable
546
copy, as its members may point at each other.
552
struct ilink *first,last;
553
inline void empty() { first= &last; last.prev= &first; }
554
base_ilist() { empty(); }
555
inline bool is_empty() { return first == &last; }
556
inline void append(ilink *a)
558
first->prev= &a->next;
559
a->next=first; a->prev= &first; first=a;
561
inline void push_back(ilink *a)
568
inline struct ilink *get()
570
struct ilink *first_link=first;
571
if (first_link == &last)
573
first_link->unlink(); // Unlink from list
576
inline struct ilink *head()
578
return (first != &last) ? first : 0;
580
friend class base_list_iterator;
584
class base_ilist_iterator
587
struct ilink **el,*current;
589
base_ilist_iterator(base_ilist &list_par) :list(&list_par),
590
el(&list_par.first),current(0) {}
593
/* This is coded to allow push_back() while iterating */
595
if (current == &list->last) return 0;
603
class I_List :private base_ilist
606
I_List() :base_ilist() {}
607
inline void empty() { base_ilist::empty(); }
608
inline bool is_empty() { return base_ilist::is_empty(); }
609
inline void append(T* a) { base_ilist::append(a); }
610
inline void push_back(T* a) { base_ilist::push_back(a); }
611
inline T* get() { return (T*) base_ilist::get(); }
612
inline T* head() { return (T*) base_ilist::head(); }
614
friend class I_List_iterator<T>;
619
template <class T> class I_List_iterator :public base_ilist_iterator
622
I_List_iterator(I_List<T> &a) : base_ilist_iterator(a) {}
623
inline T* operator++(int) { return (T*) base_ilist_iterator::next(); }
627
451
Make a deep copy of each list element.