2
* Inkscape::GC::Alloc - GC-aware STL allocator
4
* Copyright 2004 MenTaLguY <mental@rydia.net>
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.
11
* See the file COPYING for details.
15
#ifndef SEEN_INKSCAPE_GC_ALLOC_H
16
#define SEEN_INKSCAPE_GC_ALLOC_H
25
template <typename T, CollectionPolicy collect>
30
typedef T const *const_pointer;
32
typedef T const &const_reference;
33
typedef std::size_t size_type;
34
typedef std::ptrdiff_t difference_type;
37
struct rebind { typedef Alloc<U, collect> other; };
40
template <typename U> Alloc(Alloc<U, collect> const &) {}
42
pointer address(reference r) { return &r; }
43
const_pointer address(const_reference r) { return &r; }
45
size_type max_size() const {
46
return std::numeric_limits<std::size_t>::max() / sizeof(T);
49
pointer allocate(size_type count, void const * =NULL) {
50
return static_cast<pointer>(::operator new(count * sizeof(T), SCANNED, collect));
53
void construct(pointer p, const_reference value) {
54
new (static_cast<void *>(p)) T(value);
56
void destroy(pointer p) { p->~T(); }
58
void deallocate(pointer p, size_type) { ::operator delete(p, GC); }
61
// allocators with the same collection policy are interchangable
63
template <typename T1, typename T2,
64
CollectionPolicy collect1, CollectionPolicy collect2>
65
bool operator==(Alloc<T1, collect1> const &, Alloc<T2, collect2> const &) {
66
return collect1 == collect2;
69
template <typename T1, typename T2,
70
CollectionPolicy collect1, CollectionPolicy collect2>
71
bool operator!=(Alloc<T1, collect1> const &, Alloc<T2, collect2> const &) {
72
return collect1 != collect2;
83
c-file-style:"stroustrup"
84
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
89
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :