~centralelyon2010/inkscape/imagelinks2

1 by mental
moving trunk for module inkscape
1
/*
2
 * Inkscape::GC::Alloc - GC-aware STL allocator
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
 *
13
 */
14
15
#ifndef SEEN_INKSCAPE_GC_ALLOC_H
16
#define SEEN_INKSCAPE_GC_ALLOC_H
17
18
#include <limits>
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
19
#include <cstddef>
1 by mental
moving trunk for module inkscape
20
#include "gc-core.h"
21
22
namespace Inkscape {
23
24
namespace GC {
25
26
template <typename T, CollectionPolicy collect>
27
class Alloc {
28
public:
29
    typedef T value_type;
30
    typedef T *pointer;
31
    typedef T const *const_pointer;
32
    typedef T &reference;
33
    typedef T const &const_reference;
34
    typedef std::size_t size_type;
35
    typedef std::ptrdiff_t difference_type;
36
37
    template <typename U>
38
    struct rebind { typedef Alloc<U, collect> other; };
39
40
    Alloc() {}
41
    template <typename U> Alloc(Alloc<U, collect> const &) {}
42
43
    pointer address(reference r) { return &r; }
44
    const_pointer address(const_reference r) { return &r; }
45
46
    size_type max_size() const {
47
        return std::numeric_limits<std::size_t>::max() / sizeof(T);
48
    }
49
50
    pointer allocate(size_type count, void const * =NULL) {
51
        return static_cast<pointer>(::operator new(count * sizeof(T), SCANNED, collect));
52
    }
53
54
    void construct(pointer p, const_reference value) {
55
        new (static_cast<void *>(p)) T(value);
56
    }
57
    void destroy(pointer p) { p->~T(); }
58
59
    void deallocate(pointer p, size_type) { ::operator delete(p, GC); }
60
};
61
62
// allocators with the same collection policy are interchangable
63
64
template <typename T1, typename T2,
65
          CollectionPolicy collect1, CollectionPolicy collect2>
66
bool operator==(Alloc<T1, collect1> const &, Alloc<T2, collect2> const &) {
67
    return collect1 == collect2;
68
}
69
70
template <typename T1, typename T2,
71
          CollectionPolicy collect1, CollectionPolicy collect2>
72
bool operator!=(Alloc<T1, collect1> const &, Alloc<T2, collect2> const &) {
73
    return collect1 != collect2;
74
}
75
76
}
77
78
}
79
80
#endif
81
/*
82
  Local Variables:
83
  mode:c++
84
  c-file-style:"stroustrup"
85
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
86
  indent-tabs-mode:nil
87
  fill-column:99
88
  End:
89
*/
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
90
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :