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 module glib.StringChunk;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gtkc.glib;
30 public  import gtkc.glibtypes;
31 
32 
33 /**
34  * An opaque data structure representing String Chunks.
35  * It should only be accessed by using the following functions.
36  */
37 public class StringChunk
38 {
39 	/** the main Gtk struct */
40 	protected GStringChunk* gStringChunk;
41 	protected bool ownedRef;
42 
43 	/** Get the main Gtk struct */
44 	public GStringChunk* getStringChunkStruct()
45 	{
46 		return gStringChunk;
47 	}
48 
49 	/** the main Gtk struct as a void* */
50 	protected void* getStruct()
51 	{
52 		return cast(void*)gStringChunk;
53 	}
54 
55 	/**
56 	 * Sets our main struct and passes it to the parent class.
57 	 */
58 	public this (GStringChunk* gStringChunk, bool ownedRef = false)
59 	{
60 		this.gStringChunk = gStringChunk;
61 		this.ownedRef = ownedRef;
62 	}
63 
64 
65 	/**
66 	 * Frees all strings contained within the #GStringChunk.
67 	 * After calling g_string_chunk_clear() it is not safe to
68 	 * access any of the strings which were contained within it.
69 	 *
70 	 * Since: 2.14
71 	 */
72 	public void clear()
73 	{
74 		g_string_chunk_clear(gStringChunk);
75 	}
76 
77 	/**
78 	 * Frees all memory allocated by the #GStringChunk.
79 	 * After calling g_string_chunk_free() it is not safe to
80 	 * access any of the strings which were contained within it.
81 	 */
82 	public void free()
83 	{
84 		g_string_chunk_free(gStringChunk);
85 	}
86 
87 	/**
88 	 * Adds a copy of @string to the #GStringChunk.
89 	 * It returns a pointer to the new copy of the string
90 	 * in the #GStringChunk. The characters in the string
91 	 * can be changed, if necessary, though you should not
92 	 * change anything after the end of the string.
93 	 *
94 	 * Unlike g_string_chunk_insert_const(), this function
95 	 * does not check for duplicates. Also strings added
96 	 * with g_string_chunk_insert() will not be searched
97 	 * by g_string_chunk_insert_const() when looking for
98 	 * duplicates.
99 	 *
100 	 * Params:
101 	 *     str = the string to add
102 	 *
103 	 * Return: a pointer to the copy of @string within
104 	 *     the #GStringChunk
105 	 */
106 	public string insert(string str)
107 	{
108 		auto retStr = g_string_chunk_insert(gStringChunk, Str.toStringz(str));
109 		
110 		scope(exit) Str.freeString(retStr);
111 		return Str.toString(retStr);
112 	}
113 
114 	/**
115 	 * Adds a copy of @string to the #GStringChunk, unless the same
116 	 * string has already been added to the #GStringChunk with
117 	 * g_string_chunk_insert_const().
118 	 *
119 	 * This function is useful if you need to copy a large number
120 	 * of strings but do not want to waste space storing duplicates.
121 	 * But you must remember that there may be several pointers to
122 	 * the same string, and so any changes made to the strings
123 	 * should be done very carefully.
124 	 *
125 	 * Note that g_string_chunk_insert_const() will not return a
126 	 * pointer to a string added with g_string_chunk_insert(), even
127 	 * if they do match.
128 	 *
129 	 * Params:
130 	 *     str = the string to add
131 	 *
132 	 * Return: a pointer to the new or existing copy of @string
133 	 *     within the #GStringChunk
134 	 */
135 	public string insertConst(string str)
136 	{
137 		auto retStr = g_string_chunk_insert_const(gStringChunk, Str.toStringz(str));
138 		
139 		scope(exit) Str.freeString(retStr);
140 		return Str.toString(retStr);
141 	}
142 
143 	/**
144 	 * Adds a copy of the first @len bytes of @string to the #GStringChunk.
145 	 * The copy is nul-terminated.
146 	 *
147 	 * Since this function does not stop at nul bytes, it is the caller's
148 	 * responsibility to ensure that @string has at least @len addressable
149 	 * bytes.
150 	 *
151 	 * The characters in the returned string can be changed, if necessary,
152 	 * though you should not change anything after the end of the string.
153 	 *
154 	 * Params:
155 	 *     str = bytes to insert
156 	 *     len = number of bytes of @string to insert, or -1 to insert a
157 	 *         nul-terminated string
158 	 *
159 	 * Return: a pointer to the copy of @string within the #GStringChunk
160 	 *
161 	 * Since: 2.4
162 	 */
163 	public string insertLen(string str, ptrdiff_t len)
164 	{
165 		auto retStr = g_string_chunk_insert_len(gStringChunk, Str.toStringz(str), len);
166 		
167 		scope(exit) Str.freeString(retStr);
168 		return Str.toString(retStr);
169 	}
170 
171 	/**
172 	 * Creates a new #GStringChunk.
173 	 *
174 	 * Params:
175 	 *     size = the default size of the blocks of memory which are
176 	 *         allocated to store the strings. If a particular string
177 	 *         is larger than this default size, a larger block of
178 	 *         memory will be allocated for it.
179 	 *
180 	 * Return: a new #GStringChunk
181 	 *
182 	 * Throws: ConstructionException GTK+ fails to create the object.
183 	 */
184 	public this(size_t size)
185 	{
186 		auto p = g_string_chunk_new(size);
187 		
188 		if(p is null)
189 		{
190 			throw new ConstructionException("null returned by new");
191 		}
192 		
193 		this(cast(GStringChunk*) p);
194 	}
195 }