6c345f5514bb4da2226e76c6ffb349eb9a0af2fa
[supertux.git] / src / obstack / obstackpp.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2007 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20 #ifndef OBSTACKPP_H_
21 #define OBSTACKPP_H_
22
23 #include "obstack.h"
24
25 inline void*
26 operator new (size_t bytes, struct obstack& obst)
27 {
28   return obstack_alloc(&obst, bytes);
29 }
30
31 inline void*
32 operator new[] (size_t bytes, struct obstack& obst)
33 {
34   return obstack_alloc(&obst, bytes);
35 }
36
37 static inline void* obstack_chunk_alloc(size_t size)
38 {
39   return new char[size];
40 }
41
42 static inline void obstack_chunk_free(void* data)
43 {
44   char* ptr = static_cast<char*> (data);
45   delete[] ptr;
46 }
47
48 #endif
49