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 
42 	/** Get the main Gtk struct */
43 	public GStringChunk* getStringChunkStruct()
44 	{
45 		return gStringChunk;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected void* getStruct()
50 	{
51 		return cast(void*)gStringChunk;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (GStringChunk* gStringChunk)
58 	{
59 		this.gStringChunk = gStringChunk;
60 	}
61 
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 		return Str.toString(g_string_chunk_insert(gStringChunk, Str.toStringz(str)));
109 	}
110 
111 	/**
112 	 * Adds a copy of @string to the #GStringChunk, unless the same
113 	 * string has already been added to the #GStringChunk with
114 	 * g_string_chunk_insert_const().
115 	 *
116 	 * This function is useful if you need to copy a large number
117 	 * of strings but do not want to waste space storing duplicates.
118 	 * But you must remember that there may be several pointers to
119 	 * the same string, and so any changes made to the strings
120 	 * should be done very carefully.
121 	 *
122 	 * Note that g_string_chunk_insert_const() will not return a
123 	 * pointer to a string added with g_string_chunk_insert(), even
124 	 * if they do match.
125 	 *
126 	 * Params:
127 	 *     str = the string to add
128 	 *
129 	 * Return: a pointer to the new or existing copy of @string
130 	 *     within the #GStringChunk
131 	 */
132 	public string insertConst(string str)
133 	{
134 		return Str.toString(g_string_chunk_insert_const(gStringChunk, Str.toStringz(str)));
135 	}
136 
137 	/**
138 	 * Adds a copy of the first @len bytes of @string to the #GStringChunk.
139 	 * The copy is nul-terminated.
140 	 *
141 	 * Since this function does not stop at nul bytes, it is the caller's
142 	 * responsibility to ensure that @string has at least @len addressable
143 	 * bytes.
144 	 *
145 	 * The characters in the returned string can be changed, if necessary,
146 	 * though you should not change anything after the end of the string.
147 	 *
148 	 * Params:
149 	 *     str = bytes to insert
150 	 *     len = number of bytes of @string to insert, or -1 to insert a
151 	 *         nul-terminated string
152 	 *
153 	 * Return: a pointer to the copy of @string within the #GStringChunk
154 	 *
155 	 * Since: 2.4
156 	 */
157 	public string insertLen(string str, ptrdiff_t len)
158 	{
159 		return Str.toString(g_string_chunk_insert_len(gStringChunk, Str.toStringz(str), len));
160 	}
161 
162 	/**
163 	 * Creates a new #GStringChunk.
164 	 *
165 	 * Params:
166 	 *     size = the default size of the blocks of memory which are
167 	 *         allocated to store the strings. If a particular string
168 	 *         is larger than this default size, a larger block of
169 	 *         memory will be allocated for it.
170 	 *
171 	 * Return: a new #GStringChunk
172 	 *
173 	 * Throws: ConstructionException GTK+ fails to create the object.
174 	 */
175 	public this(size_t size)
176 	{
177 		auto p = g_string_chunk_new(size);
178 		
179 		if(p is null)
180 		{
181 			throw new ConstructionException("null returned by new");
182 		}
183 		
184 		this(cast(GStringChunk*) p);
185 	}
186 }