~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

  • Committer: Brian Aker
  • Date: 2011-02-18 16:48:57 UTC
  • mfrom: (2180.1.3 drizzle-staging)
  • Revision ID: brian@tangent.org-20110218164857-4n61en8wai9c91gi
Rollup all of Olaf's branch.

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
 
 
24
23
#include <cstdlib>
25
24
#include <cassert>
26
25
#include <utility>
28
27
#include <drizzled/memory/sql_alloc.h>
29
28
#include <drizzled/visibility.h>
30
29
 
 
30
namespace drizzled {
31
31
 
32
 
namespace drizzled
 
32
typedef struct st_sql_list 
33
33
{
34
 
 
35
 
/** Struct to handle simple linked lists. */
36
 
typedef struct st_sql_list {
37
34
  uint32_t elements;
38
35
  unsigned char *first;
39
36
  unsigned char **next;
40
37
 
41
 
  st_sql_list() {}                              /* Remove gcc warning */
42
 
  inline void empty()
 
38
  inline void clear()
43
39
  {
44
40
    elements=0;
45
41
    first=0;
55
51
  inline void save_and_clear(struct st_sql_list *save)
56
52
  {
57
53
    *save= *this;
58
 
    empty();
 
54
    clear();
59
55
  }
60
56
  inline void push_front(struct st_sql_list *save)
61
57
  {
115
111
public:
116
112
  uint32_t elements;
117
113
 
118
 
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
119
 
  inline base_list() { empty(); }
 
114
  inline void clear() { elements=0; first= &end_of_list; last=&first;}
 
115
  inline base_list() { clear(); }
120
116
  /**
121
117
    This is a shallow copy constructor that implicitly passes the ownership
122
118
    from the source list to the new instance. The old instance is not
333
329
    el= &tmp->next;
334
330
    return tmp->info;
335
331
  }
336
 
  inline void rewind(void)
337
 
  {
338
 
    el= &list->first;
339
 
  }
340
332
  inline void *replace(void *element)
341
333
  {                                             // Return old element
342
334
    void *tmp=current->info;
381
373
  friend class error_list_iterator;
382
374
};
383
375
 
 
376
template <class T> class List_iterator;
 
377
 
384
378
template <class T> class List :public base_list
385
379
{
386
380
public:
 
381
  typedef List_iterator<T> iterator;
 
382
 
387
383
  inline List() :base_list() {}
388
384
  inline List(const List<T> &tmp) :base_list(tmp) {}
389
385
  inline List(const List<T> &tmp, memory::Root *mem_root) :
393
389
  { return base_list::push_back(a, mem_root); }
394
390
  inline bool push_front(T *a) { return base_list::push_front(a); }
395
391
  inline T* head() {return static_cast<T*>(base_list::head()); }
396
 
  inline T** head_ref() {return static_cast<T**>(base_list::head_ref()); }
397
392
  inline T* pop()  {return static_cast<T*>(base_list::pop()); }
398
393
  inline void concat(List<T> *list) { base_list::concat(list); }
399
394
  inline void disjoin(List<T> *list) { base_list::disjoin(list); }
406
401
      next=element->next;
407
402
      delete (T*) element->info;
408
403
    }
409
 
    empty();
 
404
    clear();
 
405
  }
 
406
 
 
407
  iterator begin()
 
408
  {
 
409
    return iterator(*this);
410
410
  }
411
411
};
412
412
 
416
416
public:
417
417
  List_iterator(List<T> &a) : base_list_iterator(a) {}
418
418
  List_iterator() : base_list_iterator() {}
419
 
  inline void init(List<T> &a) { base_list_iterator::init(a); }
420
419
  inline T* operator++(int) { return (T*) base_list_iterator::next(); }
421
420
  inline T *replace(T *a)   { return (T*) base_list_iterator::replace(a); }
422
421
  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); }
426
422
  inline T** ref(void)      { return (T**) base_list_iterator::ref(); }
427
423
};
428
424
 
441
437
  inline List_iterator_fast() : base_list_iterator() {}
442
438
  inline void init(List<T> &a) { base_list_iterator::init(a); }
443
439
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
444
 
  inline void rewind(void)  { base_list_iterator::rewind(); }
445
440
  void sublist(List<T> &list_arg, uint32_t el_arg)
446
441
  {
447
442
    base_list_iterator::sublist(list_arg, el_arg);
470
465
list_copy_and_replace_each_value(List<T> &list, memory::Root *mem_root)
471
466
{
472
467
  /* Make a deep copy of each element */
473
 
  List_iterator<T> it(list);
 
468
  typename List<T>::iterator it(list);
474
469
  T *el;
475
470
  while ((el= it++))
476
471
    it.replace(el->clone(mem_root));