~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_list.h

Removed DBUG symbols and fixed TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 INCLUDES_DRIZZLE_SQL_LIST_H
21
 
#define INCLUDES_DRIZZLE_SQL_LIST_H
22
 
 
23
 
 
24
 
#include <utility>
25
 
#include <algorithm>
26
 
 
27
 
/** Struct to handle simple linked lists. */
28
 
typedef struct st_sql_list {
29
 
  uint32_t elements;
30
 
  unsigned char *first;
31
 
  unsigned char **next;
32
 
 
33
 
  st_sql_list() {}                              /* Remove gcc warning */
34
 
  inline void empty()
35
 
  {
36
 
    elements=0;
37
 
    first=0;
38
 
    next= &first;
39
 
  }
40
 
  inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
41
 
  {
42
 
    elements++;
43
 
    (*next)=element;
44
 
    next= next_ptr;
45
 
    *next=0;
46
 
  }
47
 
  inline void save_and_clear(struct st_sql_list *save)
48
 
  {
49
 
    *save= *this;
50
 
    empty();
51
 
  }
52
 
  inline void push_front(struct st_sql_list *save)
53
 
  {
54
 
    *save->next= first;                         /* link current list last */
55
 
    first= save->first;
56
 
    elements+= save->elements;
57
 
  }
58
 
  inline void push_back(struct st_sql_list *save)
59
 
  {
60
 
    if (save->first)
61
 
    {
62
 
      *next= save->first;
63
 
      next= save->next;
64
 
      elements+= save->elements;
65
 
    }
66
 
  }
67
 
} SQL_LIST;
 
1
#ifndef INCLUDES_MYSQL_SQL_LIST_H
 
2
#define INCLUDES_MYSQL_SQL_LIST_H
 
3
/* Copyright (C) 2000-2003 MySQL AB
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; version 2 of the License.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software
 
16
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
17
 
 
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
68
22
 
69
23
/* mysql standard class memory allocator */
 
24
 
70
25
class Sql_alloc
71
26
{
72
27
public:
82
37
  { return alloc_root(mem_root, size); }
83
38
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
84
39
  { return alloc_root(mem_root, size); }
85
 
  static void operator delete(void *ptr __attribute__((unused)),
86
 
                              size_t size __attribute__((unused)))
 
40
  static void operator delete(void *ptr __attribute__((__unused__)),
 
41
                              size_t size __attribute__((__unused__)))
87
42
  { TRASH(ptr, size); }
88
 
  static void operator delete(void *ptr __attribute__((unused)),
89
 
                              MEM_ROOT *mem_root __attribute__((unused)))
90
 
  { /* never called */ }
91
 
  static void operator delete[](void *ptr __attribute__((unused)),
92
 
                                MEM_ROOT *mem_root __attribute__((unused)))
93
 
  { /* never called */ }
94
 
  static void operator delete[](void *ptr __attribute__((unused)),
95
 
                                size_t size __attribute__((unused)))
 
43
  static void operator delete(void *ptr __attribute__((__unused__)),
 
44
                              MEM_ROOT *mem_root __attribute__((__unused__)))
 
45
  { /* never called */ }
 
46
  static void operator delete[](void *ptr __attribute__((__unused__)),
 
47
                                MEM_ROOT *mem_root __attribute__((__unused__)))
 
48
  { /* never called */ }
 
49
  static void operator delete[](void *ptr __attribute__((__unused__)),
 
50
                                size_t size __attribute__((__unused__)))
96
51
  { TRASH(ptr, size); }
97
52
#ifdef HAVE_purify
98
53
  bool dummy;
145
100
  list_node *first,**last;
146
101
 
147
102
public:
148
 
  uint32_t elements;
 
103
  uint elements;
149
104
 
150
105
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
151
106
  inline base_list() { empty(); }
171
126
    list_copy_and_replace_each_value after creating a copy.
172
127
  */
173
128
  base_list(const base_list &rhs, MEM_ROOT *mem_root);
174
 
  inline base_list(bool error __attribute__((unused))) { }
 
129
  inline base_list(bool error __attribute__((__unused__))) { }
175
130
  inline bool push_back(void *info)
176
131
  {
177
132
    if (((*last)=new list_node(info, &end_of_list)))
262
217
  */
263
218
  inline void swap(base_list &rhs)
264
219
  {
265
 
    std::swap(first, rhs.first);
266
 
    std::swap(last, rhs.last);
267
 
    std::swap(elements, rhs.elements);
 
220
    swap_variables(list_node *, first, rhs.first);
 
221
    swap_variables(list_node **, last, rhs.last);
 
222
    swap_variables(uint, elements, rhs.elements);
268
223
  }
269
224
  inline list_node* last_node() { return *last; }
270
225
  inline list_node* first_node() { return first;}
296
251
  {
297
252
    base_list *list= this;
298
253
    list_node *node= first;
299
 
    uint32_t cnt= 0;
 
254
    uint cnt= 0;
300
255
 
301
256
    while (node->next != &end_of_list)
302
257
    {
303
258
      if (!node->info)
304
259
      {
305
 
        return false;
 
260
        DBUG_PRINT("list_invariants",("%s: error: NULL element in the list", 
 
261
                                      name));
 
262
        return FALSE;
306
263
      }
307
264
      node= node->next;
308
265
      cnt++;
309
266
    }
310
267
    if (last != &(node->next))
311
268
    {
312
 
      return false;
 
269
      DBUG_PRINT("list_invariants", ("%s: error: wrong last pointer", name));
 
270
      return FALSE;
313
271
    }
314
272
    if (cnt+1 != elements)
315
273
    {
316
 
      return false;
 
274
      DBUG_PRINT("list_invariants", ("%s: error: wrong element count", name));
 
275
      return FALSE;
317
276
    }
318
 
    return true;
 
277
    DBUG_PRINT("list_invariants", ("%s: list is ok", name));
 
278
    return TRUE;
319
279
  }
320
280
#endif // LIST_EXTRA_DEBUG
321
281
 
336
296
protected:
337
297
  base_list *list;
338
298
  list_node **el,**prev,*current;
339
 
  void sublist(base_list &ls, uint32_t elm)
 
299
  void sublist(base_list &ls, uint elm)
340
300
  {
341
301
    ls.first= *el;
342
302
    ls.last= list->last;
379
339
  inline void *replace(void *element)
380
340
  {                                             // Return old element
381
341
    void *tmp=current->info;
382
 
    assert(current->info != 0);
 
342
    DBUG_ASSERT(current->info != 0);
383
343
    current->info=element;
384
344
    return tmp;
385
345
  }
469
429
template <class T> class List_iterator_fast :public base_list_iterator
470
430
{
471
431
protected:
472
 
  inline T *replace(T *a __attribute__((unused)))   { return (T*) 0; }
473
 
  inline T *replace(List<T> &a __attribute__((unused))) { return (T*) 0; }
 
432
  inline T *replace(T *a __attribute__((__unused__)))   { return (T*) 0; }
 
433
  inline T *replace(List<T> &a __attribute__((__unused__))) { return (T*) 0; }
474
434
  inline void remove(void)  { }
475
 
  inline void after(T *a __attribute__((unused)))   { }
 
435
  inline void after(T *a __attribute__((__unused__)))   { }
476
436
  inline T** ref(void)      { return (T**) 0; }
477
437
 
478
438
public:
481
441
  inline void init(List<T> &a) { base_list_iterator::init(a); }
482
442
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
483
443
  inline void rewind(void)  { base_list_iterator::rewind(); }
484
 
  void sublist(List<T> &list_arg, uint32_t el_arg)
 
444
  void sublist(List<T> &list_arg, uint el_arg)
485
445
  {
486
446
    base_list_iterator::sublist(list_arg, el_arg);
487
447
  }
501
461
    return (void*)my_malloc((uint)size, MYF(MY_WME | MY_FAE | ME_FATALERROR));
502
462
  }
503
463
  static void operator delete(void* ptr_arg,
504
 
                              size_t size __attribute__((unused)))
 
464
                              size_t size __attribute__((__unused__)))
505
465
  {
506
 
     free((unsigned char*)ptr_arg);
 
466
     my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
507
467
  }
508
468
 
509
469
  inline ilink()
654
614
    it.replace(el->clone(mem_root));
655
615
}
656
616
 
657
 
#endif // INCLUDES_DRIZZLE_SQL_LIST_H
 
617
#endif // INCLUDES_MYSQL_SQL_LIST_H