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.StrvBuilder;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.c.functions;
30 public  import glib.c.types;
31 private import gtkd.Loader;
32 
33 
34 /**
35  * #GStrvBuilder is a method of easily building dynamically sized
36  * NULL-terminated string arrays.
37  * 
38  * The following example shows how to build a two element array:
39  * 
40  * |[<!-- language="C" -->
41  * g_autoptr(GStrvBuilder) builder = g_strv_builder_new ();
42  * g_strv_builder_add (builder, "hello");
43  * g_strv_builder_add (builder, "world");
44  * g_auto(GStrv) array = g_strv_builder_end (builder);
45  * ]|
46  *
47  * Since: 2.68
48  */
49 public class StrvBuilder
50 {
51 	/** the main Gtk struct */
52 	protected GStrvBuilder* gStrvBuilder;
53 	protected bool ownedRef;
54 
55 	/** Get the main Gtk struct */
56 	public GStrvBuilder* getStrvBuilderStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gStrvBuilder;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected void* getStruct()
65 	{
66 		return cast(void*)gStrvBuilder;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GStrvBuilder* gStrvBuilder, bool ownedRef = false)
73 	{
74 		this.gStrvBuilder = gStrvBuilder;
75 		this.ownedRef = ownedRef;
76 	}
77 
78 	~this ()
79 	{
80 		if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
81 			g_strv_builder_unref(gStrvBuilder);
82 	}
83 
84 
85 	/**
86 	 * Add a string to the end of the array.
87 	 *
88 	 * Since 2.68
89 	 *
90 	 * Params:
91 	 *     value = a string.
92 	 */
93 	public void add(string value)
94 	{
95 		g_strv_builder_add(gStrvBuilder, Str.toStringz(value));
96 	}
97 
98 	/**
99 	 * Ends the builder process and returns the constructed NULL-terminated string
100 	 * array. The returned value should be freed with g_strfreev() when no longer
101 	 * needed.
102 	 *
103 	 * Returns: the constructed string array.
104 	 *
105 	 *     Since 2.68
106 	 */
107 	public string[] end()
108 	{
109 		auto retStr = g_strv_builder_end(gStrvBuilder);
110 
111 		scope(exit) Str.freeStringArray(retStr);
112 		return Str.toStringArray(retStr);
113 	}
114 
115 	alias doref = ref_;
116 	/**
117 	 * Atomically increments the reference count of @builder by one.
118 	 * This function is thread-safe and may be called from any thread.
119 	 *
120 	 * Returns: The passed in #GStrvBuilder
121 	 *
122 	 * Since: 2.68
123 	 */
124 	public StrvBuilder ref_()
125 	{
126 		auto __p = g_strv_builder_ref(gStrvBuilder);
127 
128 		if(__p is null)
129 		{
130 			return null;
131 		}
132 
133 		return new StrvBuilder(cast(GStrvBuilder*) __p, true);
134 	}
135 
136 	/**
137 	 * Decreases the reference count on @builder.
138 	 *
139 	 * In the event that there are no more references, releases all memory
140 	 * associated with the #GStrvBuilder.
141 	 *
142 	 * Since: 2.68
143 	 */
144 	public void unref()
145 	{
146 		g_strv_builder_unref(gStrvBuilder);
147 	}
148 
149 	/**
150 	 * Creates a new #GStrvBuilder with a reference count of 1.
151 	 * Use g_strv_builder_unref() on the returned value when no longer needed.
152 	 *
153 	 * Returns: the new #GStrvBuilder
154 	 *
155 	 * Since: 2.68
156 	 *
157 	 * Throws: ConstructionException GTK+ fails to create the object.
158 	 */
159 	public this()
160 	{
161 		auto __p = g_strv_builder_new();
162 
163 		if(__p is null)
164 		{
165 			throw new ConstructionException("null returned by new");
166 		}
167 
168 		this(cast(GStrvBuilder*) __p);
169 	}
170 }