~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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