static gpointer value_as_pointer (GValue *value) { if (g_value_fits_pointer (value)) return g_value_peek_pointer (value); if (G_VALUE_HOLDS_BOOLEAN (value)) return (void*) g_value_get_boolean (value); if (G_VALUE_HOLDS_CHAR (value)) return (void*) (gssize) g_value_get_char (value); if (G_VALUE_HOLDS_UCHAR (value)) return (void*) (gsize) g_value_get_uchar (value); if (G_VALUE_HOLDS_INT (value)) return (void*) g_value_get_int (value); if (G_VALUE_HOLDS_UINT (value)) return (void*) g_value_get_uint (value); if (G_VALUE_HOLDS_LONG (value)) return (void*) g_value_get_long (value); if (G_VALUE_HOLDS_ULONG (value)) return (void*) g_value_get_ulong (value); if (G_VALUE_HOLDS_FLOAT (value)) return (void*) (gssize) g_value_get_float (value); if (G_VALUE_HOLDS_DOUBLE (value)) return (void*) (gssize) g_value_get_double (value); if (G_VALUE_HOLDS_ENUM (value)) return (void*) (gssize) g_value_get_enum (value); if (G_VALUE_HOLDS_FLAGS (value)) return (void*) (gsize) g_value_get_flags (value); return (void*) 0x1373babe; }
/** * g_value_get_char: * @value: a valid #GValue of type %G_TYPE_CHAR * * Get the contents of a %G_TYPE_CHAR #GValue. * * Returns: character contents of @value */ gchar g_value_get_char (const GValue *value) { g_return_val_if_fail (G_VALUE_HOLDS_CHAR (value), 0); return value->data[0].v_int; }
int ce_get_property_default (NMSetting *setting, const char *property_name) { GParamSpec *spec; GValue value = { 0, }; g_return_val_if_fail (NM_IS_SETTING (setting), -1); spec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_name); g_return_val_if_fail (spec != NULL, -1); g_value_init (&value, spec->value_type); g_param_value_set_default (spec, &value); if (G_VALUE_HOLDS_CHAR (&value)) return (int) g_value_get_schar (&value); else if (G_VALUE_HOLDS_INT (&value)) return g_value_get_int (&value); else if (G_VALUE_HOLDS_INT64 (&value)) return (int) g_value_get_int64 (&value); else if (G_VALUE_HOLDS_LONG (&value)) return (int) g_value_get_long (&value); else if (G_VALUE_HOLDS_UINT (&value)) return (int) g_value_get_uint (&value); else if (G_VALUE_HOLDS_UINT64 (&value)) return (int) g_value_get_uint64 (&value); else if (G_VALUE_HOLDS_ULONG (&value)) return (int) g_value_get_ulong (&value); else if (G_VALUE_HOLDS_UCHAR (&value)) return (int) g_value_get_uchar (&value); g_return_val_if_fail (FALSE, 0); return 0; }
/** * g_value_set_char: * @value: a valid #GValue of type %G_TYPE_CHAR * @v_char: character value to be set * * Set the contents of a %G_TYPE_CHAR #GValue to @v_char. */ void g_value_set_char (GValue *value, gchar v_char) { g_return_if_fail (G_VALUE_HOLDS_CHAR (value)); value->data[0].v_int = v_char; }
gboolean g_settings_get_mapping (GValue *value, GVariant *variant, gpointer user_data) { if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN)) { if (!G_VALUE_HOLDS_BOOLEAN (value)) return FALSE; g_value_set_boolean (value, g_variant_get_boolean (variant)); return TRUE; } else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BYTE)) { if (G_VALUE_HOLDS_UCHAR (value)) g_value_set_uchar (value, g_variant_get_byte (variant)); else if (G_VALUE_HOLDS_CHAR (value)) g_value_set_char (value, (gchar) g_variant_get_byte (variant)); else return FALSE; return TRUE; } else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_INT16) || g_variant_is_of_type (variant, G_VARIANT_TYPE_INT32) || g_variant_is_of_type (variant, G_VARIANT_TYPE_INT64)) return g_settings_get_mapping_int (value, variant); else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_DOUBLE)) return g_settings_get_mapping_float (value, variant); else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT16) || g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32) || g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT64) || g_variant_is_of_type (variant, G_VARIANT_TYPE_HANDLE)) return g_settings_get_mapping_unsigned_int (value, variant); else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING) || g_variant_is_of_type (variant, G_VARIANT_TYPE_OBJECT_PATH) || g_variant_is_of_type (variant, G_VARIANT_TYPE_SIGNATURE)) { if (G_VALUE_HOLDS_STRING (value)) { g_value_set_string (value, g_variant_get_string (variant, NULL)); return TRUE; } else if (G_VALUE_HOLDS_ENUM (value)) { GEnumClass *eclass; GEnumValue *evalue; const gchar *nick; /* GParamSpecEnum holds a ref on the class so we just peek... */ eclass = g_type_class_peek (G_VALUE_TYPE (value)); nick = g_variant_get_string (variant, NULL); evalue = g_enum_get_value_by_nick (eclass, nick); if (evalue) { g_value_set_enum (value, evalue->value); return TRUE; } g_warning ("Unable to lookup enum nick '%s' via GType\n", nick); return FALSE; } } else if (g_variant_is_of_type (variant, G_VARIANT_TYPE ("as"))) { if (G_VALUE_HOLDS (value, G_TYPE_STRV)) { g_value_take_boxed (value, g_variant_dup_strv (variant, NULL)); return TRUE; } else if (G_VALUE_HOLDS_FLAGS (value)) { GFlagsClass *fclass; GFlagsValue *fvalue; const gchar *nick; GVariantIter iter; guint flags = 0; fclass = g_type_class_peek (G_VALUE_TYPE (value)); g_variant_iter_init (&iter, variant); while (g_variant_iter_next (&iter, "&s", &nick)) { fvalue = g_flags_get_value_by_nick (fclass, nick); if (fvalue) flags |= fvalue->value; else { g_warning ("Unable to lookup flags nick '%s' via GType\n", nick); return FALSE; } } g_value_set_flags (value, flags); return TRUE; } } else if (g_variant_is_of_type (variant, G_VARIANT_TYPE_BYTESTRING)) { g_value_set_string (value, g_variant_get_bytestring (variant)); return TRUE; } g_critical ("No GSettings bind handler for type \"%s\".", g_variant_get_type_string (variant)); return FALSE; }
GVariant * g_settings_set_mapping (const GValue *value, const GVariantType *expected_type, gpointer user_data) { gchar *type_string; if (G_VALUE_HOLDS_BOOLEAN (value)) { if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BOOLEAN)) return g_variant_new_boolean (g_value_get_boolean (value)); } else if (G_VALUE_HOLDS_CHAR (value) || G_VALUE_HOLDS_UCHAR (value)) { if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTE)) { if (G_VALUE_HOLDS_CHAR (value)) return g_variant_new_byte (g_value_get_char (value)); else return g_variant_new_byte (g_value_get_uchar (value)); } } else if (G_VALUE_HOLDS_INT (value) || G_VALUE_HOLDS_INT64 (value)) return g_settings_set_mapping_int (value, expected_type); else if (G_VALUE_HOLDS_DOUBLE (value)) return g_settings_set_mapping_float (value, expected_type); else if (G_VALUE_HOLDS_UINT (value) || G_VALUE_HOLDS_UINT64 (value)) return g_settings_set_mapping_unsigned_int (value, expected_type); else if (G_VALUE_HOLDS_STRING (value)) { if (g_value_get_string (value) == NULL) return NULL; else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING)) return g_variant_new_string (g_value_get_string (value)); else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BYTESTRING)) return g_variant_new_bytestring (g_value_get_string (value)); else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_OBJECT_PATH)) return g_variant_new_object_path (g_value_get_string (value)); else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_SIGNATURE)) return g_variant_new_signature (g_value_get_string (value)); } else if (G_VALUE_HOLDS (value, G_TYPE_STRV)) { if (g_value_get_boxed (value) == NULL) return NULL; return g_variant_new_strv ((const gchar **) g_value_get_boxed (value), -1); } else if (G_VALUE_HOLDS_ENUM (value)) { GEnumValue *enumval; GEnumClass *eclass; /* GParamSpecEnum holds a ref on the class so we just peek... */ eclass = g_type_class_peek (G_VALUE_TYPE (value)); enumval = g_enum_get_value (eclass, g_value_get_enum (value)); if (enumval) return g_variant_new_string (enumval->value_nick); else return NULL; } else if (G_VALUE_HOLDS_FLAGS (value)) { GVariantBuilder builder; GFlagsValue *flagsval; GFlagsClass *fclass; guint flags; fclass = g_type_class_peek (G_VALUE_TYPE (value)); flags = g_value_get_flags (value); g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); while (flags) { flagsval = g_flags_get_first_value (fclass, flags); if (flagsval == NULL) { g_variant_builder_clear (&builder); return NULL; } g_variant_builder_add (&builder, "s", flagsval->value_nick); flags &= ~flagsval->value; } return g_variant_builder_end (&builder); } type_string = g_variant_type_dup_string (expected_type); g_critical ("No GSettings bind handler for type \"%s\".", type_string); g_free (type_string); return NULL; }
void ada_gvalue_set (GValue* value, void *val) { if G_VALUE_HOLDS_CHAR (value) g_value_set_schar (value, *(gchar*)val); else if G_VALUE_HOLDS_UCHAR (value)