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