1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-String-Chunks.html
27  * outPack = glib
28  * outFile = StringGChunk
29  * strct   = GStringChunk
30  * realStrct=
31  * ctorStrct=
32  * clss    = StringGChunk
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_string_chunk_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gtkc.paths
48  * 	- gtkc.Loader
49  * structWrap:
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.StringGChunk;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 private import glib.Str;
63 private import gtkc.paths;
64 private import gtkc.Loader;
65 
66 
67 
68 /**
69  * String chunks are used to store groups of strings. Memory is
70  * allocated in blocks, and as strings are added to the GStringChunk
71  * they are copied into the next free position in a block. When a block
72  * is full a new block is allocated.
73  *
74  * When storing a large number of strings, string chunks are more
75  * efficient than using g_strdup() since fewer calls to malloc() are
76  * needed, and less memory is wasted in memory allocation overheads.
77  *
78  * By adding strings with g_string_chunk_insert_const() it is also
79  * possible to remove duplicates.
80  *
81  * To create a new GStringChunk use g_string_chunk_new().
82  *
83  * To add strings to a GStringChunk use g_string_chunk_insert().
84  *
85  * To add strings to a GStringChunk, but without duplicating strings
86  * which are already in the GStringChunk, use
87  * g_string_chunk_insert_const().
88  *
89  * To free the entire GStringChunk use g_string_chunk_free(). It is
90  * not possible to free individual strings.
91  */
92 public class StringGChunk
93 {
94 	
95 	/** the main Gtk struct */
96 	protected GStringChunk* gStringChunk;
97 	
98 	
99 	/** Get the main Gtk struct */
100 	public GStringChunk* getStringGChunkStruct()
101 	{
102 		return gStringChunk;
103 	}
104 	
105 	
106 	/** the main Gtk struct as a void* */
107 	protected void* getStruct()
108 	{
109 		return cast(void*)gStringChunk;
110 	}
111 	
112 	/**
113 	 * Sets our main struct and passes it to the parent class
114 	 */
115 	public this (GStringChunk* gStringChunk)
116 	{
117 		this.gStringChunk = gStringChunk;
118 	}
119 	
120 	~this ()
121 	{
122 		if (  Linker.isLoaded(LIBRARY.GLIB) && gStringChunk !is null )
123 		{
124 			g_string_chunk_free(gStringChunk);
125 		}
126 	}
127 	
128 	/**
129 	 */
130 	
131 	/**
132 	 * Creates a new GStringChunk.
133 	 * Params:
134 	 * size = the default size of the blocks of memory which are
135 	 * allocated to store the strings. If a particular string
136 	 * is larger than this default size, a larger block of
137 	 * memory will be allocated for it.
138 	 * Throws: ConstructionException GTK+ fails to create the object.
139 	 */
140 	public this (gsize size)
141 	{
142 		// GStringChunk * g_string_chunk_new (gsize size);
143 		auto p = g_string_chunk_new(size);
144 		if(p is null)
145 		{
146 			throw new ConstructionException("null returned by g_string_chunk_new(size)");
147 		}
148 		this(cast(GStringChunk*) p);
149 	}
150 	
151 	/**
152 	 * Adds a copy of string to the GStringChunk.
153 	 * It returns a pointer to the new copy of the string
154 	 * in the GStringChunk. The characters in the string
155 	 * can be changed, if necessary, though you should not
156 	 * change anything after the end of the string.
157 	 * Unlike g_string_chunk_insert_const(), this function
158 	 * does not check for duplicates. Also strings added
159 	 * with g_string_chunk_insert() will not be searched
160 	 * by g_string_chunk_insert_const() when looking for
161 	 * duplicates.
162 	 * Params:
163 	 * string = the string to add
164 	 * Returns: a pointer to the copy of string within the GStringChunk
165 	 */
166 	public string insert(string string)
167 	{
168 		// gchar * g_string_chunk_insert (GStringChunk *chunk,  const gchar *string);
169 		return Str.toString(g_string_chunk_insert(gStringChunk, Str.toStringz(string)));
170 	}
171 	
172 	/**
173 	 * Adds a copy of string to the GStringChunk, unless the same
174 	 * string has already been added to the GStringChunk with
175 	 * g_string_chunk_insert_const().
176 	 * This function is useful if you need to copy a large number
177 	 * of strings but do not want to waste space storing duplicates.
178 	 * But you must remember that there may be several pointers to
179 	 * the same string, and so any changes made to the strings
180 	 * should be done very carefully.
181 	 * Note that g_string_chunk_insert_const() will not return a
182 	 * pointer to a string added with g_string_chunk_insert(), even
183 	 * if they do match.
184 	 * Params:
185 	 * string = the string to add
186 	 * Returns: a pointer to the new or existing copy of string within the GStringChunk
187 	 */
188 	public string insertConst(string string)
189 	{
190 		// gchar * g_string_chunk_insert_const (GStringChunk *chunk,  const gchar *string);
191 		return Str.toString(g_string_chunk_insert_const(gStringChunk, Str.toStringz(string)));
192 	}
193 	
194 	/**
195 	 * Adds a copy of the first len bytes of string to the GStringChunk.
196 	 * The copy is nul-terminated.
197 	 * Since this function does not stop at nul bytes, it is the caller's
198 	 * responsibility to ensure that string has at least len addressable
199 	 * bytes.
200 	 * The characters in the returned string can be changed, if necessary,
201 	 * though you should not change anything after the end of the string.
202 	 * Since 2.4
203 	 * Params:
204 	 * string = bytes to insert
205 	 * len = number of bytes of string to insert, or -1 to insert a
206 	 * nul-terminated string
207 	 * Returns: a pointer to the copy of string within the GStringChunk
208 	 */
209 	public string insertLen(string string, gssize len)
210 	{
211 		// gchar * g_string_chunk_insert_len (GStringChunk *chunk,  const gchar *string,  gssize len);
212 		return Str.toString(g_string_chunk_insert_len(gStringChunk, Str.toStringz(string), len));
213 	}
214 	
215 	/**
216 	 * Frees all strings contained within the GStringChunk.
217 	 * After calling g_string_chunk_clear() it is not safe to
218 	 * access any of the strings which were contained within it.
219 	 * Since 2.14
220 	 */
221 	public void clear()
222 	{
223 		// void g_string_chunk_clear (GStringChunk *chunk);
224 		g_string_chunk_clear(gStringChunk);
225 	}
226 	
227 	/**
228 	 * Frees all memory allocated by the GStringChunk.
229 	 * After calling g_string_chunk_free() it is not safe to
230 	 * access any of the strings which were contained within it.
231 	 */
232 	public void free()
233 	{
234 		// void g_string_chunk_free (GStringChunk *chunk);
235 		g_string_chunk_free(gStringChunk);
236 	}
237 }