os/ossrv/glib/tsrc/BC/tests/gobject/testcommon.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* GObject - GLib Type, Object, Parameter and Signal Library
sl@0
     2
 * Copyright (C) 2003 Red Hat, Inc.
sl@0
     3
 *
sl@0
     4
 * This library is free software; you can redistribute it and/or
sl@0
     5
 * modify it under the terms of the GNU Lesser General Public
sl@0
     6
 * License as published by the Free Software Foundation; either
sl@0
     7
 * version 2 of the License, or (at your option) any later version.
sl@0
     8
 *
sl@0
     9
 * This library is distributed in the hope that it will be useful,
sl@0
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
sl@0
    12
 * Lesser General Public License for more details.
sl@0
    13
 *
sl@0
    14
 * You should have received a copy of the GNU Lesser General
sl@0
    15
 * Public License along with this library; if not, write to the
sl@0
    16
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
sl@0
    17
 * Boston, MA 02111-1307, USA.
sl@0
    18
 */
sl@0
    19
sl@0
    20
#ifndef __TEST_COMMON_H__
sl@0
    21
#define __TEST_COMMON_H__
sl@0
    22
sl@0
    23
G_BEGIN_DECLS
sl@0
    24
sl@0
    25
#define DEFINE_TYPE_FULL(name, prefix,				\
sl@0
    26
		         class_init, base_init, instance_init,	\
sl@0
    27
		         parent_type, interface_decl)		\
sl@0
    28
GType								\
sl@0
    29
prefix ## _get_type (void)					\
sl@0
    30
{								\
sl@0
    31
  static GType object_type = 0;					\
sl@0
    32
								\
sl@0
    33
  if (!object_type)						\
sl@0
    34
    {								\
sl@0
    35
      static const GTypeInfo object_info =			\
sl@0
    36
	{							\
sl@0
    37
	  sizeof (name ## Class),				\
sl@0
    38
	  (GBaseInitFunc) base_init,				\
sl@0
    39
	  (GBaseFinalizeFunc) NULL,				\
sl@0
    40
	  (GClassInitFunc) class_init,				\
sl@0
    41
	  (GClassFinalizeFunc) NULL,				\
sl@0
    42
	  NULL,           /* class_data */			\
sl@0
    43
	  sizeof (name),					\
sl@0
    44
	  0,             /* n_prelocs */			\
sl@0
    45
	  (GInstanceInitFunc) instance_init			\
sl@0
    46
	};							\
sl@0
    47
								\
sl@0
    48
      object_type = g_type_register_static (parent_type,	\
sl@0
    49
					    # name,		\
sl@0
    50
					    &object_info, 0);	\
sl@0
    51
      interface_decl						\
sl@0
    52
    }								\
sl@0
    53
								\
sl@0
    54
  return object_type;						\
sl@0
    55
}
sl@0
    56
sl@0
    57
#define DEFINE_TYPE(name, prefix,				\
sl@0
    58
		    class_init, base_init, instance_init,	\
sl@0
    59
		    parent_type)				\
sl@0
    60
  DEFINE_TYPE_FULL(name, prefix, class_init, base_init,		\
sl@0
    61
		   instance_init, parent_type, {})
sl@0
    62
sl@0
    63
#define DEFINE_IFACE(name, prefix, base_init, dflt_init)	\
sl@0
    64
GType								\
sl@0
    65
prefix ## _get_type (void)					\
sl@0
    66
{								\
sl@0
    67
  static GType iface_type = 0;					\
sl@0
    68
								\
sl@0
    69
  if (!iface_type)						\
sl@0
    70
    {								\
sl@0
    71
      static const GTypeInfo iface_info =			\
sl@0
    72
      {								\
sl@0
    73
	sizeof (name ## Class),					\
sl@0
    74
	(GBaseInitFunc)	base_init,				\
sl@0
    75
	(GBaseFinalizeFunc) NULL,				\
sl@0
    76
	(GClassInitFunc) dflt_init,				\
sl@0
    77
      };							\
sl@0
    78
								\
sl@0
    79
      iface_type = g_type_register_static (G_TYPE_INTERFACE,	\
sl@0
    80
					    # name,		\
sl@0
    81
					    &iface_info, 0);	\
sl@0
    82
    }								\
sl@0
    83
  return iface_type;						\
sl@0
    84
}
sl@0
    85
sl@0
    86
#define INTERFACE_FULL(type, init_func, iface_type)		\
sl@0
    87
{								\
sl@0
    88
  static GInterfaceInfo const iface =				\
sl@0
    89
    {								\
sl@0
    90
      (GInterfaceInitFunc) init_func, NULL, NULL		\
sl@0
    91
    };								\
sl@0
    92
								\
sl@0
    93
  g_type_add_interface_static (type, iface_type, &iface);	\
sl@0
    94
}
sl@0
    95
#define INTERFACE(init_func, iface_type)	\
sl@0
    96
  INTERFACE_FULL(object_type, init_func, iface_type)
sl@0
    97
sl@0
    98
G_END_DECLS
sl@0
    99
sl@0
   100
#endif /* __TEST_COMMON_H__ */