grim/gobjects-101
Clone
Summary
Browse
Changes
Graph
Move to macros add a subclass and instance method
draft
2021-06-23, Gary Kramlich
e21f4ddf7902
Move to macros add a subclass and instance method
#include
<stdio.h>
#include
"bicycle.h"
G_DEFINE_TYPE
(
GobjectsBicycle
,
gobjects_bicycle
,
G_TYPE_OBJECT
)
/*******************************************************************************
* Default Implementations
******************************************************************************/
static
void
gobjects_bicycle_default_ring_bell
(
GobjectsBicycle
*
bicycle
)
{
printf
(
"%p is ringing it's bell
\n
"
,
bicycle
);
}
/*******************************************************************************
* GObject Implementation
******************************************************************************/
static
void
gobjects_bicycle_init
(
GobjectsBicycle
*
bicycle
)
{
}
static
void
gobjects_bicycle_class_init
(
GobjectsBicycleClass
*
klass
)
{
klass
->
ring_bell
=
gobjects_bicycle_default_ring_bell
;
}
/*******************************************************************************
* Public API
******************************************************************************/
GobjectsBicycle
*
gobjects_bicycle_new
(
void
)
{
return
g_object_new
(
GOBJECTS_TYPE_BICYCLE
,
NULL
);
}
void
gobjects_bicycle_ring_bell
(
GobjectsBicycle
*
bicycle
)
{
GobjectsBicycleClass
*
klass
=
NULL
;
g_return_if_fail
(
GOBJECTS_IS_BICYCLE
(
bicycle
));
klass
=
GOBJECTS_BICYCLE_GET_CLASS
(
bicycle
);
if
(
klass
!=
NULL
&&
klass
->
ring_bell
!=
NULL
)
{
klass
->
ring_bell
(
bicycle
);
}
}