Utilities

Utilities — Assorted macros and functions

Synopsis

#define             ADG_DIR_DOWN
#define             ADG_DIR_LEFT
#define             ADG_DIR_RIGHT
#define             ADG_DIR_UP
#define             ADG_FORWARD_DECL                    (id)
#define             ADG_UTF8_DEGREE
#define             ADG_UTF8_DIAMETER
struct              AdgClosure;
gboolean            adg_is_boolean_value                (gboolean value);
gboolean            adg_is_enum_value                   (int value,
                                                         GType enum_type);
gboolean            adg_is_string_empty                 (const gchar *str);
gchar *             adg_string_replace                  (const gchar *str,
                                                         const gchar *from,
                                                         const gchar *to);
gint                g_strcmp0                           (const gchar *s1,
                                                         const gchar *s2);

Description

Collection of macros and functions that do not fit inside any other topic.

Details

ADG_DIR_DOWN

#define ADG_DIR_DOWN            G_PI_2

Symbolic constant for the down direction (in radians).

Since 1.0


ADG_DIR_LEFT

#define ADG_DIR_LEFT            G_PI

Symbolic constant for the left direction (in radians).

Since 1.0


ADG_DIR_RIGHT

#define ADG_DIR_RIGHT           0.

Symbolic constant for the right direction (in radians).

Since 1.0


ADG_DIR_UP

#define ADG_DIR_UP              -G_PI_2

Symbolic constant for the up direction (in radians).

Since 1.0


ADG_FORWARD_DECL()

#define ADG_FORWARD_DECL(id)    typedef struct _##id id

Forward declaration of struct id. It is equivalent to a typical struct forward declaration, for example:

ADG_FORWARD_DECL(test)

will expand to:

typedef struct _test test

This macro is needed to fake gtk-doc, because up to now (v.1.12) it generates two conflicting links when using forward declarations: the first in the source with the declaration and the second where the type is defined. Using ADG_FORWARD_DECL() instead of the usual typedef avoids the parsing of the declaration in the first file (gtk-doc is not able to do C preprocessing).

The same principle can be applied in the definition file. Following the previous example, you can use something like this where struct _type is defined:

#if 0
// This is declared in another file
typedef struct _type type;
#endif
struct _type {
...
};

id :

The name of a struct

Since 1.0


ADG_UTF8_DEGREE

#define ADG_UTF8_DEGREE         "\xC2\xB0"

String constant that embeds a UTF-8 encoded degree symbol (U+00B0). It is used to suffix by the default implementation of AdgADim to suffix the set value, but can be also used manually:

adg_dim_set_value(dim, "<>" ADG_UTF8_DEGREE);

Since 1.0


ADG_UTF8_DIAMETER

#define ADG_UTF8_DIAMETER       "\xE2\x8C\x80"

String constant that embeds a UTF-8 encoded diameter (U+2300). It can be used to prefix diameter quotes, such as:

adg_dim_set_value(dim, ADG_UTF8_DIAMETER "<>");

Since 1.0


struct AdgClosure

struct AdgClosure {
    GCallback       callback;
    gpointer        user_data;
};

adg_is_boolean_value ()

gboolean            adg_is_boolean_value                (gboolean value);

Checks if value is a valid gboolean value, that is if it is TRUE or FALSE. No other values are accepted.

value :

the gboolean value to check

Returns :

TRUE if value is a valid gboolean, FALSE otherwise

Since 1.0


adg_is_enum_value ()

gboolean            adg_is_enum_value                   (int value,
                                                         GType enum_type);

Checks if value is a valid enum_type value.

value :

the enum value to check

enum_type :

a GEnum based type

Returns :

TRUE if value is a valid enum_type, FALSE otherwise

Since 1.0


adg_is_string_empty ()

gboolean            adg_is_string_empty                 (const gchar *str);

Checks if str is an empty string, that is if is NULL or if its first character is %'\0'.

str :

the subject string

Returns :

TRUE if str is an empty string, FALSE otherwise

Since 1.0


adg_string_replace ()

gchar *             adg_string_replace                  (const gchar *str,
                                                         const gchar *from,
                                                         const gchar *to);

Replaces from with to inside str and returns the result as a newly allocated string.

str and from must be non-null valid C strings while to can be NULL, in which case an empty string ("") will be implied.

str :

the original string

from :

the substring to replace

to :

the replacement string

Returns :

a newly allocated string to be freed with g_free() or NULL on errors

Since 1.0


g_strcmp0 ()

gint                g_strcmp0                           (const gchar *s1,
                                                         const gchar *s2);

Compares str1 and str2 like strcmp(). Handles NULL gracefully by sorting it before non-NULL strings. This is a backward compatibility fallback for GLib prior to 2.16.0

str1 :

a C string or NULL

str2 :

another C string or NULL

Returns :

-1, 0 or 1, if str1 is <, == or > than str2.

Since 1.0