~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

  • Committer: Lee Bieber
  • Date: 2011-02-11 20:30:05 UTC
  • mfrom: (2157.1.3 build)
  • Revision ID: kalebral@gmail.com-20110211203005-757o1y2yf78dxzqr
Merge Stewart - 716848: drizzleimport displays wrong program_name
Merge Stewart - update README file
Merge Andrew and Joe - Exposes the InnoDB SYS_REPLICATION_LOG to data_dictionary so that it is fast and fixes many issues we have been having

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef DRIZZLED_SQL_LIST_H
21
21
#define DRIZZLED_SQL_LIST_H
22
22
 
 
23
 
23
24
#include <cstdlib>
24
25
#include <cassert>
25
26
#include <utility>
26
27
#include <algorithm>
27
 
#include <drizzled/memory/sql_alloc.h>
28
 
#include <drizzled/visibility.h>
29
 
 
30
 
namespace drizzled {
31
 
 
32
 
typedef struct st_sql_list 
 
28
#include "drizzled/memory/sql_alloc.h"
 
29
#include "drizzled/visibility.h"
 
30
 
 
31
 
 
32
namespace drizzled
33
33
{
 
34
 
 
35
/** Struct to handle simple linked lists. */
 
36
typedef struct st_sql_list {
34
37
  uint32_t elements;
35
38
  unsigned char *first;
36
39
  unsigned char **next;
37
40
 
38
 
  inline void clear()
 
41
  st_sql_list() {}                              /* Remove gcc warning */
 
42
  inline void empty()
39
43
  {
40
44
    elements=0;
41
45
    first=0;
51
55
  inline void save_and_clear(struct st_sql_list *save)
52
56
  {
53
57
    *save= *this;
54
 
    clear();
 
58
    empty();
55
59
  }
56
60
  inline void push_front(struct st_sql_list *save)
57
61
  {
111
115
public:
112
116
  uint32_t elements;
113
117
 
114
 
  inline void clear() { elements=0; first= &end_of_list; last=&first;}
115
 
  inline base_list() { clear(); }
 
118
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
 
119
  inline base_list() { empty(); }
116
120
  /**
117
121
    This is a shallow copy constructor that implicitly passes the ownership
118
122
    from the source list to the new instance. The old instance is not
230
234
  inline bool is_empty() { return first == &end_of_list ; }
231
235
  inline list_node *last_ref() { return &end_of_list; }
232
236
  friend class base_list_iterator;
 
237
  friend class error_list;
 
238
  friend class error_list_iterator;
233
239
 
234
240
#ifdef LIST_EXTRA_DEBUG
235
241
  /*
291
297
protected:
292
298
  base_list *list;
293
299
  list_node **el,**prev,*current;
294
 
public:
295
300
  void sublist(base_list &ls, uint32_t elm)
296
301
  {
297
302
    ls.first= *el;
298
303
    ls.last= list->last;
299
304
    ls.elements= elm;
300
305
  }
 
306
public:
301
307
  base_list_iterator()
302
308
    :list(0), el(0), prev(0), current(0)
303
309
  {}
304
310
 
305
 
  base_list_iterator(base_list &list_par, list_node** el0)
306
 
    :list(&list_par), el(el0), prev(0), current(0)
 
311
  base_list_iterator(base_list &list_par)
 
312
  { init(list_par); }
 
313
 
 
314
  inline void init(base_list &list_par)
307
315
  {
 
316
    list= &list_par;
 
317
    el= &list_par.first;
 
318
    prev= 0;
 
319
    current= 0;
308
320
  }
309
321
 
310
322
  inline void *next(void)
314
326
    el= &current->next;
315
327
    return current->info;
316
328
  }
 
329
  inline void *next_fast(void)
 
330
  {
 
331
    list_node *tmp;
 
332
    tmp= *el;
 
333
    el= &tmp->next;
 
334
    return tmp->info;
 
335
  }
 
336
  inline void rewind(void)
 
337
  {
 
338
    el= &list->first;
 
339
  }
317
340
  inline void *replace(void *element)
318
341
  {                                             // Return old element
319
342
    void *tmp=current->info;
355
378
  {
356
379
    return el == &list->last_ref()->next;
357
380
  }
 
381
  friend class error_list_iterator;
358
382
};
359
383
 
360
 
template <class T> class List_iterator;
361
 
 
362
384
template <class T> class List :public base_list
363
385
{
364
386
public:
365
 
  typedef List_iterator<T> iterator;
366
 
 
367
 
  friend class List_iterator<T>;
368
 
 
369
387
  inline List() :base_list() {}
370
388
  inline List(const List<T> &tmp) :base_list(tmp) {}
371
389
  inline List(const List<T> &tmp, memory::Root *mem_root) :
374
392
  inline bool push_back(T *a, memory::Root *mem_root)
375
393
  { return base_list::push_back(a, mem_root); }
376
394
  inline bool push_front(T *a) { return base_list::push_front(a); }
377
 
  inline T* head() {return static_cast<T*>(base_list::head()); }
378
 
  inline T* pop()  {return static_cast<T*>(base_list::pop()); }
 
395
  inline T* head() {return (T*) base_list::head(); }
 
396
  inline T** head_ref() {return (T**) base_list::head_ref(); }
 
397
  inline T* pop()  {return (T*) base_list::pop(); }
379
398
  inline void concat(List<T> *list) { base_list::concat(list); }
380
399
  inline void disjoin(List<T> *list) { base_list::disjoin(list); }
381
400
  inline void prepand(List<T> *list) { base_list::prepand(list); }
387
406
      next=element->next;
388
407
      delete (T*) element->info;
389
408
    }
390
 
    clear();
391
 
  }
392
 
 
393
 
  iterator begin()
394
 
  {
395
 
    return iterator(*this, &first);
 
409
    empty();
396
410
  }
397
411
};
398
412
 
400
414
template <class T> class List_iterator :public base_list_iterator
401
415
{
402
416
public:
403
 
  List_iterator(List<T>& a, list_node** b) : base_list_iterator(a, b) {};
404
 
  List_iterator() {};
 
417
  List_iterator(List<T> &a) : base_list_iterator(a) {}
 
418
  List_iterator() : base_list_iterator() {}
 
419
  inline void init(List<T> &a) { base_list_iterator::init(a); }
405
420
  inline T* operator++(int) { return (T*) base_list_iterator::next(); }
406
421
  inline T *replace(T *a)   { return (T*) base_list_iterator::replace(a); }
407
422
  inline T *replace(List<T> &a) { return (T*) base_list_iterator::replace(a); }
 
423
  inline void rewind(void)  { base_list_iterator::rewind(); }
 
424
  inline void remove()      { base_list_iterator::remove(); }
 
425
  inline void after(T *a)   { base_list_iterator::after(a); }
408
426
  inline T** ref(void)      { return (T**) base_list_iterator::ref(); }
409
427
};
410
428
 
 
429
 
 
430
template <class T> class List_iterator_fast :public base_list_iterator
 
431
{
 
432
protected:
 
433
  inline T *replace(T *)   { return (T*) 0; }
 
434
  inline T *replace(List<T> &) { return (T*) 0; }
 
435
  inline void remove(void)  { }
 
436
  inline void after(T *)   { }
 
437
  inline T** ref(void)      { return (T**) 0; }
 
438
 
 
439
public:
 
440
  inline List_iterator_fast(List<T> &a) : base_list_iterator(a) {}
 
441
  inline List_iterator_fast() : base_list_iterator() {}
 
442
  inline void init(List<T> &a) { base_list_iterator::init(a); }
 
443
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
 
444
  inline void rewind(void)  { base_list_iterator::rewind(); }
 
445
  void sublist(List<T> &list_arg, uint32_t el_arg)
 
446
  {
 
447
    base_list_iterator::sublist(list_arg, el_arg);
 
448
  }
 
449
};
 
450
 
 
451
 
411
452
/**
412
453
  Make a deep copy of each list element.
413
454
 
424
465
*/
425
466
 
426
467
template <typename T>
427
 
void list_copy_and_replace_each_value(List<T> &list, memory::Root *mem_root)
 
468
inline
 
469
void
 
470
list_copy_and_replace_each_value(List<T> &list, memory::Root *mem_root)
428
471
{
429
472
  /* Make a deep copy of each element */
430
 
  typename List<T>::iterator it(list.begin());
 
473
  List_iterator<T> it(list);
431
474
  T *el;
432
475
  while ((el= it++))
433
476
    it.replace(el->clone(mem_root));