Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
share.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Inkscape::Util::ptr_shared<T> - like T const *, but stronger.
4 * Used to hold c-style strings for objects that are managed by the gc.
5 *
6 * Authors:
7 * MenTaLguY <mental@rydia.net>
8 *
9 * Copyright (C) 2006 MenTaLguY
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14#include "util/share.h"
15#include <glib.h>
16
17namespace Inkscape {
18namespace Util {
19
20ptr_shared share_string(char const *string) {
21 g_return_val_if_fail(string != nullptr, share_unsafe(nullptr));
22 return share_string(string, std::strlen(string));
23}
24
25ptr_shared share_string(char const *string, std::size_t length) {
26 g_return_val_if_fail(string != nullptr, share_unsafe(nullptr));
27 char *new_string=new (GC::ATOMIC) char[length+1];
28 std::memcpy(new_string, string, length);
29 new_string[length] = 0;
30 return share_unsafe(new_string);
31}
32
33}
34}
35
36/*
37 Local Variables:
38 mode:c++
39 c-file-style:"stroustrup"
40 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
41 indent-tabs-mode:nil
42 fill-column:99
43 End:
44*/
45// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Miscellaneous supporting code.
Definition document.h:93
ptr_shared share_unsafe(char const *string)
Definition share.h:90
ptr_shared share_string(char const *string)
Definition share.cpp:20
Helper class to stream background task notifications as a series of messages.