~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

  • Committer: Monty Taylor
  • Date: 2008-12-24 01:49:53 UTC
  • mto: This revision was merged to the branch mainline in revision 751.
  • Revision ID: mordred@inaugust.com-20081224014953-rc9p7a162p74y889
Fixed connect.test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef INCLUDES_DRIZZLE_SQL_LIST_H
2
 
#define INCLUDES_DRIZZLE_SQL_LIST_H
3
 
/* Copyright (C) 2000-2003 MySQL AB
4
 
 
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.
8
 
 
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.
13
 
 
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 */
17
 
 
18
 
 
19
 
#ifdef USE_PRAGMA_INTERFACE
20
 
#pragma interface                       /* gcc class implementation */
21
 
#endif
22
 
                                  
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 */
 
19
 
 
20
#ifndef DRIZZLED_SQL_LIST_H
 
21
#define DRIZZLED_SQL_LIST_H
 
22
 
 
23
 
 
24
#include <utility>
 
25
#include <algorithm>
 
26
#include <stdlib.h>
 
27
#include <drizzled/sql_alloc.h>
 
28
 
23
29
/** Struct to handle simple linked lists. */
24
30
typedef struct st_sql_list {
25
 
  uint elements;
26
 
  uchar *first;
27
 
  uchar **next;
 
31
  uint32_t elements;
 
32
  unsigned char *first;
 
33
  unsigned char **next;
28
34
 
29
35
  st_sql_list() {}                              /* Remove gcc warning */
30
36
  inline void empty()
33
39
    first=0;
34
40
    next= &first;
35
41
  }
36
 
  inline void link_in_list(uchar *element,uchar **next_ptr)
 
42
  inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
37
43
  {
38
44
    elements++;
39
45
    (*next)=element;
62
68
  }
63
69
} SQL_LIST;
64
70
 
65
 
/* mysql standard class memory allocator */
66
 
class Sql_alloc
67
 
{
68
 
public:
69
 
  static void *operator new(size_t size) throw ()
70
 
  {
71
 
    return sql_alloc(size);
72
 
  }
73
 
  static void *operator new[](size_t size)
74
 
  {
75
 
    return sql_alloc(size);
76
 
  }
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)))
83
 
  { TRASH(ptr, size); }
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)))
92
 
  { TRASH(ptr, size); }
93
 
#ifdef HAVE_purify
94
 
  bool dummy;
95
 
  inline Sql_alloc() :dummy(0) {}
96
 
  inline ~Sql_alloc() {}
97
 
#else
98
 
  inline Sql_alloc() {}
99
 
  inline ~Sql_alloc() {}
100
 
#endif
101
 
 
102
 
};
103
 
 
104
 
 
105
71
/*
106
72
  Basic single linked list
107
73
  Used for item and item_buffs.
141
107
  list_node *first,**last;
142
108
 
143
109
public:
144
 
  uint elements;
 
110
  uint32_t elements;
145
111
 
146
112
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
147
113
  inline base_list() { empty(); }
167
133
    list_copy_and_replace_each_value after creating a copy.
168
134
  */
169
135
  base_list(const base_list &rhs, MEM_ROOT *mem_root);
170
 
  inline base_list(bool error __attribute__((unused))) { }
 
136
  inline base_list(bool) { }
171
137
  inline bool push_back(void *info)
172
138
  {
173
139
    if (((*last)=new list_node(info, &end_of_list)))
258
224
  */
259
225
  inline void swap(base_list &rhs)
260
226
  {
261
 
    swap_variables(list_node *, first, rhs.first);
262
 
    swap_variables(list_node **, last, rhs.last);
263
 
    swap_variables(uint, elements, rhs.elements);
 
227
    std::swap(first, rhs.first);
 
228
    std::swap(last, rhs.last);
 
229
    std::swap(elements, rhs.elements);
264
230
  }
265
231
  inline list_node* last_node() { return *last; }
266
232
  inline list_node* first_node() { return first;}
283
249
      check_list()
284
250
        name  Name to print to trace file
285
251
 
286
 
    RETURN 
 
252
    RETURN
287
253
      1  The list is Ok.
288
254
      0  List invariants are not met.
289
255
  */
292
258
  {
293
259
    base_list *list= this;
294
260
    list_node *node= first;
295
 
    uint cnt= 0;
 
261
    uint32_t cnt= 0;
296
262
 
297
263
    while (node->next != &end_of_list)
298
264
    {
332
298
protected:
333
299
  base_list *list;
334
300
  list_node **el,**prev,*current;
335
 
  void sublist(base_list &ls, uint elm)
 
301
  void sublist(base_list &ls, uint32_t elm)
336
302
  {
337
303
    ls.first= *el;
338
304
    ls.last= list->last;
339
305
    ls.elements= elm;
340
306
  }
341
307
public:
342
 
  base_list_iterator() 
 
308
  base_list_iterator()
343
309
    :list(0), el(0), prev(0), current(0)
344
310
  {}
345
311
 
346
 
  base_list_iterator(base_list &list_par) 
 
312
  base_list_iterator(base_list &list_par)
347
313
  { init(list_par); }
348
314
 
349
315
  inline void init(base_list &list_par)
465
431
template <class T> class List_iterator_fast :public base_list_iterator
466
432
{
467
433
protected:
468
 
  inline T *replace(T *a __attribute__((unused)))   { return (T*) 0; }
469
 
  inline T *replace(List<T> &a __attribute__((unused))) { return (T*) 0; }
 
434
  inline T *replace(T *)   { return (T*) 0; }
 
435
  inline T *replace(List<T> &) { return (T*) 0; }
470
436
  inline void remove(void)  { }
471
 
  inline void after(T *a __attribute__((unused)))   { }
 
437
  inline void after(T *a)   { }
472
438
  inline T** ref(void)      { return (T**) 0; }
473
439
 
474
440
public:
477
443
  inline void init(List<T> &a) { base_list_iterator::init(a); }
478
444
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
479
445
  inline void rewind(void)  { base_list_iterator::rewind(); }
480
 
  void sublist(List<T> &list_arg, uint el_arg)
 
446
  void sublist(List<T> &list_arg, uint32_t el_arg)
481
447
  {
482
448
    base_list_iterator::sublist(list_arg, el_arg);
483
449
  }
486
452
 
487
453
/*
488
454
  A simple intrusive list which automaticly removes element from list
489
 
  on delete (for THD element)
 
455
  on delete (for Session element)
490
456
*/
491
457
 
492
458
struct ilink
494
460
  struct ilink **prev,*next;
495
461
  static void *operator new(size_t size)
496
462
  {
497
 
    return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
 
463
    return (void*)malloc((uint)size);
498
464
  }
499
 
  static void operator delete(void* ptr_arg,
500
 
                              size_t size __attribute__((unused)))
 
465
  static void operator delete(void* ptr_arg, size_t)
501
466
  {
502
 
     my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
 
467
     free((unsigned char*)ptr_arg);
503
468
  }
504
469
 
505
470
  inline ilink()
534
499
  const char* key;
535
500
  const char* val;
536
501
  i_string_pair():key(0),val(0) { }
537
 
  i_string_pair(const char* key_arg, const char* val_arg) : 
 
502
  i_string_pair(const char* key_arg, const char* val_arg) :
538
503
    key(key_arg),val(val_arg) {}
539
504
};
540
505
 
605
570
public:
606
571
  I_List() :base_ilist()        {}
607
572
  inline void empty()           { base_ilist::empty(); }
608
 
  inline bool is_empty()        { return base_ilist::is_empty(); } 
 
573
  inline bool is_empty()        { return base_ilist::is_empty(); }
609
574
  inline void append(T* a)      { base_ilist::append(a); }
610
575
  inline void push_back(T* a)   { base_ilist::push_back(a); }
611
576
  inline T* get()               { return (T*) base_ilist::get(); }
634
599
  Evidently not all template arguments have clone() method with
635
600
  the right signature.
636
601
 
637
 
  @return You must query the error state in THD for out-of-memory
 
602
  @return You must query the error state in Session for out-of-memory
638
603
  situation after calling this function.
639
604
*/
640
605
 
650
615
    it.replace(el->clone(mem_root));
651
616
}
652
617
 
653
 
#endif // INCLUDES_DRIZZLE_SQL_LIST_H
 
618
/* sql_list.cc */
 
619
void free_list(I_List <i_string_pair> *list);
 
620
void free_list(I_List <i_string> *list);
 
621
 
 
622
 
 
623
#endif // DRIZZLED_SQL_LIST_H