~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/query_arena.h

  • Committer: Brian Aker
  • Date: 2009-06-11 22:06:29 UTC
  • mfrom: (1055.2.24 working)
  • Revision ID: brian@gaz-20090611220629-ct55qcmaiiuxrjaq
Merge Jay

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
 
 
21
 
#ifndef DRIZZLED_QUERY_ARENA_H
22
 
#define DRIZZLED_QUERY_ARENA_H
23
 
 
24
 
#include <mysys/my_alloc.h>
25
 
 
26
 
class Item;
27
 
 
28
 
class Query_arena
29
 
{
30
 
public:
31
 
  /*
32
 
    List of items created in the parser for this query. Every item puts
33
 
    itself to the list on creation (see Item::Item() for details))
34
 
  */
35
 
  Item *free_list;
36
 
  MEM_ROOT *mem_root;                   // Pointer to current memroot
37
 
 
38
 
  Query_arena(MEM_ROOT *mem_root_arg) :
39
 
    free_list(0), mem_root(mem_root_arg)
40
 
  { }
41
 
  /*
42
 
    This constructor is used only when Query_arena is created as
43
 
    backup storage for another instance of Query_arena.
44
 
  */
45
 
  Query_arena() { }
46
 
 
47
 
  virtual ~Query_arena() {};
48
 
 
49
 
  inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
50
 
  inline void* calloc(size_t size)
51
 
  {
52
 
    void *ptr;
53
 
    if ((ptr=alloc_root(mem_root,size)))
54
 
      memset(ptr, 0, size);
55
 
    return ptr;
56
 
  }
57
 
  inline char *strdup(const char *str)
58
 
  { return strdup_root(mem_root,str); }
59
 
  inline char *strmake(const char *str, size_t size)
60
 
  { return strmake_root(mem_root,str,size); }
61
 
  inline void *memdup(const void *str, size_t size)
62
 
  { return memdup_root(mem_root,str,size); }
63
 
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
64
 
  {
65
 
    void *ptr;
66
 
    if ((ptr= alloc_root(mem_root,size+gap)))
67
 
      memcpy(ptr,str,size);
68
 
    return ptr;
69
 
  }
70
 
 
71
 
  void free_items()
72
 
  {
73
 
    Item *next;
74
 
    /* This works because items are allocated with sql_alloc() */
75
 
    for (; free_list; free_list= next)
76
 
    {
77
 
      next= free_list->next;
78
 
      free_list->delete_self();
79
 
    }
80
 
    /* Postcondition: free_list is 0 */
81
 
    return;
82
 
  }
83
 
};
84
 
 
85
 
 
86
 
#endif /* DRIZZLED_QUERY_ARENA_H */