Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
gc-alloc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors:
6 * see git history
7 * MenTaLguY <mental@rydia.net>
8 *
9 * Copyright (C) 2018 Authors
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef SEEN_INKSCAPE_GC_ALLOC_H
14#define SEEN_INKSCAPE_GC_ALLOC_H
15
16#include <cstddef>
17#include "inkgc/gc-core.h"
18
19namespace Inkscape {
20
21namespace GC {
22
23template <typename T,
25 CollectionPolicy collect=AUTO>
26class Alloc {
27public:
28 typedef T value_type;
29 typedef T *pointer;
30 typedef std::size_t size_type;
31
32 template <typename U>
34
35 Alloc() = default;
36 template <typename U> Alloc(Alloc<U, scan, collect> const &) {}
37
38 pointer allocate(size_type count, void const * =nullptr) {
39 return static_cast<pointer>(::operator new(count * sizeof(T), scan, collect));
40 }
41
42 void deallocate(pointer p, size_type) { ::operator delete(p, GC); }
43};
44
45// allocators with the same scan and collection policy are interchangeable
46
47template <typename T1, typename T2,
48 ScanPolicy scan1, ScanPolicy scan2,
49 CollectionPolicy collect1, CollectionPolicy collect2>
50bool operator==(Alloc<T1, scan1, collect1> const &, Alloc<T2, scan2, collect2> const &) {
51 return collect1 == collect2 && scan1 == scan2;
52}
53
54template <typename T1, typename T2,
55 ScanPolicy scan1, ScanPolicy scan2,
56 CollectionPolicy collect1, CollectionPolicy collect2>
58 return collect1 != collect2 || scan1 != scan2;
59}
60
61}
62
63}
64
65#endif
66/*
67 Local Variables:
68 mode:c++
69 c-file-style:"stroustrup"
70 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
71 indent-tabs-mode:nil
72 fill-column:99
73 End:
74*/
75// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Alloc(Alloc< U, scan, collect > const &)
Definition gc-alloc.h:36
void deallocate(pointer p, size_type)
Definition gc-alloc.h:42
pointer allocate(size_type count, void const *=nullptr)
Definition gc-alloc.h:38
std::size_t size_type
Definition gc-alloc.h:30
Wrapper for Boehm GC.
bool operator!=(Alloc< T1, scan1, collect1 > const &, Alloc< T2, scan2, collect2 > const &)
Definition gc-alloc.h:57
Helper class to stream background task notifications as a series of messages.
Alloc< U, scan, collect > other
Definition gc-alloc.h:33