From 35a96bde514a8897f6f0fcc41c5833bf63df2e2a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:29:01 +0200 Subject: Adding upstream version 1.0.2. Signed-off-by: Daniel Baumann --- src/inkgc/gc-alloc.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/inkgc/gc-alloc.h (limited to 'src/inkgc/gc-alloc.h') diff --git a/src/inkgc/gc-alloc.h b/src/inkgc/gc-alloc.h new file mode 100644 index 0000000..8935c12 --- /dev/null +++ b/src/inkgc/gc-alloc.h @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Inkscape::GC::Alloc - GC-aware STL allocator + *//* + * Authors: + * see git history + * MenTaLguY + * + * Copyright (C) 2018 Authors + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INKSCAPE_GC_ALLOC_H +#define SEEN_INKSCAPE_GC_ALLOC_H + +#include +#include +#include "inkgc/gc-core.h" + +namespace Inkscape { + +namespace GC { + +template +class Alloc { +public: + typedef T value_type; + typedef T *pointer; + typedef T const *const_pointer; + typedef T &reference; + typedef T const &const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template + struct rebind { typedef Alloc other; }; + + Alloc() = default; + template Alloc(Alloc const &) {} + + pointer address(reference r) { return &r; } + const_pointer address(const_reference r) { return &r; } + + size_type max_size() const { + return std::numeric_limits::max() / sizeof(T); + } + + pointer allocate(size_type count, void const * =nullptr) { + return static_cast(::operator new(count * sizeof(T), SCANNED, collect)); + } + + void construct(pointer p, const_reference value) { + new (static_cast(p)) T(value); + } + void destroy(pointer p) { p->~T(); } + + void deallocate(pointer p, size_type) { ::operator delete(p, GC); } +}; + +// allocators with the same collection policy are interchangeable + +template +bool operator==(Alloc const &, Alloc const &) { + return collect1 == collect2; +} + +template +bool operator!=(Alloc const &, Alloc const &) { + return collect1 != collect2; +} + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3