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 	 * Frees all strings contained within the #GStringChunk.
65 	 * After calling g_string_chunk_clear() it is not safe to
66 	 * access any of the strings which were contained within it.
67 	 *
68 	 * Since: 2.14
69 	 */
70 	public void clear()
71 	{
72 		g_string_chunk_clear(gStringChunk);
73 	}
74 
75 	/**
76 	 * Frees all memory allocated by the #GStringChunk.
77 	 * After calling g_string_chunk_free() it is not safe to
78 	 * access any of the strings which were contained within it.
79 	 */
80 	public void free()
81 	{
82 		g_string_chunk_free(gStringChunk);
83 	}
84 
85 	/**
86 	 * Adds a copy of @string to the #GStringChunk.
87 	 * It returns a pointer to the new copy of the string
88 	 * in the #GStringChunk. The characters in the string
89 	 * can be changed, if necessary, though you should not
90 	 * change anything after the end of the string.
91 	 *
92 	 * Unlike g_string_chunk_insert_const(), this function
93 	 * does not check for duplicates. Also strings added
94 	 * with g_string_chunk_insert() will not be searched
95 	 * by g_string_chunk_insert_const() when looking for
96 	 * duplicates.
97 	 *
98 	 * Params:
99 	 *     str = the string to add
100 	 *
101 	 * Return: a pointer to the copy of @string within
102 	 *     the #GStringChunk
103 	 */
104 	public string insert(string str)
105 	{
106 		return Str.toString(g_string_chunk_insert(gStringChunk, Str.toStringz(str)));
107 	}
108 
109 	/**
110 	 * Adds a copy of @string to the #GStringChunk, unless the same
111 	 * string has already been added to the #GStringChunk with
112 	 * g_string_chunk_insert_const().
113 	 *
114 	 * This function is useful if you need to copy a large number
115 	 * of strings but do not want to waste space storing duplicates.
116 	 * But you must remember that there may be several pointers to
117 	 * the same string, and so any changes made to the strings
118 	 * should be done very carefully.
119 	 *
120 	 * Note that g_string_chunk_insert_const() will not return a
121 	 * pointer to a string added with g_string_chunk_insert(), even
122 	 * if they do match.
123 	 *
124 	 * Params:
125 	 *     str = the string to add
126 	 *
127 	 * Return: a pointer to the new or existing copy of @string
128 	 *     within the #GStringChunk
129 	 */
130 	public string insertConst(string str)
131 	{
132 		return Str.toString(g_string_chunk_insert_const(gStringChunk, Str.toStringz(str)));
133 	}
134 
135 	/**
136 	 * Adds a copy of the first @len bytes of @string to the #GStringChunk.
137 	 * The copy is nul-terminated.
138 	 *
139 	 * Since this function does not stop at nul bytes, it is the caller's
140 	 * responsibility to ensure that @string has at least @len addressable
141 	 * bytes.
142 	 *
143 	 * The characters in the returned string can be changed, if necessary,
144 	 * though you should not change anything after the end of the string.
145 	 *
146 	 * Params:
147 	 *     str = bytes to insert
148 	 *     len = number of bytes of @string to insert, or -1 to insert a
149 	 *         nul-terminated string
150 	 *
151 	 * Return: a pointer to the copy of @string within the #GStringChunk
152 	 *
153 	 * Since: 2.4
154 	 */
155 	public string insertLen(string str, ptrdiff_t len)
156 	{
157 		return Str.toString(g_string_chunk_insert_len(gStringChunk, Str.toStringz(str), len));
158 	}
159 
160 	/**
161 	 * Creates a new #GStringChunk.
162 	 *
163 	 * Params:
164 	 *     size = the default size of the blocks of memory which are
165 	 *         allocated to store the strings. If a particular string
166 	 *         is larger than this default size, a larger block of
167 	 *         memory will be allocated for it.
168 	 *
169 	 * Return: a new #GStringChunk
170 	 *
171 	 * Throws: ConstructionException GTK+ fails to create the object.
172 	 */
173 	public this(size_t size)
174 	{
175 		auto p = g_string_chunk_new(size);
176 		
177 		if(p is null)
178 		{
179 			throw new ConstructionException("null returned by new");
180 		}
181 		
182 		this(cast(GStringChunk*) p);
183 	}
184 }