~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 01:37:05 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916013705-772d1t7rh9ah9j1x
Moved more functions into drizzle.c as part of the split of code.
Added accessor function for drizzle_port.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_SQL_LIST_H
21
 
#define DRIZZLED_SQL_LIST_H
22
 
 
 
20
#ifndef INCLUDES_DRIZZLE_SQL_LIST_H
 
21
#define INCLUDES_DRIZZLE_SQL_LIST_H
 
22
 
 
23
 
 
24
#ifdef USE_PRAGMA_INTERFACE
 
25
#pragma interface                       /* gcc class implementation */
 
26
#endif
23
27
 
24
28
#include <utility>
25
 
#include <algorithm>
26
 
#include <stdlib.h>
27
 
#include <drizzled/sql_alloc.h>
28
29
 
29
30
/** Struct to handle simple linked lists. */
30
31
typedef struct st_sql_list {
31
 
  uint32_t elements;
32
 
  unsigned char *first;
33
 
  unsigned char **next;
 
32
  uint elements;
 
33
  uchar *first;
 
34
  uchar **next;
34
35
 
35
36
  st_sql_list() {}                              /* Remove gcc warning */
36
37
  inline void empty()
39
40
    first=0;
40
41
    next= &first;
41
42
  }
42
 
  inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
 
43
  inline void link_in_list(uchar *element,uchar **next_ptr)
43
44
  {
44
45
    elements++;
45
46
    (*next)=element;
68
69
  }
69
70
} SQL_LIST;
70
71
 
 
72
/* mysql standard class memory allocator */
 
73
class Sql_alloc
 
74
{
 
75
public:
 
76
  static void *operator new(size_t size) throw ()
 
77
  {
 
78
    return sql_alloc(size);
 
79
  }
 
80
  static void *operator new[](size_t size)
 
81
  {
 
82
    return sql_alloc(size);
 
83
  }
 
84
  static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
 
85
  { return alloc_root(mem_root, size); }
 
86
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
 
87
  { return alloc_root(mem_root, size); }
 
88
  static void operator delete(void *ptr __attribute__((unused)),
 
89
                              size_t size __attribute__((unused)))
 
90
  { TRASH(ptr, size); }
 
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
                                MEM_ROOT *mem_root __attribute__((unused)))
 
96
  { /* never called */ }
 
97
  static void operator delete[](void *ptr __attribute__((unused)),
 
98
                                size_t size __attribute__((unused)))
 
99
  { TRASH(ptr, size); }
 
100
#ifdef HAVE_purify
 
101
  bool dummy;
 
102
  inline Sql_alloc() :dummy(0) {}
 
103
  inline ~Sql_alloc() {}
 
104
#else
 
105
  inline Sql_alloc() {}
 
106
  inline ~Sql_alloc() {}
 
107
#endif
 
108
 
 
109
};
 
110
 
 
111
 
71
112
/*
72
113
  Basic single linked list
73
114
  Used for item and item_buffs.
107
148
  list_node *first,**last;
108
149
 
109
150
public:
110
 
  uint32_t elements;
 
151
  uint elements;
111
152
 
112
153
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
113
154
  inline base_list() { empty(); }
133
174
    list_copy_and_replace_each_value after creating a copy.
134
175
  */
135
176
  base_list(const base_list &rhs, MEM_ROOT *mem_root);
136
 
  inline base_list(bool) { }
 
177
  inline base_list(bool error __attribute__((unused))) { }
137
178
  inline bool push_back(void *info)
138
179
  {
139
180
    if (((*last)=new list_node(info, &end_of_list)))
249
290
      check_list()
250
291
        name  Name to print to trace file
251
292
 
252
 
    RETURN
 
293
    RETURN 
253
294
      1  The list is Ok.
254
295
      0  List invariants are not met.
255
296
  */
258
299
  {
259
300
    base_list *list= this;
260
301
    list_node *node= first;
261
 
    uint32_t cnt= 0;
 
302
    uint cnt= 0;
262
303
 
263
304
    while (node->next != &end_of_list)
264
305
    {
298
339
protected:
299
340
  base_list *list;
300
341
  list_node **el,**prev,*current;
301
 
  void sublist(base_list &ls, uint32_t elm)
 
342
  void sublist(base_list &ls, uint elm)
302
343
  {
303
344
    ls.first= *el;
304
345
    ls.last= list->last;
305
346
    ls.elements= elm;
306
347
  }
307
348
public:
308
 
  base_list_iterator()
 
349
  base_list_iterator() 
309
350
    :list(0), el(0), prev(0), current(0)
310
351
  {}
311
352
 
312
 
  base_list_iterator(base_list &list_par)
 
353
  base_list_iterator(base_list &list_par) 
313
354
  { init(list_par); }
314
355
 
315
356
  inline void init(base_list &list_par)
431
472
template <class T> class List_iterator_fast :public base_list_iterator
432
473
{
433
474
protected:
434
 
  inline T *replace(T *)   { return (T*) 0; }
435
 
  inline T *replace(List<T> &) { return (T*) 0; }
 
475
  inline T *replace(T *a __attribute__((unused)))   { return (T*) 0; }
 
476
  inline T *replace(List<T> &a __attribute__((unused))) { return (T*) 0; }
436
477
  inline void remove(void)  { }
437
 
  inline void after(T *a)   { }
 
478
  inline void after(T *a __attribute__((unused)))   { }
438
479
  inline T** ref(void)      { return (T**) 0; }
439
480
 
440
481
public:
443
484
  inline void init(List<T> &a) { base_list_iterator::init(a); }
444
485
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
445
486
  inline void rewind(void)  { base_list_iterator::rewind(); }
446
 
  void sublist(List<T> &list_arg, uint32_t el_arg)
 
487
  void sublist(List<T> &list_arg, uint el_arg)
447
488
  {
448
489
    base_list_iterator::sublist(list_arg, el_arg);
449
490
  }
452
493
 
453
494
/*
454
495
  A simple intrusive list which automaticly removes element from list
455
 
  on delete (for Session element)
 
496
  on delete (for THD element)
456
497
*/
457
498
 
458
499
struct ilink
460
501
  struct ilink **prev,*next;
461
502
  static void *operator new(size_t size)
462
503
  {
463
 
    return (void*)malloc((uint32_t)size);
 
504
    return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
464
505
  }
465
 
  static void operator delete(void* ptr_arg, size_t)
 
506
  static void operator delete(void* ptr_arg,
 
507
                              size_t size __attribute__((unused)))
466
508
  {
467
 
     free((unsigned char*)ptr_arg);
 
509
     my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
468
510
  }
469
511
 
470
512
  inline ilink()
499
541
  const char* key;
500
542
  const char* val;
501
543
  i_string_pair():key(0),val(0) { }
502
 
  i_string_pair(const char* key_arg, const char* val_arg) :
 
544
  i_string_pair(const char* key_arg, const char* val_arg) : 
503
545
    key(key_arg),val(val_arg) {}
504
546
};
505
547
 
570
612
public:
571
613
  I_List() :base_ilist()        {}
572
614
  inline void empty()           { base_ilist::empty(); }
573
 
  inline bool is_empty()        { return base_ilist::is_empty(); }
 
615
  inline bool is_empty()        { return base_ilist::is_empty(); } 
574
616
  inline void append(T* a)      { base_ilist::append(a); }
575
617
  inline void push_back(T* a)   { base_ilist::push_back(a); }
576
618
  inline T* get()               { return (T*) base_ilist::get(); }
599
641
  Evidently not all template arguments have clone() method with
600
642
  the right signature.
601
643
 
602
 
  @return You must query the error state in Session for out-of-memory
 
644
  @return You must query the error state in THD for out-of-memory
603
645
  situation after calling this function.
604
646
*/
605
647
 
615
657
    it.replace(el->clone(mem_root));
616
658
}
617
659
 
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
 
660
#endif // INCLUDES_DRIZZLE_SQL_LIST_H