Top | ![]() |
![]() |
![]() |
![]() |
void | (*IpatchValueTransform) () |
IpatchUnitInfo * | ipatch_unit_info_new () |
void | ipatch_unit_info_free () |
IpatchUnitInfo * | ipatch_unit_info_duplicate () |
guint16 | ipatch_unit_register () |
IpatchUnitInfo * | ipatch_unit_lookup () |
IpatchUnitInfo * | ipatch_unit_lookup_by_name () |
void | ipatch_unit_class_register_map () |
IpatchUnitInfo * | ipatch_unit_class_lookup_map () |
void | ipatch_unit_conversion_register () |
void | ipatch_unit_conversion_register_full () |
IpatchValueTransform | ipatch_unit_conversion_lookup () |
gboolean | ipatch_unit_convert () |
double | ipatch_unit_user_class_convert () |
void (*IpatchValueTransform) (const GValue *src
,GValue *dest
);
Transform from one value to another. The src
and dest
values have
already been initialized to specific types and the transform function
should convert/process them as necessary.
IpatchUnitInfo *
ipatch_unit_info_new (void
);
Allocate a unit info structure for registering unit types with
ipatch_unit_register()
. Using this function should minimize API changes
if additional fields are added to IpatchUnitInfo. Free the returned
structure with ipatch_unit_free()
when finished registering unit types.
[skip]
void
ipatch_unit_info_free (IpatchUnitInfo *info
);
Free a unit info structure that was created with ipatch_unit_info_new()
.
[skip]
IpatchUnitInfo *
ipatch_unit_info_duplicate (const IpatchUnitInfo *info
);
Duplicate a unit info structure.
[skip]
Since: 1.1.0
guint16
ipatch_unit_register (const IpatchUnitInfo *info
);
Add a new unit type to the unit registry. Note that the info
structure
is shallow copied, so strings should be constant or guaranteed to not
be freed. If the <structfield>id</structfield> field is already set
(non-zero) in info
, then it is used (should be 0 for dynamic unit
types). If the <structfield>label</structfield> field of the info
structure is NULL
then it is set to the i18n translated string for
<structfield>name</structfield>. Unit types can not be un-registered.
Unit IDs of dynamic (non built-in types) should not be relied apon to
always be the same between program executions.
IpatchUnitInfo *
ipatch_unit_lookup_by_name (const char *name
);
Looks up unit info by name.
void ipatch_unit_class_register_map (guint16 class_type
,guint16 src_units
,guint16 dest_units
);
Register a unit class mapping. Unit class types define domains of conversion, an example is the "user" unit class (IPATCH_UNIT_CLASS_USER) which is used to convert values to units digestable by a human. A conversion class is essentially a mapping between unit types, which can then be used to lookup conversion functions.
class_type |
Class type (see IpatchUnitClassType). |
[type IpatchUnitClassType] |
src_units |
Source unit type of mapping |
|
dest_units |
Destination unit type for this map |
IpatchUnitInfo * ipatch_unit_class_lookup_map (guint16 class_type
,guint16 src_units
);
Lookup a unit class mapping (see ipatch_unit_class_register_map()
).
class_type |
Class type (see IpatchUnitClassType). |
[type IpatchUnitClassType] |
src_units |
Source unit type of mapping to lookup |
void ipatch_unit_conversion_register (guint16 src_units
,guint16 dest_units
,IpatchValueTransform func
);
Register a parameter unit conversion function.
[skip]
void ipatch_unit_conversion_register_full (guint16 src_units
,guint16 dest_units
,IpatchValueTransform func
,GDestroyNotify notify_func
,gpointer user_data
);
Register a parameter unit conversion function. Like ipatch_unit_conversion_register()
but friendlier to GObject Introspection.
[rename-to ipatch_unit_conversion_register]
src_units |
Source unit type |
|
dest_units |
Destination unit type |
|
func |
Conversion function handler or |
|
notify_func |
Destroy notification when conversion function is removed. |
[nullable][scope async][closure user_data] |
user_data |
Data to pass to |
[nullable] |
Since: 1.1.0
IpatchValueTransform ipatch_unit_conversion_lookup (guint16 src_units
,guint16 dest_units
,gboolean *set
);
Lookup a conversion function by source and destination unit types.
[skip]
gboolean ipatch_unit_convert (guint16 src_units
,guint16 dest_units
,const GValue *src_val
,GValue *dest_val
);
Convert a value from one unit type to another.
src_units |
Source unit type ID |
|
dest_units |
Destination unit type ID |
|
src_val |
Source value (type should be compatible with the source unit's value type) |
|
dest_val |
Destination value (value should be initialized to a type that is compatible with the destination unit's value type). |
[transfer none] |
TRUE
if value was successfully converted, FALSE
otherwise (the only reasons for failure are invalid function
parameters, no conversion function for the given unit types, or
incompatible GValue types in conversion, therefore the return value
can be safely ignored if the caller is sure the parameters and
types are OK).
double ipatch_unit_user_class_convert (guint16 src_units
,const GValue *src_val
);
Converts a value to "user" units. User units are unit types that
are adequate for human consumption. The IPATCH_UNIT_CLASS_USER
map is used to lookup the corresponding user type to convert to.
Not all unit types have an associated user type or the src_units
type can itself be a user type; in either of these cases the
src_val
is converted as is (possibly converted from another value
type to double).