Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix prototype, and use boolean operators.
[simgrid.git] / include / xbt / automaton.h
1 /* Copyright (c) 2011-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef XBT_AUTOMATON_H
7 #define XBT_AUTOMATON_H
8
9 #include <xbt/dynar.h>
10
11 SG_BEGIN_DECL
12
13 typedef struct xbt_automaton_state {
14   char* id;
15   int type; /* -1 = init, 0 = inter, 1 = final */
16   xbt_dynar_t in;
17   xbt_dynar_t out;
18 } s_xbt_automaton_state;
19
20 typedef struct xbt_automaton_state* xbt_automaton_state_t;
21
22 typedef struct xbt_automaton {
23   xbt_dynar_t propositional_symbols;
24   xbt_dynar_t transitions;
25   xbt_dynar_t states;
26   xbt_automaton_state_t current_state;
27 } s_xbt_automaton;
28
29 typedef struct xbt_automaton* xbt_automaton_t;
30
31 typedef struct xbt_automaton_exp_label{
32   enum{AUT_OR=0, AUT_AND=1, AUT_NOT=2, AUT_PREDICAT=3, AUT_ONE=4} type;
33   union{
34     struct{
35       struct xbt_automaton_exp_label* left_exp;
36       struct xbt_automaton_exp_label* right_exp;
37     }or_and;
38     struct xbt_automaton_exp_label* exp_not;
39     char* predicat;
40   }u;
41 } s_xbt_automaton_exp_label;
42
43 typedef struct xbt_automaton_exp_label* xbt_automaton_exp_label_t;
44
45 typedef struct xbt_automaton_transition {
46   xbt_automaton_state_t src;
47   xbt_automaton_state_t dst;
48   xbt_automaton_exp_label_t label;
49 } s_xbt_automaton_transition;
50
51 typedef struct xbt_automaton_transition* xbt_automaton_transition_t;
52
53 typedef struct xbt_automaton_propositional_symbol* xbt_automaton_propositional_symbol_t;
54
55 typedef int (*xbt_automaton_propositional_symbol_callback_type)(void*);
56 typedef void (*xbt_automaton_propositional_symbol_free_function_type)(void*);
57
58 XBT_PUBLIC xbt_automaton_t xbt_automaton_new(void);
59 XBT_PUBLIC void xbt_automaton_load(xbt_automaton_t automaton, const char* file);
60 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_state_new(xbt_automaton_t a, int type, char* id);
61 XBT_PUBLIC xbt_automaton_transition_t xbt_automaton_transition_new(xbt_automaton_t a, xbt_automaton_state_t src,
62                                                                    xbt_automaton_state_t dst,
63                                                                    xbt_automaton_exp_label_t label);
64 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_or(xbt_automaton_exp_label_t left,
65                                                                     xbt_automaton_exp_label_t right);
66 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_and(xbt_automaton_exp_label_t left,
67                                                                      xbt_automaton_exp_label_t right);
68 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_not(xbt_automaton_exp_label_t exp_not);
69 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_predicat(char* p);
70 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_one(void);
71 XBT_PUBLIC xbt_dynar_t xbt_automaton_get_states(xbt_automaton_t a);
72 XBT_PUBLIC xbt_dynar_t xbt_automaton_get_transitions(xbt_automaton_t a);
73 XBT_PUBLIC xbt_automaton_transition_t xbt_automaton_get_transition(xbt_automaton_t a, xbt_automaton_state_t src,
74                                                                    xbt_automaton_state_t dst);
75 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_transition_get_source(xbt_automaton_transition_t t);
76 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_transition_get_destination(xbt_automaton_transition_t t);
77 XBT_PUBLIC void xbt_automaton_transition_set_source(xbt_automaton_transition_t t, xbt_automaton_state_t src);
78 XBT_PUBLIC void xbt_automaton_transition_set_destination(xbt_automaton_transition_t t, xbt_automaton_state_t dst);
79 XBT_PUBLIC xbt_dynar_t xbt_automaton_state_get_out_transitions(xbt_automaton_state_t s);
80 XBT_PUBLIC xbt_dynar_t xbt_automaton_state_get_in_transitions(xbt_automaton_state_t s);
81 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_state_exists(xbt_automaton_t a, char* id);
82 XBT_PUBLIC void xbt_automaton_display(xbt_automaton_t a);
83 XBT_PUBLIC void xbt_automaton_exp_label_display(xbt_automaton_exp_label_t l);
84
85 // xbt_automaton_propositional_symbol constructors:
86 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new(xbt_automaton_t a,
87                                                                                        const char* id,
88                                                                                        int (*fct)(void));
89 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new_pointer(xbt_automaton_t a,
90                                                                                                const char* id,
91                                                                                                int* value);
92 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new_callback(
93     xbt_automaton_t a, const char* id, xbt_automaton_propositional_symbol_callback_type callback, void* data,
94     xbt_automaton_propositional_symbol_free_function_type free_function);
95
96 // xbt_automaton_propositional_symbol accessors:
97 XBT_PUBLIC xbt_automaton_propositional_symbol_callback_type
98 xbt_automaton_propositional_symbol_get_callback(xbt_automaton_propositional_symbol_t symbol);
99 XBT_PUBLIC void* xbt_automaton_propositional_symbol_get_data(xbt_automaton_propositional_symbol_t symbol);
100 XBT_PUBLIC const char* xbt_automaton_propositional_symbol_get_name(xbt_automaton_propositional_symbol_t symbol);
101
102 // xbt_automaton_propositional_symbol methods!
103 XBT_PUBLIC int xbt_automaton_propositional_symbol_evaluate(xbt_automaton_propositional_symbol_t symbol);
104
105 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_get_current_state(xbt_automaton_t a);
106 XBT_PUBLIC int xbt_automaton_state_compare(xbt_automaton_state_t s1, xbt_automaton_state_t s2);
107 XBT_PUBLIC int xbt_automaton_propositional_symbols_compare_value(xbt_dynar_t s1, xbt_dynar_t s2);
108 XBT_PUBLIC int xbt_automaton_transition_compare(xbt_automaton_transition_t t1, xbt_automaton_transition_t t2);
109 XBT_PUBLIC int xbt_automaton_exp_label_compare(xbt_automaton_exp_label_t l1, xbt_automaton_exp_label_t l2);
110 XBT_PUBLIC void xbt_automaton_state_free_voidp(void* s);
111 XBT_PUBLIC void xbt_automaton_state_free(xbt_automaton_state_t s);
112 XBT_PUBLIC void xbt_automaton_transition_free_voidp(void* t);
113 XBT_PUBLIC void xbt_automaton_exp_label_free_voidp(void* e);
114 XBT_PUBLIC void xbt_automaton_propositional_symbol_free_voidp(void* ps);
115 XBT_PUBLIC void xbt_automaton_free(xbt_automaton_t a);
116
117 SG_END_DECL
118
119 #endif