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