parent
0a4957627a
commit
ab004ab189
8 changed files with 176 additions and 1 deletions
@ -0,0 +1,41 @@ |
||||
/*** BEGIN file-header ***/ |
||||
|
||||
#include "enums.h" |
||||
|
||||
/*** END file-header ***/ |
||||
/*** BEGIN file-production ***/ |
||||
|
||||
/* enumerations from "@basename@" */ |
||||
#include "@basename@" |
||||
|
||||
/*** END file-production ***/ |
||||
|
||||
/*** BEGIN value-header ***/ |
||||
GType |
||||
@enum_name@_get_type(void) { |
||||
static volatile gsize g_define_type_id__volatile = 0; |
||||
|
||||
if(g_once_init_enter(&g_define_type_id__volatile)) { |
||||
static const G@Type@Value values [] = { |
||||
/*** END value-header ***/ |
||||
|
||||
/*** BEGIN value-production ***/ |
||||
{ @VALUENAME@, "@VALUENAME@", "@valuenick@" }, |
||||
/*** END value-production ***/ |
||||
|
||||
/*** BEGIN value-tail ***/ |
||||
{ 0, NULL, NULL } |
||||
}; |
||||
|
||||
GType g_define_type_id = |
||||
g_@type@_register_static(g_intern_static_string("@EnumName@"), values); |
||||
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); |
||||
} |
||||
|
||||
return g_define_type_id__volatile; |
||||
} |
||||
|
||||
/*** END value-tail ***/ |
||||
|
||||
/*** BEGIN file-tail ***/ |
||||
/*** END file-tail ***/ |
@ -0,0 +1,24 @@ |
||||
/*** BEGIN file-header ***/ |
||||
#ifndef MESON_ENUMS_H |
||||
#define MESON_ENUMS_H |
||||
|
||||
#include <glib-object.h> |
||||
|
||||
G_BEGIN_DECLS |
||||
/*** END file-header ***/ |
||||
|
||||
/*** BEGIN file-production ***/ |
||||
|
||||
/* enumerations from "@basename@" */ |
||||
/*** END file-production ***/ |
||||
/*** BEGIN value-header ***/ |
||||
GType @enum_name@_get_type(void) G_GNUC_CONST; |
||||
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) |
||||
/*** END value-header ***/ |
||||
|
||||
/*** BEGIN file-tail ***/ |
||||
|
||||
G_END_DECLS |
||||
|
||||
#endif /* MESON_ENUMS_H */ |
||||
/*** END file-tail ***/ |
@ -0,0 +1,30 @@ |
||||
#include<stdio.h> |
||||
#include<string.h> |
||||
#include<glib-object.h> |
||||
#include"meson-sample.h" |
||||
#include"enums.h" |
||||
|
||||
int main(int argc, char **argv) { |
||||
GEnumClass *xenum = g_type_class_ref(MESON_TYPE_THE_XENUM); |
||||
GFlagsClass *flags_enum = g_type_class_ref(MESON_TYPE_THE_FLAGS_ENUM); |
||||
if (g_enum_get_value_by_name(xenum, "MESON_THE_XVALUE")->value != MESON_THE_XVALUE) { |
||||
fprintf(stderr, "Get MESON_THE_XVALUE by name failed.\n"); |
||||
return 1; |
||||
} |
||||
if (g_enum_get_value_by_nick(xenum, "the-xvalue")->value != MESON_THE_XVALUE) { |
||||
fprintf(stderr, "Get MESON_THE_XVALUE by nick failed.\n"); |
||||
return 2; |
||||
} |
||||
if (g_flags_get_value_by_name(flags_enum, "MESON_THE_FIRST_VALUE")->value != MESON_THE_FIRST_VALUE) { |
||||
fprintf(stderr, "Get MESON_THE_FIRST_VALUE by name failed.\n"); |
||||
return 3; |
||||
} |
||||
if (g_flags_get_value_by_nick(flags_enum, "the-first-value")->value != MESON_THE_FIRST_VALUE) { |
||||
fprintf(stderr, "Get MESON_THE_FIRST_VALUE by nick failed.\n"); |
||||
return 4; |
||||
} |
||||
g_type_class_unref(xenum); |
||||
g_type_class_unref(flags_enum); |
||||
fprintf(stderr, "All ok.\n"); |
||||
return 0; |
||||
} |
@ -0,0 +1,18 @@ |
||||
typedef enum |
||||
{ |
||||
MESON_THE_XVALUE, |
||||
MESON_ANOTHER_VALUE |
||||
} MesonTheXEnum; |
||||
|
||||
typedef enum /*< skip >*/ |
||||
{ |
||||
MESON_FOO |
||||
} MesonThisEnumWillBeSkipped; |
||||
|
||||
typedef enum /*< flags,prefix=MESON >*/ |
||||
{ |
||||
MESON_THE_ZEROTH_VALUE, /*< skip >*/ |
||||
MESON_THE_FIRST_VALUE, |
||||
MESON_THE_SECOND_VALUE, |
||||
MESON_THE_THIRD_VALUE, /*< nick=the-last-value >*/ |
||||
} MesonTheFlagsEnum; |
@ -0,0 +1,14 @@ |
||||
enums_h = gnome.mkenums('enums.h', |
||||
sources : 'meson-sample.h', |
||||
template : 'enums.h.in', |
||||
install : true, |
||||
install_dir : get_option('includedir')) |
||||
|
||||
enums_c = gnome.mkenums('enums.c', |
||||
sources : 'meson-sample.h', |
||||
template : 'enums.c.in', |
||||
depends : enums_h) |
||||
|
||||
enumexe = executable('enumprog', 'main.c', enums_c, enums_h, |
||||
dependencies : gobj) |
||||
test('enum test', enumexe) |
Loading…
Reference in new issue