Examples for using the option type.
Examples for using the option type.
#include <stdio.h>
#include <stdlib.h>
};
.value = self->value,
.description = strdup(self->description),
};
}
fprintf(
stream,
"example_data@%p {\n", (
void*)self);
}
#define ITEM struct example_data
#define ITEM_DELETE example_data_delete
#define ITEM_CLONE example_data_clone
#define ITEM_DEBUG example_data_debug
#define NAME example_option
present_option = example_option_from(
(
struct example_data){.value = 42, .description = strdup(
"A present option")});
DC_SCOPED(example_option) empty_option = example_option_empty();
fprintf(stdout, "\n");
fprintf(stdout, "\n");
DC_ASSERT(example_option_is_present(&present_option));
DC_ASSERT(!example_option_is_present(&empty_option));
struct example_data const* present_data = example_option_get_const(&present_option);
struct example_data const* empty_data = example_option_get_const(&empty_option);
bool was_present = example_option_replace(
&empty_option,
(
struct example_data){.value = 100, .description = strdup(
"Replaced value")});
DC_ASSERT(example_option_is_present(&empty_option));
struct example_data const* replaced_data = example_option_get_const(&empty_option);
}
return 0;
}
static void example_data_debug(struct example_data const *self, dc_debug_fmt fmt, FILE *stream)
static void example_data_delete(struct example_data *self)
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_new()
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
static struct example_data example_data_clone(struct example_data const *self)
static void example_option_example()
#define DC_ASSERT(expr,...)
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
Debug format helpers for debug printin data structures.
static DC_PUBLIC FILE * stream(SELF *self)