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 gio.InetAddressMask;
26 
27 private import gio.InetAddress;
28 private import gio.InitableIF;
29 private import gio.InitableT;
30 private import gio.c.functions;
31 public  import gio.c.types;
32 private import glib.ConstructionException;
33 private import glib.ErrorG;
34 private import glib.GException;
35 private import glib.Str;
36 private import gobject.ObjectG;
37 public  import gtkc.giotypes;
38 
39 
40 /**
41  * #GInetAddressMask represents a range of IPv4 or IPv6 addresses
42  * described by a base address and a length indicating how many bits
43  * of the base address are relevant for matching purposes. These are
44  * often given in string form. Eg, "10.0.0.0/8", or "fe80::/10".
45  *
46  * Since: 2.32
47  */
48 public class InetAddressMask : ObjectG, InitableIF
49 {
50 	/** the main Gtk struct */
51 	protected GInetAddressMask* gInetAddressMask;
52 
53 	/** Get the main Gtk struct */
54 	public GInetAddressMask* getInetAddressMaskStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return gInetAddressMask;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gInetAddressMask;
65 	}
66 
67 	protected override void setStruct(GObject* obj)
68 	{
69 		gInetAddressMask = cast(GInetAddressMask*)obj;
70 		super.setStruct(obj);
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GInetAddressMask* gInetAddressMask, bool ownedRef = false)
77 	{
78 		this.gInetAddressMask = gInetAddressMask;
79 		super(cast(GObject*)gInetAddressMask, ownedRef);
80 	}
81 
82 	// add the Initable capabilities
83 	mixin InitableT!(GInetAddressMask);
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return g_inet_address_mask_get_type();
90 	}
91 
92 	/**
93 	 * Creates a new #GInetAddressMask representing all addresses whose
94 	 * first @length bits match @addr.
95 	 *
96 	 * Params:
97 	 *     addr = a #GInetAddress
98 	 *     length = number of bits of @addr to use
99 	 *
100 	 * Returns: a new #GInetAddressMask, or %NULL on error
101 	 *
102 	 * Since: 2.32
103 	 *
104 	 * Throws: GException on failure.
105 	 * Throws: ConstructionException GTK+ fails to create the object.
106 	 */
107 	public this(InetAddress addr, uint length)
108 	{
109 		GError* err = null;
110 
111 		auto p = g_inet_address_mask_new((addr is null) ? null : addr.getInetAddressStruct(), length, &err);
112 
113 		if (err !is null)
114 		{
115 			throw new GException( new ErrorG(err) );
116 		}
117 
118 		if(p is null)
119 		{
120 			throw new ConstructionException("null returned by new");
121 		}
122 
123 		this(cast(GInetAddressMask*) p, true);
124 	}
125 
126 	/**
127 	 * Parses @mask_string as an IP address and (optional) length, and
128 	 * creates a new #GInetAddressMask. The length, if present, is
129 	 * delimited by a "/". If it is not present, then the length is
130 	 * assumed to be the full length of the address.
131 	 *
132 	 * Params:
133 	 *     maskString = an IP address or address/length string
134 	 *
135 	 * Returns: a new #GInetAddressMask corresponding to @string, or %NULL
136 	 *     on error.
137 	 *
138 	 * Since: 2.32
139 	 *
140 	 * Throws: GException on failure.
141 	 * Throws: ConstructionException GTK+ fails to create the object.
142 	 */
143 	public this(string maskString)
144 	{
145 		GError* err = null;
146 
147 		auto p = g_inet_address_mask_new_from_string(Str.toStringz(maskString), &err);
148 
149 		if (err !is null)
150 		{
151 			throw new GException( new ErrorG(err) );
152 		}
153 
154 		if(p is null)
155 		{
156 			throw new ConstructionException("null returned by new_from_string");
157 		}
158 
159 		this(cast(GInetAddressMask*) p, true);
160 	}
161 
162 	/**
163 	 * Tests if @mask and @mask2 are the same mask.
164 	 *
165 	 * Params:
166 	 *     mask2 = another #GInetAddressMask
167 	 *
168 	 * Returns: whether @mask and @mask2 are the same mask
169 	 *
170 	 * Since: 2.32
171 	 */
172 	public bool equal(InetAddressMask mask2)
173 	{
174 		return g_inet_address_mask_equal(gInetAddressMask, (mask2 is null) ? null : mask2.getInetAddressMaskStruct()) != 0;
175 	}
176 
177 	/**
178 	 * Gets @mask's base address
179 	 *
180 	 * Returns: @mask's base address
181 	 *
182 	 * Since: 2.32
183 	 */
184 	public InetAddress getAddress()
185 	{
186 		auto p = g_inet_address_mask_get_address(gInetAddressMask);
187 
188 		if(p is null)
189 		{
190 			return null;
191 		}
192 
193 		return ObjectG.getDObject!(InetAddress)(cast(GInetAddress*) p);
194 	}
195 
196 	/**
197 	 * Gets the #GSocketFamily of @mask's address
198 	 *
199 	 * Returns: the #GSocketFamily of @mask's address
200 	 *
201 	 * Since: 2.32
202 	 */
203 	public GSocketFamily getFamily()
204 	{
205 		return g_inet_address_mask_get_family(gInetAddressMask);
206 	}
207 
208 	/**
209 	 * Gets @mask's length
210 	 *
211 	 * Returns: @mask's length
212 	 *
213 	 * Since: 2.32
214 	 */
215 	public uint getLength()
216 	{
217 		return g_inet_address_mask_get_length(gInetAddressMask);
218 	}
219 
220 	/**
221 	 * Tests if @address falls within the range described by @mask.
222 	 *
223 	 * Params:
224 	 *     address = a #GInetAddress
225 	 *
226 	 * Returns: whether @address falls within the range described by
227 	 *     @mask.
228 	 *
229 	 * Since: 2.32
230 	 */
231 	public bool matches(InetAddress address)
232 	{
233 		return g_inet_address_mask_matches(gInetAddressMask, (address is null) ? null : address.getInetAddressStruct()) != 0;
234 	}
235 
236 	/**
237 	 * Converts @mask back to its corresponding string form.
238 	 *
239 	 * Returns: a string corresponding to @mask.
240 	 *
241 	 * Since: 2.32
242 	 */
243 	public override string toString()
244 	{
245 		auto retStr = g_inet_address_mask_to_string(gInetAddressMask);
246 
247 		scope(exit) Str.freeString(retStr);
248 		return Str.toString(retStr);
249 	}
250 }