[gnome-db] New Proporsol Functions for 2.7 developmen series



I'm working in port the current implementation of GdaValue (from the
www.gnome-db.org proyect), to use as the container of values the
GValue of GLib.

But I find that GdaValue requires some king of data types, that must
need derived from a G_TYPE_CHAR/UCHAR and G_TYPE_INT/UINT fundamental
types; then hard code a function to derive a type from the existing
one, and create the g_value_get/set respective functions.

Then I suggest to add the followin functions to the GLib, to give to
the developer the necesary functions to do so.

The functions are:

GType
g_char_type_register_static (const gchar *name)
{
  static const GTypeInfo type_info = {
    0,			/* class_size */
    NULL,		/* base_init */
    NULL,		/* base_finalize */
    NULL,		/* class_init */
    NULL,		/* class_finalize */
    NULL,		/* class_data */
    0,			/* instance_size */
    0,			/* n_preallocs */
    NULL,		/* instance_init */
    NULL		/* value_table */
  };
  GType type;

  g_return_val_if_fail (name != NULL, 0);
  g_return_val_if_fail (g_type_from_name (name) == 0, 0);

  type = g_type_register_static (G_TYPE_CHAR, name, &type_info, 0);

  return type;
}


GType
g_uchar_type_register_static (const gchar *name)
{
  static const GTypeInfo type_info = {
    0,			/* class_size */
    NULL,		/* base_init */
    NULL,		/* base_finalize */
    NULL,		/* class_init */
    NULL,		/* class_finalize */
    NULL,		/* class_data */
    0,			/* instance_size */
    0,			/* n_preallocs */
    NULL,		/* instance_init */
    NULL		/* value_table */
  };
  GType type;

  g_return_val_if_fail (name != NULL, 0);
  g_return_val_if_fail (g_type_from_name (name) == 0, 0);

  type = g_type_register_static (G_TYPE_UCHAR, name, &type_info, 0);

  return type;
}

GType
g_int_type_register_static (const gchar *name)
{
  static const GTypeInfo type_info = {
    0,			/* class_size */
    NULL,		/* base_init */
    NULL,		/* base_finalize */
    NULL,		/* class_init */
    NULL,		/* class_finalize */
    NULL,		/* class_data */
    0,			/* instance_size */
    0,			/* n_preallocs */
    NULL,		/* instance_init */
    NULL		/* value_table */
  };
  GType type;

  g_return_val_if_fail (name != NULL, 0);
  g_return_val_if_fail (g_type_from_name (name) == 0, 0);

  type = g_type_register_static (G_TYPE_INT, name, &type_info, 0);

  return type;
}

GType
g_uint_type_register_static (const gchar *name)
{
  static const GTypeInfo type_info = {
    0,			/* class_size */
    NULL,		/* base_init */
    NULL,		/* base_finalize */
    NULL,		/* class_init */
    NULL,		/* class_finalize */
    NULL,		/* class_data */
    0,			/* instance_size */
    0,			/* n_preallocs */
    NULL,		/* instance_init */
    NULL		/* value_table */
  };
  GType type;

  g_return_val_if_fail (name != NULL, 0);
  g_return_val_if_fail (g_type_from_name (name) == 0, 0);

  type = g_type_register_static (G_TYPE_UINT, name, &type_info, 0);

  return type;
}

void
g_value_set_tinyint (GValue *value,
		  tinyint	  v_tinyint)
{
//  g_return_if_fail (G_VALUE_HOLDS_TINYINT (value));
  
  g_value_set_char(value, v_tinyint);
}

tinyint
g_value_get_tinyint (const GValue *value)
{
//  g_return_val_if_fail (G_VALUE_HOLDS_TINYINT (value), 0);
  
  return (tinyint) g_value_get_char(value);
}

void
g_value_set_tinyuint (GValue *value,
		  tinyuint	  v_tinyuint)
{
//  g_return_if_fail (G_VALUE_HOLDS_TINYINT (value));
  
  g_value_set_char(value, v_tinyuint);
}

tinyuint
g_value_get_tinyuint (const GValue *value)
{
//  g_return_val_if_fail (G_VALUE_HOLDS_TINYINT (value), 0);
  
  return (tinyuint) g_value_get_char(value);
}

void
g_value_set_short (GValue *value,
		  gshort	  v_short)
{
	g_return_if_fail (G_VALUE_HOLDS_GSHORT (value));
	value->data[0].v_int = v_short;
}

gshort
g_value_get_short (const GValue *value)
{
	g_return_val_if_fail (G_VALUE_HOLDS_GSHORT (value), 0);
    return (gshort) value->data[0].v_int;
}

void
g_value_set_ushort (GValue *value,
		  gushort	  v_ushort)
{
	g_return_if_fail (G_VALUE_HOLDS_GUSHORT (value));
	value->data[0].v_uint = v_ushort;
}

gushort
g_value_get_ushort (const GValue *value)
{
	g_return_val_if_fail (G_VALUE_HOLDS_GUSHORT (value), 0);
  
	return (gushort) value->data[0].v_uint;
}

-- 
Trabajar, la mejor arma para tu superación



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]