~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_list.h

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

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 DRIZZLED_SQL_LIST_H
21
 
#define DRIZZLED_SQL_LIST_H
22
 
 
 
1
#ifndef INCLUDES_DRIZZLE_SQL_LIST_H
 
2
#define INCLUDES_DRIZZLE_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
23
22
 
24
23
#include <utility>
25
 
#include <algorithm>
26
 
#include <drizzled/sql_alloc.h>
27
24
 
28
25
/** Struct to handle simple linked lists. */
29
26
typedef struct st_sql_list {
30
 
  uint32_t elements;
31
 
  unsigned char *first;
32
 
  unsigned char **next;
 
27
  uint elements;
 
28
  uchar *first;
 
29
  uchar **next;
33
30
 
34
31
  st_sql_list() {}                              /* Remove gcc warning */
35
32
  inline void empty()
38
35
    first=0;
39
36
    next= &first;
40
37
  }
41
 
  inline void link_in_list(unsigned char *element,unsigned char **next_ptr)
 
38
  inline void link_in_list(uchar *element,uchar **next_ptr)
42
39
  {
43
40
    elements++;
44
41
    (*next)=element;
67
64
  }
68
65
} SQL_LIST;
69
66
 
 
67
/* mysql standard class memory allocator */
 
68
class Sql_alloc
 
69
{
 
70
public:
 
71
  static void *operator new(size_t size) throw ()
 
72
  {
 
73
    return sql_alloc(size);
 
74
  }
 
75
  static void *operator new[](size_t size)
 
76
  {
 
77
    return sql_alloc(size);
 
78
  }
 
79
  static void *operator new[](size_t size, MEM_ROOT *mem_root) throw ()
 
80
  { return alloc_root(mem_root, size); }
 
81
  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
 
82
  { return alloc_root(mem_root, size); }
 
83
  static void operator delete(void *ptr __attribute__((unused)),
 
84
                              size_t size __attribute__((unused)))
 
85
  { TRASH(ptr, size); }
 
86
  static void operator delete(void *ptr __attribute__((unused)),
 
87
                              MEM_ROOT *mem_root __attribute__((unused)))
 
88
  { /* never called */ }
 
89
  static void operator delete[](void *ptr __attribute__((unused)),
 
90
                                MEM_ROOT *mem_root __attribute__((unused)))
 
91
  { /* never called */ }
 
92
  static void operator delete[](void *ptr __attribute__((unused)),
 
93
                                size_t size __attribute__((unused)))
 
94
  { TRASH(ptr, size); }
 
95
#ifdef HAVE_purify
 
96
  bool dummy;
 
97
  inline Sql_alloc() :dummy(0) {}
 
98
  inline ~Sql_alloc() {}
 
99
#else
 
100
  inline Sql_alloc() {}
 
101
  inline ~Sql_alloc() {}
 
102
#endif
 
103
 
 
104
};
 
105
 
 
106
 
70
107
/*
71
108
  Basic single linked list
72
109
  Used for item and item_buffs.
106
143
  list_node *first,**last;
107
144
 
108
145
public:
109
 
  uint32_t elements;
 
146
  uint elements;
110
147
 
111
148
  inline void empty() { elements=0; first= &end_of_list; last=&first;}
112
149
  inline base_list() { empty(); }
257
294
  {
258
295
    base_list *list= this;
259
296
    list_node *node= first;
260
 
    uint32_t cnt= 0;
 
297
    uint cnt= 0;
261
298
 
262
299
    while (node->next != &end_of_list)
263
300
    {
297
334
protected:
298
335
  base_list *list;
299
336
  list_node **el,**prev,*current;
300
 
  void sublist(base_list &ls, uint32_t elm)
 
337
  void sublist(base_list &ls, uint elm)
301
338
  {
302
339
    ls.first= *el;
303
340
    ls.last= list->last;
442
479
  inline void init(List<T> &a) { base_list_iterator::init(a); }
443
480
  inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); }
444
481
  inline void rewind(void)  { base_list_iterator::rewind(); }
445
 
  void sublist(List<T> &list_arg, uint32_t el_arg)
 
482
  void sublist(List<T> &list_arg, uint el_arg)
446
483
  {
447
484
    base_list_iterator::sublist(list_arg, el_arg);
448
485
  }
451
488
 
452
489
/*
453
490
  A simple intrusive list which automaticly removes element from list
454
 
  on delete (for Session element)
 
491
  on delete (for THD element)
455
492
*/
456
493
 
457
494
struct ilink
464
501
  static void operator delete(void* ptr_arg,
465
502
                              size_t size __attribute__((unused)))
466
503
  {
467
 
     free((unsigned char*)ptr_arg);
 
504
     my_free((uchar*)ptr_arg, MYF(MY_WME|MY_ALLOW_ZERO_PTR));
468
505
  }
469
506
 
470
507
  inline ilink()
599
636
  Evidently not all template arguments have clone() method with
600
637
  the right signature.
601
638
 
602
 
  @return You must query the error state in Session for out-of-memory
 
639
  @return You must query the error state in THD for out-of-memory
603
640
  situation after calling this function.
604
641
*/
605
642
 
615
652
    it.replace(el->clone(mem_root));
616
653
}
617
654
 
618
 
#endif // DRIZZLED_SQL_LIST_H
 
655
#endif // INCLUDES_DRIZZLE_SQL_LIST_H