source: appstream-generator/build/girepo/gio/InetAddressMask.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 5.7 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.InetAddressMask;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.InetAddress;
26private import gio.InitableIF;
27private import gio.InitableT;
28private import glib.ConstructionException;
29private import glib.ErrorG;
30private import glib.GException;
31private import glib.Str;
32private import gobject.ObjectG;
33
34
35/**
36 * #GInetAddressMask represents a range of IPv4 or IPv6 addresses
37 * described by a base address and a length indicating how many bits
38 * of the base address are relevant for matching purposes. These are
39 * often given in string form. Eg, "10.0.0.0/8", or "fe80::/10".
40 *
41 * Since: 2.32
42 */
43public class InetAddressMask : ObjectG, InitableIF
44{
45        /** the main Gtk struct */
46        protected GInetAddressMask* gInetAddressMask;
47
48        /** Get the main Gtk struct */
49        public GInetAddressMask* getInetAddressMaskStruct()
50        {
51                return gInetAddressMask;
52        }
53
54        /** the main Gtk struct as a void* */
55        protected override void* getStruct()
56        {
57                return cast(void*)gInetAddressMask;
58        }
59
60        protected override void setStruct(GObject* obj)
61        {
62                gInetAddressMask = cast(GInetAddressMask*)obj;
63                super.setStruct(obj);
64        }
65
66        /**
67         * Sets our main struct and passes it to the parent class.
68         */
69        public this (GInetAddressMask* gInetAddressMask, bool ownedRef = false)
70        {
71                this.gInetAddressMask = gInetAddressMask;
72                super(cast(GObject*)gInetAddressMask, ownedRef);
73        }
74
75        // add the Initable capabilities
76        mixin InitableT!(GInetAddressMask);
77
78
79        /** */
80        public static GType getType()
81        {
82                return g_inet_address_mask_get_type();
83        }
84
85        /**
86         * Creates a new #GInetAddressMask representing all addresses whose
87         * first @length bits match @addr.
88         *
89         * Params:
90         *     addr = a #GInetAddress
91         *     length = number of bits of @addr to use
92         *
93         * Returns: a new #GInetAddressMask, or %NULL on error
94         *
95         * Since: 2.32
96         *
97         * Throws: GException on failure.
98         * Throws: ConstructionException GTK+ fails to create the object.
99         */
100        public this(InetAddress addr, uint length)
101        {
102                GError* err = null;
103               
104                auto p = g_inet_address_mask_new((addr is null) ? null : addr.getInetAddressStruct(), length, &err);
105               
106                if (err !is null)
107                {
108                        throw new GException( new ErrorG(err) );
109                }
110               
111                if(p is null)
112                {
113                        throw new ConstructionException("null returned by new");
114                }
115               
116                this(cast(GInetAddressMask*) p, true);
117        }
118
119        /**
120         * Parses @mask_string as an IP address and (optional) length, and
121         * creates a new #GInetAddressMask. The length, if present, is
122         * delimited by a "/". If it is not present, then the length is
123         * assumed to be the full length of the address.
124         *
125         * Params:
126         *     maskString = an IP address or address/length string
127         *
128         * Returns: a new #GInetAddressMask corresponding to @string, or %NULL
129         *     on error.
130         *
131         * Since: 2.32
132         *
133         * Throws: GException on failure.
134         * Throws: ConstructionException GTK+ fails to create the object.
135         */
136        public this(string maskString)
137        {
138                GError* err = null;
139               
140                auto p = g_inet_address_mask_new_from_string(Str.toStringz(maskString), &err);
141               
142                if (err !is null)
143                {
144                        throw new GException( new ErrorG(err) );
145                }
146               
147                if(p is null)
148                {
149                        throw new ConstructionException("null returned by new_from_string");
150                }
151               
152                this(cast(GInetAddressMask*) p, true);
153        }
154
155        /**
156         * Tests if @mask and @mask2 are the same mask.
157         *
158         * Params:
159         *     mask2 = another #GInetAddressMask
160         *
161         * Returns: whether @mask and @mask2 are the same mask
162         *
163         * Since: 2.32
164         */
165        public bool equal(InetAddressMask mask2)
166        {
167                return g_inet_address_mask_equal(gInetAddressMask, (mask2 is null) ? null : mask2.getInetAddressMaskStruct()) != 0;
168        }
169
170        /**
171         * Gets @mask's base address
172         *
173         * Returns: @mask's base address
174         *
175         * Since: 2.32
176         */
177        public InetAddress getAddress()
178        {
179                auto p = g_inet_address_mask_get_address(gInetAddressMask);
180               
181                if(p is null)
182                {
183                        return null;
184                }
185               
186                return ObjectG.getDObject!(InetAddress)(cast(GInetAddress*) p);
187        }
188
189        /**
190         * Gets the #GSocketFamily of @mask's address
191         *
192         * Returns: the #GSocketFamily of @mask's address
193         *
194         * Since: 2.32
195         */
196        public GSocketFamily getFamily()
197        {
198                return g_inet_address_mask_get_family(gInetAddressMask);
199        }
200
201        /**
202         * Gets @mask's length
203         *
204         * Returns: @mask's length
205         *
206         * Since: 2.32
207         */
208        public uint getLength()
209        {
210                return g_inet_address_mask_get_length(gInetAddressMask);
211        }
212
213        /**
214         * Tests if @address falls within the range described by @mask.
215         *
216         * Params:
217         *     address = a #GInetAddress
218         *
219         * Returns: whether @address falls within the range described by
220         *     @mask.
221         *
222         * Since: 2.32
223         */
224        public bool matches(InetAddress address)
225        {
226                return g_inet_address_mask_matches(gInetAddressMask, (address is null) ? null : address.getInetAddressStruct()) != 0;
227        }
228
229        /**
230         * Converts @mask back to its corresponding string form.
231         *
232         * Returns: a string corresponding to @mask.
233         *
234         * Since: 2.32
235         */
236        public override string toString()
237        {
238                auto retStr = g_inet_address_mask_to_string(gInetAddressMask);
239               
240                scope(exit) Str.freeString(retStr);
241                return Str.toString(retStr);
242        }
243}
Note: See TracBrowser for help on using the repository browser.