source: appstream-generator/build/girepo/glib/StringChunk.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 5.3 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.StringChunk;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ConstructionException;
26private import glib.Str;
27
28
29/**
30 * An opaque data structure representing String Chunks.
31 * It should only be accessed by using the following functions.
32 */
33public class StringChunk
34{
35        /** the main Gtk struct */
36        protected GStringChunk* gStringChunk;
37        protected bool ownedRef;
38
39        /** Get the main Gtk struct */
40        public GStringChunk* getStringChunkStruct()
41        {
42                return gStringChunk;
43        }
44
45        /** the main Gtk struct as a void* */
46        protected void* getStruct()
47        {
48                return cast(void*)gStringChunk;
49        }
50
51        /**
52         * Sets our main struct and passes it to the parent class.
53         */
54        public this (GStringChunk* gStringChunk, bool ownedRef = false)
55        {
56                this.gStringChunk = gStringChunk;
57                this.ownedRef = ownedRef;
58        }
59
60
61        /**
62         * Frees all strings contained within the #GStringChunk.
63         * After calling g_string_chunk_clear() it is not safe to
64         * access any of the strings which were contained within it.
65         *
66         * Since: 2.14
67         */
68        public void clear()
69        {
70                g_string_chunk_clear(gStringChunk);
71        }
72
73        /**
74         * Frees all memory allocated by the #GStringChunk.
75         * After calling g_string_chunk_free() it is not safe to
76         * access any of the strings which were contained within it.
77         */
78        public void free()
79        {
80                g_string_chunk_free(gStringChunk);
81        }
82
83        /**
84         * Adds a copy of @string to the #GStringChunk.
85         * It returns a pointer to the new copy of the string
86         * in the #GStringChunk. The characters in the string
87         * can be changed, if necessary, though you should not
88         * change anything after the end of the string.
89         *
90         * Unlike g_string_chunk_insert_const(), this function
91         * does not check for duplicates. Also strings added
92         * with g_string_chunk_insert() will not be searched
93         * by g_string_chunk_insert_const() when looking for
94         * duplicates.
95         *
96         * Params:
97         *     str = the string to add
98         *
99         * Returns: a pointer to the copy of @string within
100         *     the #GStringChunk
101         */
102        public string insert(string str)
103        {
104                auto retStr = g_string_chunk_insert(gStringChunk, Str.toStringz(str));
105               
106                scope(exit) Str.freeString(retStr);
107                return Str.toString(retStr);
108        }
109
110        /**
111         * Adds a copy of @string to the #GStringChunk, unless the same
112         * string has already been added to the #GStringChunk with
113         * g_string_chunk_insert_const().
114         *
115         * This function is useful if you need to copy a large number
116         * of strings but do not want to waste space storing duplicates.
117         * But you must remember that there may be several pointers to
118         * the same string, and so any changes made to the strings
119         * should be done very carefully.
120         *
121         * Note that g_string_chunk_insert_const() will not return a
122         * pointer to a string added with g_string_chunk_insert(), even
123         * if they do match.
124         *
125         * Params:
126         *     str = the string to add
127         *
128         * Returns: a pointer to the new or existing copy of @string
129         *     within the #GStringChunk
130         */
131        public string insertConst(string str)
132        {
133                auto retStr = g_string_chunk_insert_const(gStringChunk, Str.toStringz(str));
134               
135                scope(exit) Str.freeString(retStr);
136                return Str.toString(retStr);
137        }
138
139        /**
140         * Adds a copy of the first @len bytes of @string to the #GStringChunk.
141         * The copy is nul-terminated.
142         *
143         * Since this function does not stop at nul bytes, it is the caller's
144         * responsibility to ensure that @string has at least @len addressable
145         * bytes.
146         *
147         * The characters in the returned string can be changed, if necessary,
148         * though you should not change anything after the end of the string.
149         *
150         * Params:
151         *     str = bytes to insert
152         *     len = number of bytes of @string to insert, or -1 to insert a
153         *         nul-terminated string
154         *
155         * Returns: a pointer to the copy of @string within the #GStringChunk
156         *
157         * Since: 2.4
158         */
159        public string insertLen(string str, ptrdiff_t len)
160        {
161                auto retStr = g_string_chunk_insert_len(gStringChunk, Str.toStringz(str), len);
162               
163                scope(exit) Str.freeString(retStr);
164                return Str.toString(retStr);
165        }
166
167        /**
168         * Creates a new #GStringChunk.
169         *
170         * Params:
171         *     size = the default size of the blocks of memory which are
172         *         allocated to store the strings. If a particular string
173         *         is larger than this default size, a larger block of
174         *         memory will be allocated for it.
175         *
176         * Returns: a new #GStringChunk
177         *
178         * Throws: ConstructionException GTK+ fails to create the object.
179         */
180        public this(size_t size)
181        {
182                auto p = g_string_chunk_new(size);
183               
184                if(p is null)
185                {
186                        throw new ConstructionException("null returned by new");
187                }
188               
189                this(cast(GStringChunk*) p);
190        }
191}
Note: See TracBrowser for help on using the repository browser.