~drizzle-trunk/drizzle/development

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