mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
tag: add a boolean tag
This commit is contained in:
parent
081bccf06d
commit
12e9304612
2 changed files with 26 additions and 0 deletions
23
tag.c
23
tag.c
|
@ -7,6 +7,7 @@ struct private {
|
||||||
char *name;
|
char *name;
|
||||||
union {
|
union {
|
||||||
long value_as_int;
|
long value_as_int;
|
||||||
|
bool value_as_bool;
|
||||||
double value_as_float;
|
double value_as_float;
|
||||||
char *value_as_string;
|
char *value_as_string;
|
||||||
};
|
};
|
||||||
|
@ -46,6 +47,13 @@ value_int(const struct tag *tag)
|
||||||
return as_string;
|
return as_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
value_bool(const struct tag *tag)
|
||||||
|
{
|
||||||
|
const struct private *priv = tag->private;
|
||||||
|
return priv->value_as_bool ? "true" : "false";
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
value_float(const struct tag *tag)
|
value_float(const struct tag *tag)
|
||||||
{
|
{
|
||||||
|
@ -78,6 +86,21 @@ tag_new_int(const char *name, long value)
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct tag *
|
||||||
|
tag_new_bool(const char *name, bool value)
|
||||||
|
{
|
||||||
|
struct private *priv = malloc(sizeof(*priv));
|
||||||
|
priv->name = strdup(name);
|
||||||
|
priv->value_as_int = value;
|
||||||
|
|
||||||
|
struct tag *tag = malloc(sizeof(*tag));
|
||||||
|
tag->private = priv;
|
||||||
|
tag->destroy = &destroy_int_and_float;
|
||||||
|
tag->name = &tag_name;
|
||||||
|
tag->value = &value_bool;
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
struct tag *
|
struct tag *
|
||||||
tag_new_float(const char *name, double value)
|
tag_new_float(const char *name, double value)
|
||||||
{
|
{
|
||||||
|
|
3
tag.h
3
tag.h
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct tag {
|
struct tag {
|
||||||
void *private;
|
void *private;
|
||||||
|
|
||||||
|
@ -16,6 +18,7 @@ struct tag_set {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tag *tag_new_int(const char *name, long value);
|
struct tag *tag_new_int(const char *name, long value);
|
||||||
|
struct tag *tag_new_bool(const char *name, bool value);
|
||||||
struct tag *tag_new_float(const char *name, double value);
|
struct tag *tag_new_float(const char *name, double value);
|
||||||
struct tag *tag_new_string(const char *name, const char *value);
|
struct tag *tag_new_string(const char *name, const char *value);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue