alternative to assert
[gtkD.git] / gtkD / src / glib / StringGChunk.d
blobdb9d7ae169d28ed74f66fb5dfadbd159e76fc237
1 /*
2 * This file is part of gtkD.
4 * gtkD 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 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD 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.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-String-Chunks.html
26 * outPack = glib
27 * outFile = StringGChunk
28 * strct = GStringChunk
29 * realStrct=
30 * ctorStrct=
31 * clss = StringGChunk
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_string_chunk_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Str
45 * structWrap:
46 * module aliases:
47 * local aliases:
50 module glib.StringGChunk;
52 version(noAssert)
54 version(Tango)
56 import tango.io.Stdout; // use the tango loging?
60 private import gtkc.glibtypes;
62 private import gtkc.glib;
65 private import glib.Str;
70 /**
71 * Description
72 * String chunks are used to store groups of strings.
73 * Memory is allocated in blocks, and as strings are added to the GStringChunk
74 * they are copied into the next free position in a block. When a block is
75 * full a new block is allocated.
76 * When storing a large number of strings, string chunks are more efficient
77 * than using g_strdup() since fewer calls to malloc()
78 * are needed, and less memory is wasted in memory allocation overheads.
79 * By adding strings with g_string_chunk_insert_const() it is also possible
80 * to remove duplicates.
81 * To create a new GStringChunk use g_string_chunk_new().
82 * To add strings to a GStringChunk use g_string_chunk_insert().
83 * To add strings to a GStringChunk, but without duplicating strings which are
84 * already in the GStringChunk, use g_string_chunk_insert_const().
85 * To free the entire GStringChunk use g_string_chunk_free().
86 * It is not possible to free individual strings.
88 public class StringGChunk
91 /** the main Gtk struct */
92 protected GStringChunk* gStringChunk;
95 public GStringChunk* getStringGChunkStruct()
97 return gStringChunk;
101 /** the main Gtk struct as a void* */
102 protected void* getStruct()
104 return cast(void*)gStringChunk;
108 * Sets our main struct and passes it to the parent class
110 public this (GStringChunk* gStringChunk)
112 version(noAssert)
114 if ( gStringChunk is null )
116 int zero = 0;
117 version(Tango)
119 Stdout("struct gStringChunk is null on constructor").newline;
121 else
123 printf("struct gStringChunk is null on constructor");
125 zero = zero / zero;
128 else
130 assert(gStringChunk !is null, "struct gStringChunk is null on constructor");
132 this.gStringChunk = gStringChunk;
140 * Creates a new GStringChunk.
141 * Creates a new GStringChunk.
142 * size:
143 * the default size of the blocks of memory which are
144 * allocated to store the strings. If a particular string
145 * is larger than this default size, a larger block of
146 * memory will be allocated for it.
147 * Returns:
148 * a new GStringChunk
150 public this (uint size)
152 // GStringChunk* g_string_chunk_new (gsize size);
153 this(cast(GStringChunk*)g_string_chunk_new(size) );
157 * Adds a copy of string to the GStringChunk.
158 * It returns a pointer to the new copy of the string
159 * in the GStringChunk. The characters in the string
160 * can be changed, if necessary, though you should not
161 * change anything after the end of the string.
162 * Unlike g_string_chunk_insert_const(), this function
163 * does not check for duplicates. Also strings added
164 * with g_string_chunk_insert() will not be searched
165 * by g_string_chunk_insert_const() when looking for
166 * duplicates.
167 * Adds a copy of string to the GStringChunk.
168 * It returns a pointer to the new copy of the string in the GStringChunk.
169 * The characters in the string can be changed, if necessary, though you
170 * should not change anything after the end of the string.
171 * Unlike g_string_chunk_insert_const(), this function does not check for
172 * duplicates. Also strings added with g_string_chunk_insert() will not be
173 * searched by g_string_chunk_insert_const() when looking for duplicates.
174 * chunk:
175 * a GStringChunk
176 * string:
177 * the string to add
178 * Returns:
179 * a pointer to the copy of string within
180 * the GStringChunk.
182 public char[] insert(char[] string)
184 // gchar* g_string_chunk_insert (GStringChunk *chunk, const gchar *string);
185 return Str.toString(g_string_chunk_insert(gStringChunk, Str.toStringz(string)) );
189 * Adds a copy of string to the GStringChunk, unless
190 * the same string has already been added to the GStringChunk
191 * with g_string_chunk_insert_const().
192 * This function is useful if you need to copy a large number
193 * of strings but do not want to waste space storing duplicates.
194 * But you must remember that there may be several pointers to
195 * the same string, and so any changes made to the strings
196 * should be done very carefully.
197 * Note that g_string_chunk_insert_const() will not return a
198 * pointer to a string added with g_string_chunk_insert(), even
199 * if they do match.
200 * Adds a copy of string to the GStringChunk, unless the same string has
201 * already been added to the GStringChunk with g_string_chunk_insert_const().
202 * This function is useful if you need to copy a large number of strings
203 * but do not want to waste space storing duplicates. But you must remember
204 * that there may be several pointers to the same string, and so any changes
205 * made to the strings should be done very carefully.
206 * Note that g_string_chunk_insert_const() will not return a pointer to a string
207 * added with g_string_chunk_insert(), even if they do match.
208 * chunk:
209 * a GStringChunk
210 * string:
211 * the string to add
212 * Returns:
213 * a pointer to the new or existing copy of string
214 * within the GStringChunk
216 public char[] insertConst(char[] string)
218 // gchar* g_string_chunk_insert_const (GStringChunk *chunk, const gchar *string);
219 return Str.toString(g_string_chunk_insert_const(gStringChunk, Str.toStringz(string)) );
223 * Adds a copy of the first len bytes of string to the GStringChunk. The
224 * copy is nul-terminated.
225 * Since this function does not stop at nul bytes, it is the caller's
226 * responsibility to ensure that string has at least len addressable bytes.
227 * The characters in the returned string can be changed, if necessary, though
228 * you should not change anything after the end of the string.
229 * chunk:
230 * a GStringChunk
231 * string:
232 * bytes to insert
233 * len:
234 * number of bytes of string to insert, or -1 to insert a
235 * nul-terminated string.
236 * Returns:
237 * a pointer to the copy of string within the GStringChunk
238 * Since 2.4
240 public char[] insertLen(char[] string, int len)
242 // gchar* g_string_chunk_insert_len (GStringChunk *chunk, const gchar *string, gssize len);
243 return Str.toString(g_string_chunk_insert_len(gStringChunk, Str.toStringz(string), len) );
247 * Frees all strings contained within the GStringChunk.
248 * After calling g_string_chunk_clear() it is not safe to
249 * access any of the strings which were contained within it.
250 * chunk:
251 * a GStringChunk
252 * Since 2.14
254 public void clear()
256 // void g_string_chunk_clear (GStringChunk *chunk);
257 g_string_chunk_clear(gStringChunk);
261 * Frees all memory allocated by the GStringChunk.
262 * After calling g_string_chunk_free() it is not safe to
263 * access any of the strings which were contained within it.
264 * Frees all memory allocated by the GStringChunk.
265 * After calling g_string_chunk_free() it is not safe to
266 * access any of the strings which were contained within it.
267 * chunk:
268 * a GStringChunk
270 public void free()
272 // void g_string_chunk_free (GStringChunk *chunk);
273 g_string_chunk_free(gStringChunk);