summaryrefslogtreecommitdiff
path: root/rushs/evalexpr/variant/variant.h
blob: 9983bc165884e2082ba352d9164ae788ff7ff3aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef VARIANT_H
#define VARIANT_H

#include <stdbool.h>
#include <stddef.h>

enum type
{
    TYPE_INT,
    TYPE_FLOAT,
    TYPE_CHAR,
    TYPE_STRING
};

union type_any
{
    int int_v;
    float float_v;
    char char_v;
    const char *str_v;
};

struct variant
{
    enum type type;
    union type_any value;
};

void variant_display(const struct variant *e);
bool variant_equal(const struct variant *left, const struct variant *right);
int variant_find(const struct variant *array, size_t len, enum type type,
                 union type_any value);
float variant_sum(const struct variant *array, size_t len);

#endif /* !VARIANT_H */