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