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

Go to the source code of this file.

Classes

struct  complex_data
 

Macros

#define T   struct complex_data
 
#define T_DELETE   complex_data_delete
 
#define SELF   complex_data_option
 

Functions

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

Macro Definition Documentation

◆ SELF

#define SELF   complex_data_option

Definition at line 19 of file option.c.

◆ T

#define T   struct complex_data

Definition at line 17 of file option.c.

◆ T_DELETE

#define T_DELETE   complex_data_delete

Definition at line 18 of file option.c.

Function Documentation

◆ complex_data_delete()

void complex_data_delete ( struct complex_data * self)
Examples
structures/option.c.

Definition at line 15 of file option.c.

15{ free(self->description); }
char * description
Definition option.c:12

◆ main()

int main ( )

Definition at line 45 of file option.c.

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

◆ option_example()

void option_example ( )
Examples
structures/option.c.

Definition at line 22 of file option.c.

22 {
23 complex_data_option opt = complex_data_option_empty();
24 assert(!complex_data_option_is_present(&opt));
25
26 // when accessing a value, you get a pointer. Not present = NULL
27 assert(!complex_data_option_get(&opt));
28 assert(!complex_data_option_get_const(&opt));
29
30 bool was_present_1 = complex_data_option_replace(
31 &opt, (struct complex_data){.x = 42, .y = 3.14, .description = strdup("A complex data")});
32 assert(!was_present_1);
33
34 assert(complex_data_option_is_present(&opt));
35 assert(complex_data_option_get(&opt));
36
37 bool was_present_2 = complex_data_option_replace(
38 &opt,
39 (struct complex_data){.x = 100, .y = 2.71, .description = strdup("Another complex data")});
40 assert(was_present_2);
41
42 complex_data_option_delete(&opt);
43}
Here is the caller graph for this function: