diff --git a/tag.c b/tag.c index c152630..0d35a7f 100644 --- a/tag.c +++ b/tag.c @@ -7,6 +7,7 @@ struct private { char *name; union { long value_as_int; + bool value_as_bool; double value_as_float; char *value_as_string; }; @@ -46,6 +47,13 @@ value_int(const struct tag *tag) 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 * value_float(const struct tag *tag) { @@ -78,6 +86,21 @@ tag_new_int(const char *name, long value) 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 * tag_new_float(const char *name, double value) { diff --git a/tag.h b/tag.h index 78f0936..4722b70 100644 --- a/tag.h +++ b/tag.h @@ -2,6 +2,8 @@ #include +#include + struct tag { void *private; @@ -16,6 +18,7 @@ struct tag_set { }; 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_string(const char *name, const char *value);