~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_array.h

  • Committer: Brian Aker
  • Date: 2008-08-22 14:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: brian@tangent.org-20080822144138-prws24otgm5bfj06
Dead define removal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <mysys/my_sys.h>
17
17
 
 
18
/*
 
19
  A typesafe wrapper around DYNAMIC_ARRAY
 
20
*/
 
21
 
 
22
template <class Elem> class Dynamic_array
 
23
{
 
24
  DYNAMIC_ARRAY  array;
 
25
public:
 
26
  Dynamic_array(uint prealloc=16, uint increment=16)
 
27
  {
 
28
    init(prealloc, increment);
 
29
  }
 
30
 
 
31
  void init(uint prealloc=16, uint increment=16)
 
32
  {
 
33
    my_init_dynamic_array(&array, sizeof(Elem), prealloc, increment);
 
34
  }
 
35
 
 
36
  Elem& at(int idx)
 
37
  {
 
38
    return *(((Elem*)array.buffer) + idx);
 
39
  }
 
40
 
 
41
  Elem *front()
 
42
  {
 
43
    return (Elem*)array.buffer;
 
44
  }
 
45
 
 
46
  Elem *back()
 
47
  {
 
48
    return ((Elem*)array.buffer) + array.elements;
 
49
  }
 
50
 
 
51
  bool append(Elem &el)
 
52
  {
 
53
    return (insert_dynamic(&array, (uchar*)&el));
 
54
  }
 
55
 
 
56
  int elements()
 
57
  {
 
58
    return array.elements;
 
59
  }
 
60
 
 
61
  void clear()
 
62
  {
 
63
    array.elements= 0;
 
64
  }
 
65
 
 
66
  ~Dynamic_array()
 
67
  {
 
68
    delete_dynamic(&array);
 
69
  }
 
70
 
 
71
  typedef int (*CMP_FUNC)(const Elem *el1, const Elem *el2);
 
72
 
 
73
  void sort(CMP_FUNC cmp_func)
 
74
  {
 
75
    my_qsort(array.buffer, array.elements, sizeof(Elem), (qsort_cmp)cmp_func);
 
76
  }
 
77
};
 
78
 
 
79
 
18
80
/* 
19
81
  Array of pointers to Elem that uses memory from MEM_ROOT
20
82