GwySIUnit

GwySIUnit — SI unit representation

Synopsis




typedef     GwySIValueFormat;
struct      GwySIUnit;
struct      GwySIUnitClass;
GObject*    gwy_si_unit_new                 (const gchar *unit_string);
void        gwy_si_unit_set_unit_string     (GwySIUnit *siunit,
                                             gchar *unit_string);
gchar*      gwy_si_unit_get_unit_string     (GwySIUnit *siunit);
GwySIValueFormat* gwy_si_unit_get_format    (GwySIUnit *siunit,
                                             gdouble value,
                                             GwySIValueFormat *format);
GwySIValueFormat* gwy_si_unit_get_format_with_resolution
                                            (GwySIUnit *siunit,
                                             gdouble maximum,
                                             gdouble resolution,
                                             GwySIValueFormat *format);
GwySIValueFormat* gwy_si_unit_get_format_with_digits
                                            (GwySIUnit *siunit,
                                             gdouble maximum,
                                             gint sdigits,
                                             GwySIValueFormat *format);
void        gwy_si_unit_value_format_free   (GwySIValueFormat *format);

Object Hierarchy


  GObject
   +----GwySIUnit

Implemented Interfaces

GwySIUnit implements GwySerializable.

Description

This object is used for representing SI unit (or any other unit). It is also responsible for prefixes selection.

Details

GwySIValueFormat

typedef struct {
    gdouble magnitude;
    gint precision;
    gchar *units;
} GwySIValueFormat;


struct GwySIUnit

struct GwySIUnit;


struct GwySIUnitClass

struct GwySIUnitClass {

    GObjectClass parent_class;

    gpointer *reserved1;
    gpointer *reserved2;
};


gwy_si_unit_new ()

GObject*    gwy_si_unit_new                 (const gchar *unit_string);

Unit string represents unit with no prefixes (e. g. "m", "N", "A", etc.)

unit_string: unit string
Returns : a new GwySiUnit with a given string

gwy_si_unit_set_unit_string ()

void        gwy_si_unit_set_unit_string     (GwySIUnit *siunit,
                                             gchar *unit_string);

Sets string that represents unit. It is the unit with no prefixes (e. g. "m", "N", "A", etc.)

siunit: GwySiUnit
unit_string: unit string to be set

gwy_si_unit_get_unit_string ()

gchar*      gwy_si_unit_get_unit_string     (GwySIUnit *siunit);

siunit: GwySiUnit
Returns : string that represents unit (with no prefixes)

gwy_si_unit_get_format ()

GwySIValueFormat* gwy_si_unit_get_format    (GwySIUnit *siunit,
                                             gdouble value,
                                             GwySIValueFormat *format);

Finds reasonable representation for a number. This means that number value should be written as value / number->magnitude [number->units].

siunit: GwySiUnit
value: input value
format: returned number representation parameters
Returns : The value format. If format was NULL, a newly allocated format is returned, otherwise (modified) format itself is returned.

gwy_si_unit_get_format_with_resolution ()

GwySIValueFormat* gwy_si_unit_get_format_with_resolution
                                            (GwySIUnit *siunit,
                                             gdouble maximum,
                                             gdouble resolution,
                                             GwySIValueFormat *format);

Finds a good format for representing a range of values with given resolution.

The values should be then printed as value/format->magnitude [format->units] with format->precision decimal places.

siunit: A SI unit.
maximum: The maximum value to be represented.
resolution: The smallest step (approximately) that should make a visible difference in the representation.
format: A value format to set-up, may be NULL, a new value format is allocated then.
Returns : The value format. If format was NULL, a newly allocated format is returned, otherwise (modified) format itself is returned.

gwy_si_unit_get_format_with_digits ()

GwySIValueFormat* gwy_si_unit_get_format_with_digits
                                            (GwySIUnit *siunit,
                                             gdouble maximum,
                                             gint sdigits,
                                             GwySIValueFormat *format);

Finds a good format for representing a values with given number of significant digits.

The values should be then printed as value/format->magnitude [format->units] with format->precision decimal places.

siunit: A SI unit.
maximum: The maximum value to be represented.
sdigits: The number of significant digits the value should have.
format: A value format to set-up, may be NULL, a new value format is allocated then.
Returns : The value format. If format was NULL, a newly allocated format is returned, otherwise (modified) format itself is returned.

gwy_si_unit_value_format_free ()

void        gwy_si_unit_value_format_free   (GwySIValueFormat *format);

Frees a value format structure.

format: A value format to free.