Utilities — Assorted macros and functions
#define ADG_FORWARD_DECL (id) #define ADG_DIR_RIGHT #define ADG_DIR_DOWN #define ADG_DIR_LEFT #define ADG_DIR_UP #define ADG_UTF8_DIAMETER #define ADG_UTF8_DEGREE gint g_strcmp0 (const gchar *s1, const gchar *s2); gboolean adg_is_string_empty (const gchar *str); gboolean adg_is_enum_value (int value, GType enum_type); gboolean adg_is_boolean_value (gboolean value); gchar * adg_string_replace (const gchar *str, const gchar *from, const gchar *to);
#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 {
...
};
|
|
The name of a struct |
#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 "<>");
#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);
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
|
|
a C string or NULL |
|
|
another C string or NULL |
|
Returns : |
-1, 0 or 1, if str1 is <, == or > than str2.
|
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'.
|
|
the subject string |
|
Returns : |
TRUE if str is an empty string, FALSE otherwise
|
gboolean adg_is_enum_value (int value,
GType enum_type);
Checks if value is a valid enum_type value.
|
|
the enum value to check |
|
|
a GEnum based type |
|
Returns : |
TRUE if value is a valid enum_type, FALSE otherwise
|
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.
|
|
the gboolean value to check |
|
Returns : |
TRUE if value is a valid gboolean, FALSE otherwise
|
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.
|
|
the original string |
|
|
the substring to replace |
|
|
the replacement string |
|
Returns : |
a newly allocated string to be freed with g_free() or NULL on errors |