Derive-C
Loading...
Searching...
No Matches
option.c File Reference
#include <stdlib.h>
#include <string.h>
#include <derive-c/core/prelude.h>
#include <derive-c/utils/option/template.h>
Include dependency graph for option.c:

Go to the source code of this file.

Classes

struct  complex_data

Macros

#define ITEM   struct complex_data
#define ITEM_DELETE   complex_data_delete
#define ITEM_CLONE   complex_data_clone
#define NAME   complex_data_option

Functions

void complex_data_delete (struct complex_data *self)
struct complex_data complex_data_clone (struct complex_data const *self)
void option_example ()
int main ()

Macro Definition Documentation

◆ ITEM

#define ITEM   struct complex_data

Definition at line 25 of file option.c.

◆ ITEM_CLONE

#define ITEM_CLONE   complex_data_clone

Definition at line 27 of file option.c.

◆ ITEM_DELETE

#define ITEM_DELETE   complex_data_delete

Definition at line 26 of file option.c.

◆ NAME

#define NAME   complex_data_option

Definition at line 28 of file option.c.

Function Documentation

◆ complex_data_clone()

struct complex_data complex_data_clone ( struct complex_data const * self)
Examples
utils/option.c.

Definition at line 17 of file option.c.

17 {
18 return (struct complex_data){
19 .x = self->x,
20 .y = self->y,
21 .description = strdup(self->description),
22 };
23}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ complex_data_delete()

void complex_data_delete ( struct complex_data * self)
Examples
container/vector/dynamic.c, and utils/option.c.

Definition at line 16 of file option.c.

16{ free(self->description); }
static void free(SELF *self, void *ptr)
Definition template.h:58
char * description
Definition option.c:13
Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 54 of file option.c.

54{ option_example(); }
void option_example()
Definition option.c:31
Here is the call graph for this function:

◆ option_example()

void option_example ( )
Examples
utils/option.c.

Definition at line 31 of file option.c.

31 {
32 complex_data_option opt = complex_data_option_empty();
33 ASSERT(!complex_data_option_is_present(&opt));
34
35 // when accessing a value, you get a pointer. Not present = NULL
36 ASSERT(!complex_data_option_get(&opt));
37 ASSERT(!complex_data_option_get_const(&opt));
38
39 bool was_present_1 = complex_data_option_replace(
40 &opt, (struct complex_data){.x = 42, .y = 3.14, .description = strdup("A complex data")});
41 ASSERT(!was_present_1);
42
43 ASSERT(complex_data_option_is_present(&opt));
44 ASSERT(complex_data_option_get(&opt));
45
46 bool was_present_2 = complex_data_option_replace(
47 &opt,
48 (struct complex_data){.x = 100, .y = 2.71, .description = strdup("Another complex data")});
49 ASSERT(was_present_2);
50
51 complex_data_option_delete(&opt);
52}
#define ASSERT(expr,...)
Definition macros.h:42
Here is the caller graph for this function: