1// SuperTux
2// Copyright (C) 2007 Matthias Braun <matze@braunis.de>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
16
17#ifndef HEADER_SUPERTUX_UTIL_OBSTACKPP_HPP
18#define HEADER_SUPERTUX_UTIL_OBSTACKPP_HPP
19
20#include <obstack.h>
21
22inline void*
23operator new (size_t bytes, struct obstack& obst)
24{
25 return obstack_alloc(&obst, static_cast<int>(bytes));
26}
27
28inline void*
29operator new[] (size_t bytes, struct obstack& obst)
30{
31 return obstack_alloc(&obst, static_cast<int>(bytes));
32}
33
34inline void
35operator delete (void* obj, struct obstack& obst)
36{
37 obstack_free(&obst, static_cast<char*>(obj));
38}
39
40inline void
41operator delete[] (void* obj, struct obstack& obst)
42{
43 obstack_free(&obst, static_cast<char*>(obj));
44}
45
46static inline void* obstack_chunk_alloc(size_t size)
47{
48 return new char[size];
49}
50
51static inline void obstack_chunk_free(void* data)
52{
53 char* ptr = static_cast<char*>(data);
54 delete[] ptr;
55}
56
57#endif
58
59/* EOF */
60