1 /** @file
2 * @brief Base class for GC-managed objects
3 */
4 /* Copyright 2004 MenTaLguY <mental@rydia.net>
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 * See the file COPYING for details.
12 */
14 #ifndef SEEN_INKSCAPE_GC_MANAGED_H
15 #define SEEN_INKSCAPE_GC_MANAGED_H
17 #include "gc-core.h"
19 namespace Inkscape {
21 namespace GC {
23 /** @brief A base class for objects for whom the normal new and delete
24 * operators should use the garbage-collected allocator
25 */
26 template <ScanPolicy default_scan=SCANNED,
27 CollectionPolicy default_collect=AUTO>
28 class Managed {
29 public:
30 void *operator new(std::size_t size,
31 ScanPolicy scan=default_scan,
32 CollectionPolicy collect=default_collect)
33 throw (std::bad_alloc)
34 {
35 return ::operator new(size, scan, collect);
36 }
38 void *operator new[](std::size_t size,
39 ScanPolicy scan=default_scan,
40 CollectionPolicy collect=default_collect)
41 throw (std::bad_alloc)
42 {
43 return ::operator new[](size, scan, collect);
44 }
46 void operator delete(void *p) { return ::operator delete(p, GC); }
47 };
49 }
51 }
53 #endif
54 /*
55 Local Variables:
56 mode:c++
57 c-file-style:"stroustrup"
58 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
59 indent-tabs-mode:nil
60 fill-column:99
61 End:
62 */
63 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :