~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/gc-alloc.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
19
#include "gc-core.h"
 
20
 
 
21
namespace Inkscape {
 
22
 
 
23
namespace GC {
 
24
 
 
25
template <typename T, CollectionPolicy collect>
 
26
class Alloc {
 
27
public:
 
28
    typedef T value_type;
 
29
    typedef T *pointer;
 
30
    typedef T const *const_pointer;
 
31
    typedef T &reference;
 
32
    typedef T const &const_reference;
 
33
    typedef std::size_t size_type;
 
34
    typedef std::ptrdiff_t difference_type;
 
35
 
 
36
    template <typename U>
 
37
    struct rebind { typedef Alloc<U, collect> other; };
 
38
 
 
39
    Alloc() {}
 
40
    template <typename U> Alloc(Alloc<U, collect> const &) {}
 
41
 
 
42
    pointer address(reference r) { return &r; }
 
43
    const_pointer address(const_reference r) { return &r; }
 
44
 
 
45
    size_type max_size() const {
 
46
        return std::numeric_limits<std::size_t>::max() / sizeof(T);
 
47
    }
 
48
 
 
49
    pointer allocate(size_type count, void const * =NULL) {
 
50
        return static_cast<pointer>(::operator new(count * sizeof(T), SCANNED, collect));
 
51
    }
 
52
 
 
53
    void construct(pointer p, const_reference value) {
 
54
        new (static_cast<void *>(p)) T(value);
 
55
    }
 
56
    void destroy(pointer p) { p->~T(); }
 
57
 
 
58
    void deallocate(pointer p, size_type) { ::operator delete(p, GC); }
 
59
};
 
60
 
 
61
// allocators with the same collection policy are interchangable
 
62
 
 
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;
 
67
}
 
68
 
 
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;
 
73
}
 
74
 
 
75
}
 
76
 
 
77
}
 
78
 
 
79
#endif
 
80
/*
 
81
  Local Variables:
 
82
  mode:c++
 
83
  c-file-style:"stroustrup"
 
84
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
85
  indent-tabs-mode:nil
 
86
  fill-column:99
 
87
  End:
 
88
*/
 
89
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :