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 gobject.Enums;
26 
27 private import glib.Str;
28 private import gobject.c.functions;
29 public  import gobject.c.types;
30 public  import gtkc.gobjecttypes;
31 
32 
33 /** */
34 public struct Enums
35 {
36 
37 	/**
38 	 * This function is meant to be called from the `complete_type_info`
39 	 * function of a #GTypePlugin implementation, as in the following
40 	 * example:
41 	 *
42 	 * |[<!-- language="C" -->
43 	 * static void
44 	 * my_enum_complete_type_info (GTypePlugin     *plugin,
45 	 * GType            g_type,
46 	 * GTypeInfo       *info,
47 	 * GTypeValueTable *value_table)
48 	 * {
49 	 * static const GEnumValue values[] = {
50 	 * { MY_ENUM_FOO, "MY_ENUM_FOO", "foo" },
51 	 * { MY_ENUM_BAR, "MY_ENUM_BAR", "bar" },
52 	 * { 0, NULL, NULL }
53 	 * };
54 	 *
55 	 * g_enum_complete_type_info (type, info, values);
56 	 * }
57 	 * ]|
58 	 *
59 	 * Params:
60 	 *     gEnumType = the type identifier of the type being completed
61 	 *     info = the #GTypeInfo struct to be filled in
62 	 *     constValues = An array of #GEnumValue structs for the possible
63 	 *         enumeration values. The array is terminated by a struct with all
64 	 *         members being 0.
65 	 */
66 	public static void completeTypeInfo(GType gEnumType, out GTypeInfo info, GEnumValue* constValues)
67 	{
68 		g_enum_complete_type_info(gEnumType, &info, constValues);
69 	}
70 
71 	/**
72 	 * Returns the #GEnumValue for a value.
73 	 *
74 	 * Params:
75 	 *     enumClass = a #GEnumClass
76 	 *     value = the value to look up
77 	 *
78 	 * Returns: the #GEnumValue for @value, or %NULL
79 	 *     if @value is not a member of the enumeration
80 	 */
81 	public static GEnumValue* getValue(GEnumClass* enumClass, int value)
82 	{
83 		return g_enum_get_value(enumClass, value);
84 	}
85 
86 	/**
87 	 * Looks up a #GEnumValue by name.
88 	 *
89 	 * Params:
90 	 *     enumClass = a #GEnumClass
91 	 *     name = the name to look up
92 	 *
93 	 * Returns: the #GEnumValue with name @name,
94 	 *     or %NULL if the enumeration doesn't have a member
95 	 *     with that name
96 	 */
97 	public static GEnumValue* getValueByName(GEnumClass* enumClass, string name)
98 	{
99 		return g_enum_get_value_by_name(enumClass, Str.toStringz(name));
100 	}
101 
102 	/**
103 	 * Looks up a #GEnumValue by nickname.
104 	 *
105 	 * Params:
106 	 *     enumClass = a #GEnumClass
107 	 *     nick = the nickname to look up
108 	 *
109 	 * Returns: the #GEnumValue with nickname @nick,
110 	 *     or %NULL if the enumeration doesn't have a member
111 	 *     with that nickname
112 	 */
113 	public static GEnumValue* getValueByNick(GEnumClass* enumClass, string nick)
114 	{
115 		return g_enum_get_value_by_nick(enumClass, Str.toStringz(nick));
116 	}
117 
118 	/**
119 	 * Registers a new static enumeration type with the name @name.
120 	 *
121 	 * It is normally more convenient to let [glib-mkenums][glib-mkenums],
122 	 * generate a my_enum_get_type() function from a usual C enumeration
123 	 * definition  than to write one yourself using g_enum_register_static().
124 	 *
125 	 * Params:
126 	 *     name = A nul-terminated string used as the name of the new type.
127 	 *     constStaticValues = An array of #GEnumValue structs for the possible
128 	 *         enumeration values. The array is terminated by a struct with all
129 	 *         members being 0. GObject keeps a reference to the data, so it cannot
130 	 *         be stack-allocated.
131 	 *
132 	 * Returns: The new type identifier.
133 	 */
134 	public static GType registerStatic(string name, GEnumValue* constStaticValues)
135 	{
136 		return g_enum_register_static(Str.toStringz(name), constStaticValues);
137 	}
138 
139 	/**
140 	 * Pretty-prints @value in the form of the enum’s name.
141 	 *
142 	 * This is intended to be used for debugging purposes. The format of the output
143 	 * may change in the future.
144 	 *
145 	 * Params:
146 	 *     gEnumType = the type identifier of a #GEnumClass type
147 	 *     value = the value
148 	 *
149 	 * Returns: a newly-allocated text string
150 	 *
151 	 * Since: 2.54
152 	 */
153 	public static string enumToString(GType gEnumType, int value)
154 	{
155 		auto retStr = g_enum_to_string(gEnumType, value);
156 
157 		scope(exit) Str.freeString(retStr);
158 		return Str.toString(retStr);
159 	}
160 
161 	/**
162 	 * Pretty-prints @value in the form of the flag names separated by ` | ` and
163 	 * sorted. Any extra bits will be shown at the end as a hexadecimal number.
164 	 *
165 	 * This is intended to be used for debugging purposes. The format of the output
166 	 * may change in the future.
167 	 *
168 	 * Params:
169 	 *     flagsType = the type identifier of a #GFlagsClass type
170 	 *     value = the value
171 	 *
172 	 * Returns: a newly-allocated text string
173 	 *
174 	 * Since: 2.54
175 	 */
176 	public static string flagsToString(GType flagsType, uint value)
177 	{
178 		auto retStr = g_flags_to_string(flagsType, value);
179 
180 		scope(exit) Str.freeString(retStr);
181 		return Str.toString(retStr);
182 	}
183 }