~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

Merged in latest plugin-slot-reorg.

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 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
 
20
#ifndef DRIZZLED_SQL_LIST_H
 
21
#define DRIZZLED_SQL_LIST_H
 
22
 
27
23
 
28
24
#include <utility>
29
25
#include <algorithm>
 
26
#include <stdlib.h>
 
27
#include <drizzled/sql_alloc.h>
30
28
 
31
29
/** Struct to handle simple linked lists. */
32
30
typedef struct st_sql_list {
70
68
  }
71
69
} SQL_LIST;
72
70
 
73
 
/* mysql standard class memory allocator */
74
 
class Sql_alloc
75
 
{
76
 
public:
77
 
  static void *operator new(size_t size) throw ()
78
 
  {
79
 
    return sql_alloc(size);
80
 
  }
81
 
  static void *operator new[](size_t size)
82
 
  {
83
 
    return sql_alloc(size);
84
 
  }
85
 
  static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
86
 
  { return alloc_root(mem_root, size); }
87
 
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
88
 
  { return alloc_root(mem_root, size); }
89
 
  static void operator delete(void *ptr __attribute__((unused)),
90
 
                              size_t size __attribute__((unused)))
91
 
  { TRASH(ptr, size); }
92
 
  static void operator delete(void *ptr __attribute__((unused)),
93
 
                              MEM_ROOT *mem_root __attribute__((unused)))
94
 
  { /* never called */ }
95
 
  static void operator delete[](void *ptr __attribute__((unused)),
96
 
                                MEM_ROOT *mem_root __attribute__((unused)))
97
 
  { /* never called */ }
98
 
  static void operator delete[](void *ptr __attribute__((unused)),
99
 
                                size_t size __attribute__((unused)))
100
 
  { TRASH(ptr, size); }
101
 
#ifdef HAVE_purify
102
 
  bool dummy;
103
 
  inline Sql_alloc() :dummy(0) {}
104
 
  inline ~Sql_alloc() {}
105
 
#else
106
 
  inline Sql_alloc() {}
107
 
  inline ~Sql_alloc() {}
108
 
#endif
109
 
 
110
 
};
111
 
 
112
 
 
113
71
/*
114
72
  Basic single linked list
115
73
  Used for item and item_buffs.
175
133
    list_copy_and_replace_each_value after creating a copy.
176
134
  */
177
135
  base_list(const base_list &rhs, MEM_ROOT *mem_root);
178
 
  inline base_list(bool error __attribute__((unused))) { }
 
136
  inline base_list(bool) { }
179
137
  inline bool push_back(void *info)
180
138
  {
181
139
    if (((*last)=new list_node(info, &end_of_list)))
291
249
      check_list()
292
250
        name  Name to print to trace file
293
251
 
294
 
    RETURN 
 
252
    RETURN
295
253
      1  The list is Ok.
296
254
      0  List invariants are not met.
297
255
  */
347
305
    ls.elements= elm;
348
306
  }
349
307
public:
350
 
  base_list_iterator() 
 
308
  base_list_iterator()
351
309
    :list(0), el(0), prev(0), current(0)
352
310
  {}
353
311
 
354
 
  base_list_iterator(base_list &list_par) 
 
312
  base_list_iterator(base_list &list_par)
355
313
  { init(list_par); }
356
314
 
357
315
  inline void init(base_list &list_par)
473
431
template <class T> class List_iterator_fast :public base_list_iterator
474
432
{
475
433
protected:
476
 
  inline T *replace(T *a __attribute__((unused)))   { return (T*) 0; }
477
 
  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; }
478
436
  inline void remove(void)  { }
479
 
  inline void after(T *a __attribute__((unused)))   { }
 
437
  inline void after(T *a)   { }
480
438
  inline T** ref(void)      { return (T**) 0; }
481
439
 
482
440
public:
494
452
 
495
453
/*
496
454
  A simple intrusive list which automaticly removes element from list
497
 
  on delete (for THD element)
 
455
  on delete (for Session element)
498
456
*/
499
457
 
500
458
struct ilink
502
460
  struct ilink **prev,*next;
503
461
  static void *operator new(size_t size)
504
462
  {
505
 
    return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
 
463
    return (void*)malloc((uint32_t)size);
506
464
  }
507
 
  static void operator delete(void* ptr_arg,
508
 
                              size_t size __attribute__((unused)))
 
465
  static void operator delete(void* ptr_arg, size_t)
509
466
  {
510
467
     free((unsigned char*)ptr_arg);
511
468
  }
542
499
  const char* key;
543
500
  const char* val;
544
501
  i_string_pair():key(0),val(0) { }
545
 
  i_string_pair(const char* key_arg, const char* val_arg) : 
 
502
  i_string_pair(const char* key_arg, const char* val_arg) :
546
503
    key(key_arg),val(val_arg) {}
547
504
};
548
505
 
613
570
public:
614
571
  I_List() :base_ilist()        {}
615
572
  inline void empty()           { base_ilist::empty(); }
616
 
  inline bool is_empty()        { return base_ilist::is_empty(); } 
 
573
  inline bool is_empty()        { return base_ilist::is_empty(); }
617
574
  inline void append(T* a)      { base_ilist::append(a); }
618
575
  inline void push_back(T* a)   { base_ilist::push_back(a); }
619
576
  inline T* get()               { return (T*) base_ilist::get(); }
642
599
  Evidently not all template arguments have clone() method with
643
600
  the right signature.
644
601
 
645
 
  @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
646
603
  situation after calling this function.
647
604
*/
648
605
 
658
615
    it.replace(el->clone(mem_root));
659
616
}
660
617
 
661
 
#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