birb/birbassert.h

Tue, 28 Jan 2025 10:49:21 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 28 Jan 2025 10:49:21 -0600
changeset 40
b2c2ca3e8e72
parent 31
ec8986e1d9ba
permissions
-rw-r--r--

Add a license file

Adding the license property to meson required bumping to version 1.1.0.

Testing Done:
Ran `meson dist`

Bugs closed: BIRB-9

Reviewed at https://reviews.imfreedom.org/r/3786/

/*
 * Copyright (C) 2023-2025 Birb Developers
 *
 * Birb is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed
 * with this source distribution
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
 */

#if !defined(BIRB_GLOBAL_HEADER_INSIDE) && !defined(BIRB_COMPILATION)
# error "only <birb.h> may be included directly"
#endif

#ifndef BIRB_ASSERT_H
#define BIRB_ASSERT_H

#include <glib.h>
#include <glib-object.h>

#include "birbversion.h"

G_BEGIN_DECLS

/**
 * birb_assert_type:
 * @instance: the instance whose type to check
 * @type: the required type
 *
 * Asserts that @instance is of type @type.
 *
 * Since: 0.3
 */
#define birb_assert_type(instance, type) G_STMT_START { \
    gpointer _instance = (instance); \
    GType _type = (type); \
    if(_instance == NULL) { \
        char *msg = g_strdup_printf("%s is NULL and not an instance of %s", \
                                    #instance, \
                                    g_type_name(_type)); \
        g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); \
        g_free(msg); \
    } else if(!G_IS_OBJECT(_instance)) { \
        char *msg = g_strdup_printf("%s is not a GObject", #instance); \
        g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); \
        g_free(msg); \
    } else if(G_OBJECT_TYPE(_instance) != _type) { \
        char *msg = g_strdup_printf("%s is of type %s not %s", \
                                    #instance, \
                                    G_OBJECT_TYPE_NAME(_instance), \
                                    g_type_name(_type)); \
        g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); \
        g_free(msg); \
    } \
    } G_STMT_END \
    BIRB_AVAILABLE_MACRO_IN_0_3

G_END_DECLS

#endif /* BIRB_ASSERT_H */

mercurial