Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

416 lignes
15 KiB

  1. /* GObject - GLib Type, Object, Parameter and Signal Library
  2. * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library 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 GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General
  15. * Public License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. *
  19. * gparam.h: GParamSpec base class implementation
  20. */
  21. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  22. #error "Only <glib-object.h> can be included directly."
  23. #endif
  24. #ifndef __G_PARAM_H__
  25. #define __G_PARAM_H__
  26. #include <gobject/gvalue.h>
  27. G_BEGIN_DECLS
  28. /* --- standard type macros --- */
  29. /**
  30. * G_TYPE_IS_PARAM:
  31. * @type: a #GType ID
  32. *
  33. * Checks whether @type "is a" %G_TYPE_PARAM.
  34. */
  35. #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
  36. /**
  37. * G_PARAM_SPEC:
  38. * @pspec: a valid #GParamSpec
  39. *
  40. * Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
  41. * a #GParamSpec object.
  42. */
  43. #define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
  44. /**
  45. * G_IS_PARAM_SPEC:
  46. * @pspec: a #GParamSpec
  47. *
  48. * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
  49. * or derived.
  50. */
  51. #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
  52. /**
  53. * G_PARAM_SPEC_CLASS:
  54. * @pclass: a valid #GParamSpecClass
  55. *
  56. * Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
  57. */
  58. #define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
  59. /**
  60. * G_IS_PARAM_SPEC_CLASS:
  61. * @pclass: a #GParamSpecClass
  62. *
  63. * Checks whether @pclass "is a" valid #GParamSpecClass structure of type
  64. * %G_TYPE_PARAM or derived.
  65. */
  66. #define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
  67. /**
  68. * G_PARAM_SPEC_GET_CLASS:
  69. * @pspec: a valid #GParamSpec
  70. *
  71. * Retrieves the #GParamSpecClass of a #GParamSpec.
  72. */
  73. #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
  74. /* --- convenience macros --- */
  75. /**
  76. * G_PARAM_SPEC_TYPE:
  77. * @pspec: a valid #GParamSpec
  78. *
  79. * Retrieves the #GType of this @pspec.
  80. */
  81. #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
  82. /**
  83. * G_PARAM_SPEC_TYPE_NAME:
  84. * @pspec: a valid #GParamSpec
  85. *
  86. * Retrieves the #GType name of this @pspec.
  87. */
  88. #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
  89. /**
  90. * G_PARAM_SPEC_VALUE_TYPE:
  91. * @pspec: a valid #GParamSpec
  92. *
  93. * Retrieves the #GType to initialize a #GValue for this parameter.
  94. */
  95. #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type)
  96. /**
  97. * G_VALUE_HOLDS_PARAM:
  98. * @value: a valid #GValue structure
  99. *
  100. * Checks whether the given #GValue can hold values derived from type %G_TYPE_PARAM.
  101. *
  102. * Returns: %TRUE on success.
  103. */
  104. #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
  105. /* --- flags --- */
  106. /**
  107. * GParamFlags:
  108. * @G_PARAM_READABLE: the parameter is readable
  109. * @G_PARAM_WRITABLE: the parameter is writable
  110. * @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
  111. * @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
  112. * @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
  113. * strict validation is not required
  114. * @G_PARAM_STATIC_NAME: the string used as name when constructing the
  115. * parameter is guaranteed to remain valid and
  116. * unmodified for the lifetime of the parameter.
  117. * Since 2.8
  118. * @G_PARAM_STATIC_NICK: the string used as nick when constructing the
  119. * parameter is guaranteed to remain valid and
  120. * unmmodified for the lifetime of the parameter.
  121. * Since 2.8
  122. * @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
  123. * parameter is guaranteed to remain valid and
  124. * unmodified for the lifetime of the parameter.
  125. * Since 2.8
  126. * @G_PARAM_PRIVATE: internal
  127. * @G_PARAM_DEPRECATED: the parameter is deprecated and will be removed
  128. * in a future version. A warning will be generated if it is used
  129. * while running with G_ENABLE_DIAGNOSTIC=1.
  130. * Since: 2.26
  131. *
  132. * Through the #GParamFlags flag values, certain aspects of parameters
  133. * can be configured.
  134. */
  135. typedef enum
  136. {
  137. G_PARAM_READABLE = 1 << 0,
  138. G_PARAM_WRITABLE = 1 << 1,
  139. G_PARAM_CONSTRUCT = 1 << 2,
  140. G_PARAM_CONSTRUCT_ONLY = 1 << 3,
  141. G_PARAM_LAX_VALIDATION = 1 << 4,
  142. G_PARAM_STATIC_NAME = 1 << 5,
  143. #ifndef G_DISABLE_DEPRECATED
  144. G_PARAM_PRIVATE = G_PARAM_STATIC_NAME,
  145. #endif
  146. G_PARAM_STATIC_NICK = 1 << 6,
  147. G_PARAM_STATIC_BLURB = 1 << 7,
  148. /* User defined flags go up to 30 */
  149. G_PARAM_DEPRECATED = 1 << 31
  150. } GParamFlags;
  151. /**
  152. * G_PARAM_READWRITE:
  153. *
  154. * #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
  155. */
  156. #define G_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE)
  157. /**
  158. * G_PARAM_STATIC_STRINGS:
  159. *
  160. * #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
  161. *
  162. * Since 2.13.0
  163. */
  164. #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
  165. /* bits in the range 0xffffff00 are reserved for 3rd party usage */
  166. /**
  167. * G_PARAM_MASK:
  168. *
  169. * Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
  170. */
  171. #define G_PARAM_MASK (0x000000ff)
  172. /**
  173. * G_PARAM_USER_SHIFT:
  174. *
  175. * Minimum shift count to be used for user defined flags, to be stored in
  176. * #GParamSpec.flags. The maximum allowed is 30 + G_PARAM_USER_SHIFT.
  177. */
  178. #define G_PARAM_USER_SHIFT (8)
  179. /* --- typedefs & structures --- */
  180. typedef struct _GParamSpec GParamSpec;
  181. typedef struct _GParamSpecClass GParamSpecClass;
  182. typedef struct _GParameter GParameter;
  183. typedef struct _GParamSpecPool GParamSpecPool;
  184. /**
  185. * GParamSpec:
  186. * @g_type_instance: private #GTypeInstance portion
  187. * @name: name of this parameter
  188. * @flags: #GParamFlags flags for this parameter
  189. * @value_type: the #GValue type for this parameter
  190. * @owner_type: #GType type that uses (introduces) this parameter
  191. *
  192. * All other fields of the <structname>GParamSpec</structname> struct are private and
  193. * should not be used directly.
  194. */
  195. struct _GParamSpec
  196. {
  197. GTypeInstance g_type_instance;
  198. gchar *name;
  199. GParamFlags flags;
  200. GType value_type;
  201. GType owner_type; /* class or interface using this property */
  202. /*< private >*/
  203. gchar *_nick;
  204. gchar *_blurb;
  205. GData *qdata;
  206. guint ref_count;
  207. guint param_id; /* sort-criteria */
  208. };
  209. /**
  210. * GParamSpecClass:
  211. * @g_type_class: the parent class
  212. * @value_type: the #GValue type for this parameter
  213. * @finalize: The instance finalization function (optional), should chain
  214. * up to the finalize method of the parent class.
  215. * @value_set_default: Resets a @value to the default value for this type
  216. * (recommended, the default is g_value_reset()), see
  217. * g_param_value_set_default().
  218. * @value_validate: Ensures that the contents of @value comply with the
  219. * specifications set out by this type (optional), see
  220. * g_param_value_set_validate().
  221. * @values_cmp: Compares @value1 with @value2 according to this type
  222. * (recommended, the default is memcmp()), see g_param_values_cmp().
  223. *
  224. * The class structure for the <structname>GParamSpec</structname> type.
  225. * Normally, <structname>GParamSpec</structname> classes are filled by
  226. * g_param_type_register_static().
  227. */
  228. struct _GParamSpecClass
  229. {
  230. GTypeClass g_type_class;
  231. GType value_type;
  232. void (*finalize) (GParamSpec *pspec);
  233. /* GParam methods */
  234. void (*value_set_default) (GParamSpec *pspec,
  235. GValue *value);
  236. gboolean (*value_validate) (GParamSpec *pspec,
  237. GValue *value);
  238. gint (*values_cmp) (GParamSpec *pspec,
  239. const GValue *value1,
  240. const GValue *value2);
  241. /*< private >*/
  242. gpointer dummy[4];
  243. };
  244. /**
  245. * GParameter:
  246. * @name: the parameter name
  247. * @value: the parameter value
  248. *
  249. * The <structname>GParameter</structname> struct is an auxiliary structure used
  250. * to hand parameter name/value pairs to g_object_newv().
  251. */
  252. struct _GParameter /* auxillary structure for _setv() variants */
  253. {
  254. const gchar *name;
  255. GValue value;
  256. };
  257. /* --- prototypes --- */
  258. GParamSpec* g_param_spec_ref (GParamSpec *pspec);
  259. void g_param_spec_unref (GParamSpec *pspec);
  260. void g_param_spec_sink (GParamSpec *pspec);
  261. GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec);
  262. gpointer g_param_spec_get_qdata (GParamSpec *pspec,
  263. GQuark quark);
  264. void g_param_spec_set_qdata (GParamSpec *pspec,
  265. GQuark quark,
  266. gpointer data);
  267. void g_param_spec_set_qdata_full (GParamSpec *pspec,
  268. GQuark quark,
  269. gpointer data,
  270. GDestroyNotify destroy);
  271. gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
  272. GQuark quark);
  273. GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
  274. void g_param_value_set_default (GParamSpec *pspec,
  275. GValue *value);
  276. gboolean g_param_value_defaults (GParamSpec *pspec,
  277. GValue *value);
  278. gboolean g_param_value_validate (GParamSpec *pspec,
  279. GValue *value);
  280. gboolean g_param_value_convert (GParamSpec *pspec,
  281. const GValue *src_value,
  282. GValue *dest_value,
  283. gboolean strict_validation);
  284. gint g_param_values_cmp (GParamSpec *pspec,
  285. const GValue *value1,
  286. const GValue *value2);
  287. G_CONST_RETURN gchar* g_param_spec_get_name (GParamSpec *pspec);
  288. G_CONST_RETURN gchar* g_param_spec_get_nick (GParamSpec *pspec);
  289. G_CONST_RETURN gchar* g_param_spec_get_blurb (GParamSpec *pspec);
  290. void g_value_set_param (GValue *value,
  291. GParamSpec *param);
  292. GParamSpec* g_value_get_param (const GValue *value);
  293. GParamSpec* g_value_dup_param (const GValue *value);
  294. void g_value_take_param (GValue *value,
  295. GParamSpec *param);
  296. #ifndef G_DISABLE_DEPRECATED
  297. void g_value_set_param_take_ownership (GValue *value,
  298. GParamSpec *param);
  299. #endif
  300. /* --- convenience functions --- */
  301. typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
  302. /**
  303. * GParamSpecTypeInfo:
  304. * @instance_size: Size of the instance (object) structure.
  305. * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the <link linkend="glib-Memory-Slices">slice allocator</link> now.
  306. * @instance_init: Location of the instance initialization function (optional).
  307. * @value_type: The #GType of values conforming to this #GParamSpec
  308. * @finalize: The instance finalization function (optional).
  309. * @value_set_default: Resets a @value to the default value for @pspec
  310. * (recommended, the default is g_value_reset()), see
  311. * g_param_value_set_default().
  312. * @value_validate: Ensures that the contents of @value comply with the
  313. * specifications set out by @pspec (optional), see
  314. * g_param_value_set_validate().
  315. * @values_cmp: Compares @value1 with @value2 according to @pspec
  316. * (recommended, the default is memcmp()), see g_param_values_cmp().
  317. *
  318. * This structure is used to provide the type system with the information
  319. * required to initialize and destruct (finalize) a parameter's class and
  320. * instances thereof.
  321. * The initialized structure is passed to the g_param_type_register_static()
  322. * The type system will perform a deep copy of this structure, so its memory
  323. * does not need to be persistent across invocation of
  324. * g_param_type_register_static().
  325. */
  326. struct _GParamSpecTypeInfo
  327. {
  328. /* type system portion */
  329. guint16 instance_size; /* obligatory */
  330. guint16 n_preallocs; /* optional */
  331. void (*instance_init) (GParamSpec *pspec); /* optional */
  332. /* class portion */
  333. GType value_type; /* obligatory */
  334. void (*finalize) (GParamSpec *pspec); /* optional */
  335. void (*value_set_default) (GParamSpec *pspec, /* recommended */
  336. GValue *value);
  337. gboolean (*value_validate) (GParamSpec *pspec, /* optional */
  338. GValue *value);
  339. gint (*values_cmp) (GParamSpec *pspec, /* recommended */
  340. const GValue *value1,
  341. const GValue *value2);
  342. };
  343. GType g_param_type_register_static (const gchar *name,
  344. const GParamSpecTypeInfo *pspec_info);
  345. /* For registering builting types */
  346. GType _g_param_type_register_static_constant (const gchar *name,
  347. const GParamSpecTypeInfo *pspec_info,
  348. GType opt_type);
  349. /* --- protected --- */
  350. gpointer g_param_spec_internal (GType param_type,
  351. const gchar *name,
  352. const gchar *nick,
  353. const gchar *blurb,
  354. GParamFlags flags);
  355. GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
  356. void g_param_spec_pool_insert (GParamSpecPool *pool,
  357. GParamSpec *pspec,
  358. GType owner_type);
  359. void g_param_spec_pool_remove (GParamSpecPool *pool,
  360. GParamSpec *pspec);
  361. GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
  362. const gchar *param_name,
  363. GType owner_type,
  364. gboolean walk_ancestors);
  365. GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
  366. GType owner_type);
  367. GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
  368. GType owner_type,
  369. guint *n_pspecs_p);
  370. /* contracts:
  371. *
  372. * gboolean value_validate (GParamSpec *pspec,
  373. * GValue *value):
  374. * modify value contents in the least destructive way, so
  375. * that it complies with pspec's requirements (i.e.
  376. * according to minimum/maximum ranges etc...). return
  377. * whether modification was necessary.
  378. *
  379. * gint values_cmp (GParamSpec *pspec,
  380. * const GValue *value1,
  381. * const GValue *value2):
  382. * return value1 - value2, i.e. (-1) if value1 < value2,
  383. * (+1) if value1 > value2, and (0) otherwise (equality)
  384. */
  385. G_END_DECLS
  386. #endif /* __G_PARAM_H__ */