~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_array.h

pandora-build v0.71. Added check for avahi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2003 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef DRIZZLED_SQL_ARRAY_H
 
21
#define DRIZZLED_SQL_ARRAY_H
15
22
 
16
23
#include <mysys/my_sys.h>
17
24
 
18
25
/*
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
 
 
80
 
/* 
81
26
  Array of pointers to Elem that uses memory from MEM_ROOT
82
27
 
83
28
  MEM_ROOT has no realloc() so this is supposed to be used for cases when
88
33
{
89
34
  enum {alloc_increment = 16};
90
35
  Elem **buffer;
91
 
  uint n_elements, max_element;
 
36
  uint32_t n_elements, max_element;
92
37
public:
93
 
  Array(MEM_ROOT *mem_root, uint prealloc=16)
 
38
  Array(MEM_ROOT *mem_root, uint32_t prealloc=16)
94
39
  {
95
40
    buffer= (Elem**)alloc_root(mem_root, prealloc * sizeof(Elem**));
96
41
    max_element = buffer? prealloc : 0;
147
92
  }
148
93
};
149
94
 
 
95
#endif /* DRIZZLED_SQL_ARRAY_H */