## gwymacros gwymacros — Utility macros |

## Functions

#define | gettext()
#define | ngettext()
#define | _()
#define | N_()
#define | GWY_SWAP()
#define | gwy_strequal()
#define | GWY_CLAMP()
#define | gwy_clear()
#define | gwy_object_unref()
#define | gwy_signal_handler_disconnect()
#define | GWY_FIND_PSPEC()
#define | gwy_debug()
void | gwy_debug_gnu ()

## Includes

    #include <libgwyddion/gwyddion.h>

## Description

## Functions

### gettext()

    #define gettext(x) (x)

### ngettext()

    #define ngettext(sing, plur, n) ((n) == 1 ? (sing) : (plur))

### _()

    #define _(x) gettext(x)

### N_()

    #define N_(x) gettext_noop(x)

### GWY_SWAP()

    #define             GWY_SWAP(t, x, y)

Swaps two variables (more precisely lhs and rhs expressions) of type `t` in a single statement.

#### Parameters

t | A C type. |
x | A variable of type `t` to swap with `x` . |
y | A variable of type `t` to swap with `y` . |

### gwy_strequal()

    #define             gwy_strequal(a, b)

Expands to `TRUE` if strings are equal, to `FALSE` otherwise.

#### Parameters

a | A string. |
b | Another string. |

### GWY_CLAMP()

    #define             GWY_CLAMP(x, low, hi)

Ensures that `x` is between the limits set by `low` and `hi` .

This macro differs from GLib's `CLAMP()` by `G_UNLIKELY()` assertions on the tests that `x` is smaller than `low` and larger than `hi` . This makes `x` already being in the right range the fast code path.

It is supposed to be used on results of floating-point operations that should fall to a known range but may occasionaly fail to due to rounding errors and in similar situations. Under normal circumstances, use `CLAMP()`.

#### Parameters

x | The value to clamp. |
low | The minimum value allowed. |
hi | The maximum value allowed. |

### gwy_clear()

    #define             gwy_clear(array, n)

Fills memory block representing an array with zeroes.

This is a shorthand for memset, with the number of bytes to fill calculated from the type of the pointer.

#### Parameters

array | Pointer to an array of values to clear. This argument may be evaluated several times. |
n | Number of items to clear. |

Since: 2.12

### gwy_object_unref()

    #define             gwy_object_unref(obj)

Unreferences an object if it exists.

If `obj` is not `NULL`, `g_object_unref()` is called on it. In all cases `obj` is set to `NULL`.

A useful property of this macro is its idempotence.

If the object reference count is greater than one, assure it should be referenced elsewhere, otherwise it leaks memory.

#### Parameters

obj | A pointer to GObject or `NULL` (must be an l-value). |

### gwy_signal_handler_disconnect()

    #define             gwy_signal_handler_disconnect(obj, hid)

Disconnect a signal handler if it exists.

If `hid` is nonzero and `obj` is not `NULL`, the signal handler identified by `hid` is disconnected. In all cases `hid` is set to 0.

A useful property of this macro is its idempotence.

#### Parameters

obj | A pointer to GObject or `NULL`. |
hid | An `obj` signal handler id or 0 (must be an l-value). |

### GWY_FIND_PSPEC()

    #define             GWY_FIND_PSPEC(type, id, spectype)

A convenience `g_object_class_find_property()` wrapper.

It expands to property spec cast to correct type (`spec` ).

#### Parameters

type | Object type (e.g. `GWY_TYPE_CONTAINER`). |
id | Property id. |
spectype | Param spec type (e.g. `DOUBLE`). |

### gwy_debug()

    #define             gwy_debug(format...)

Prints a debugging message.

Does nothing if compiled without DEBUG defined.

#### Parameters

format... | A format string followed by stuff to print. |

### gwy_debug_gnu ()

    void
    gwy_debug_gnu (const gchar *domain,
                   const gchar *fileline,
                   const gchar *funcname,
                   const gchar *format,
                   ...);

Print a debugging message.

To be used via `gwy_debug()`, should not be used directly.

#### Parameters

domain | Log domain. |
fileline | File and line info. |
funcname | Function name. |
format | Message format. |
... | Message parameters. |

## Types and Values

## See Also

gwyutils -- utility

functions