Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #272 from mpoquet/SMPI_convert
[simgrid.git] / include / xbt / automaton.h
1 /* Copyright (c) 2011-2018. 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(int type, ...);
65 XBT_PUBLIC xbt_dynar_t xbt_automaton_get_states(xbt_automaton_t a);
66 XBT_PUBLIC xbt_dynar_t xbt_automaton_get_transitions(xbt_automaton_t a);
67 XBT_PUBLIC xbt_automaton_transition_t xbt_automaton_get_transition(xbt_automaton_t a, xbt_automaton_state_t src,
68                                                                    xbt_automaton_state_t dst);
69 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_transition_get_source(xbt_automaton_transition_t t);
70 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_transition_get_destination(xbt_automaton_transition_t t);
71 XBT_PUBLIC void xbt_automaton_transition_set_source(xbt_automaton_transition_t t, xbt_automaton_state_t src);
72 XBT_PUBLIC void xbt_automaton_transition_set_destination(xbt_automaton_transition_t t, xbt_automaton_state_t dst);
73 XBT_PUBLIC xbt_dynar_t xbt_automaton_state_get_out_transitions(xbt_automaton_state_t s);
74 XBT_PUBLIC xbt_dynar_t xbt_automaton_state_get_in_transitions(xbt_automaton_state_t s);
75 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_state_exists(xbt_automaton_t a, char* id);
76 XBT_PUBLIC void xbt_automaton_display(xbt_automaton_t a);
77 XBT_PUBLIC void xbt_automaton_exp_label_display(xbt_automaton_exp_label_t l);
78
79 // xbt_automaton_propositional_symbol constructors:
80 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new(xbt_automaton_t a,
81                                                                                        const char* id,
82                                                                                        int (*fct)(void));
83 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new_pointer(xbt_automaton_t a,
84                                                                                                const char* id,
85                                                                                                int* value);
86 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new_callback(
87     xbt_automaton_t a, const char* id, xbt_automaton_propositional_symbol_callback_type callback, void* data,
88     xbt_automaton_propositional_symbol_free_function_type free_function);
89
90 // xbt_automaton_propositional_symbol accessors:
91 XBT_PUBLIC xbt_automaton_propositional_symbol_callback_type
92 xbt_automaton_propositional_symbol_get_callback(xbt_automaton_propositional_symbol_t symbol);
93 XBT_PUBLIC void* xbt_automaton_propositional_symbol_get_data(xbt_automaton_propositional_symbol_t symbol);
94 XBT_PUBLIC const char* xbt_automaton_propositional_symbol_get_name(xbt_automaton_propositional_symbol_t symbol);
95
96 // xbt_automaton_propositional_symbol methods!
97 XBT_PUBLIC int xbt_automaton_propositional_symbol_evaluate(xbt_automaton_propositional_symbol_t symbol);
98
99 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_get_current_state(xbt_automaton_t a);
100 XBT_PUBLIC int xbt_automaton_state_compare(xbt_automaton_state_t s1, xbt_automaton_state_t s2);
101 XBT_PUBLIC int xbt_automaton_propositional_symbols_compare_value(xbt_dynar_t s1, xbt_dynar_t s2);
102 XBT_PUBLIC int xbt_automaton_transition_compare(const void* t1, const void* t2);
103 XBT_PUBLIC int xbt_automaton_exp_label_compare(xbt_automaton_exp_label_t l1, xbt_automaton_exp_label_t l2);
104 XBT_PUBLIC void xbt_automaton_state_free_voidp(void* s);
105 XBT_PUBLIC void xbt_automaton_state_free(xbt_automaton_state_t s);
106 XBT_PUBLIC void xbt_automaton_transition_free_voidp(void* t);
107 XBT_PUBLIC void xbt_automaton_exp_label_free_voidp(void* e);
108 XBT_PUBLIC void xbt_automaton_propositional_symbol_free_voidp(void* ps);
109 XBT_PUBLIC void xbt_automaton_free(xbt_automaton_t a);
110
111 SG_END_DECL()
112
113 #endif