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 
63 private import glib.Str;
64 private import gtkc.paths;
65 private import gtkc.Loader;
66 
67 
68 
69 
70 /**
71  * String chunks are used to store groups of strings. Memory is
72  * allocated in blocks, and as strings are added to the GStringChunk
73  * they are copied into the next free position in a block. When a block
74  * is full a new block is allocated.
75  *
76  * When storing a large number of strings, string chunks are more
77  * efficient than using g_strdup() since fewer calls to malloc() are
78  * needed, and less memory is wasted in memory allocation overheads.
79  *
80  * By adding strings with g_string_chunk_insert_const() it is also
81  * possible to remove duplicates.
82  *
83  * To create a new GStringChunk use g_string_chunk_new().
84  *
85  * To add strings to a GStringChunk use g_string_chunk_insert().
86  *
87  * To add strings to a GStringChunk, but without duplicating strings
88  * which are already in the GStringChunk, use
89  * g_string_chunk_insert_const().
90  *
91  * To free the entire GStringChunk use g_string_chunk_free(). It is
92  * not possible to free individual strings.
93  */
94 public class StringGChunk
95 {
96 	
97 	/** the main Gtk struct */
98 	protected GStringChunk* gStringChunk;
99 	
100 	
101 	public GStringChunk* getStringGChunkStruct()
102 	{
103 		return gStringChunk;
104 	}
105 	
106 	
107 	/** the main Gtk struct as a void* */
108 	protected void* getStruct()
109 	{
110 		return cast(void*)gStringChunk;
111 	}
112 	
113 	/**
114 	 * Sets our main struct and passes it to the parent class
115 	 */
116 	public this (GStringChunk* gStringChunk)
117 	{
118 		this.gStringChunk = gStringChunk;
119 	}
120 	
121 	~this ()
122 	{
123 		if (  Linker.isLoaded(LIBRARY.GLIB) && gStringChunk !is null )
124 		{
125 			g_string_chunk_free(gStringChunk);
126 		}
127 	}
128 	
129 	/**
130 	 */
131 	
132 	/**
133 	 * Creates a new GStringChunk.
134 	 * Params:
135 	 * size = the default size of the blocks of memory which are
136 	 * allocated to store the strings. If a particular string
137 	 * is larger than this default size, a larger block of
138 	 * memory will be allocated for it.
139 	 * Throws: ConstructionException GTK+ fails to create the object.
140 	 */
141 	public this (gsize size)
142 	{
143 		// GStringChunk * g_string_chunk_new (gsize size);
144 		auto p = g_string_chunk_new(size);
145 		if(p is null)
146 		{
147 			throw new ConstructionException("null returned by g_string_chunk_new(size)");
148 		}
149 		this(cast(GStringChunk*) p);
150 	}
151 	
152 	/**
153 	 * Adds a copy of string to the GStringChunk.
154 	 * It returns a pointer to the new copy of the string
155 	 * in the GStringChunk. The characters in the string
156 	 * can be changed, if necessary, though you should not
157 	 * change anything after the end of the string.
158 	 * Unlike g_string_chunk_insert_const(), this function
159 	 * does not check for duplicates. Also strings added
160 	 * with g_string_chunk_insert() will not be searched
161 	 * by g_string_chunk_insert_const() when looking for
162 	 * duplicates.
163 	 * Params:
164 	 * string = the string to add
165 	 * Returns: a pointer to the copy of string within the GStringChunk
166 	 */
167 	public string insert(string string)
168 	{
169 		// gchar * g_string_chunk_insert (GStringChunk *chunk,  const gchar *string);
170 		return Str.toString(g_string_chunk_insert(gStringChunk, Str.toStringz(string)));
171 	}
172 	
173 	/**
174 	 * Adds a copy of string to the GStringChunk, unless the same
175 	 * string has already been added to the GStringChunk with
176 	 * g_string_chunk_insert_const().
177 	 * This function is useful if you need to copy a large number
178 	 * of strings but do not want to waste space storing duplicates.
179 	 * But you must remember that there may be several pointers to
180 	 * the same string, and so any changes made to the strings
181 	 * should be done very carefully.
182 	 * Note that g_string_chunk_insert_const() will not return a
183 	 * pointer to a string added with g_string_chunk_insert(), even
184 	 * if they do match.
185 	 * Params:
186 	 * string = the string to add
187 	 * Returns: a pointer to the new or existing copy of string within the GStringChunk
188 	 */
189 	public string insertConst(string string)
190 	{
191 		// gchar * g_string_chunk_insert_const (GStringChunk *chunk,  const gchar *string);
192 		return Str.toString(g_string_chunk_insert_const(gStringChunk, Str.toStringz(string)));
193 	}
194 	
195 	/**
196 	 * Adds a copy of the first len bytes of string to the GStringChunk.
197 	 * The copy is nul-terminated.
198 	 * Since this function does not stop at nul bytes, it is the caller's
199 	 * responsibility to ensure that string has at least len addressable
200 	 * bytes.
201 	 * The characters in the returned string can be changed, if necessary,
202 	 * though you should not change anything after the end of the string.
203 	 * Since 2.4
204 	 * Params:
205 	 * string = bytes to insert
206 	 * len = number of bytes of string to insert, or -1 to insert a
207 	 * nul-terminated string
208 	 * Returns: a pointer to the copy of string within the GStringChunk
209 	 */
210 	public string insertLen(string string, gssize len)
211 	{
212 		// gchar * g_string_chunk_insert_len (GStringChunk *chunk,  const gchar *string,  gssize len);
213 		return Str.toString(g_string_chunk_insert_len(gStringChunk, Str.toStringz(string), len));
214 	}
215 	
216 	/**
217 	 * Frees all strings contained within the GStringChunk.
218 	 * After calling g_string_chunk_clear() it is not safe to
219 	 * access any of the strings which were contained within it.
220 	 * Since 2.14
221 	 */
222 	public void clear()
223 	{
224 		// void g_string_chunk_clear (GStringChunk *chunk);
225 		g_string_chunk_clear(gStringChunk);
226 	}
227 	
228 	/**
229 	 * Frees all memory allocated by the GStringChunk.
230 	 * After calling g_string_chunk_free() it is not safe to
231 	 * access any of the strings which were contained within it.
232 	 */
233 	public void free()
234 	{
235 		// void g_string_chunk_free (GStringChunk *chunk);
236 		g_string_chunk_free(gStringChunk);
237 	}
238 }