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