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