1 /* Copyright (c) 2011-2020. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef XBT_AUTOMATON_H
7 #define XBT_AUTOMATON_H
13 typedef struct xbt_automaton_state {
15 int type; /* -1 = init, 0 = inter, 1 = final */
18 } s_xbt_automaton_state;
20 typedef struct xbt_automaton_state* xbt_automaton_state_t;
21 typedef const struct xbt_automaton_state* const_xbt_automaton_state_t;
23 typedef struct xbt_automaton {
24 xbt_dynar_t propositional_symbols;
25 xbt_dynar_t transitions;
27 xbt_automaton_state_t current_state;
30 typedef struct xbt_automaton* xbt_automaton_t;
31 typedef const struct xbt_automaton* const_xbt_automaton_t;
33 typedef struct xbt_automaton_exp_label{
34 enum{AUT_OR=0, AUT_AND=1, AUT_NOT=2, AUT_PREDICAT=3, AUT_ONE=4} type;
37 struct xbt_automaton_exp_label* left_exp;
38 struct xbt_automaton_exp_label* right_exp;
40 struct xbt_automaton_exp_label* exp_not;
43 } s_xbt_automaton_exp_label;
45 typedef struct xbt_automaton_exp_label* xbt_automaton_exp_label_t;
46 typedef const struct xbt_automaton_exp_label* const_xbt_automaton_exp_label_t;
48 typedef struct xbt_automaton_transition {
49 xbt_automaton_state_t src;
50 xbt_automaton_state_t dst;
51 xbt_automaton_exp_label_t label;
52 } s_xbt_automaton_transition;
54 typedef struct xbt_automaton_transition* xbt_automaton_transition_t;
55 typedef const struct xbt_automaton_transition* const_xbt_automaton_transition_t;
57 typedef struct xbt_automaton_propositional_symbol* xbt_automaton_propositional_symbol_t;
58 typedef const struct xbt_automaton_propositional_symbol* const_xbt_automaton_propositional_symbol_t;
60 typedef int (*xbt_automaton_propositional_symbol_callback_type)(void*);
61 typedef void (*xbt_automaton_propositional_symbol_free_function_type)(void*);
63 XBT_PUBLIC xbt_automaton_t xbt_automaton_new(void);
64 XBT_PUBLIC void xbt_automaton_load(xbt_automaton_t automaton, const char* file);
65 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_state_new(const_xbt_automaton_t a, int type, const char* id);
66 XBT_PUBLIC xbt_automaton_transition_t xbt_automaton_transition_new(const_xbt_automaton_t a, xbt_automaton_state_t src,
67 xbt_automaton_state_t dst,
68 xbt_automaton_exp_label_t label);
69 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_or(xbt_automaton_exp_label_t left,
70 xbt_automaton_exp_label_t right);
71 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_and(xbt_automaton_exp_label_t left,
72 xbt_automaton_exp_label_t right);
73 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_not(xbt_automaton_exp_label_t exp_not);
74 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_predicat(const char* p);
75 XBT_PUBLIC xbt_automaton_exp_label_t xbt_automaton_exp_label_new_one(void);
76 XBT_PUBLIC xbt_dynar_t xbt_automaton_get_states(const_xbt_automaton_t a);
77 XBT_PUBLIC xbt_dynar_t xbt_automaton_get_transitions(const_xbt_automaton_t a);
78 XBT_PUBLIC xbt_automaton_transition_t xbt_automaton_get_transition(const_xbt_automaton_t a,
79 const_xbt_automaton_state_t src,
80 const_xbt_automaton_state_t dst);
81 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_transition_get_source(const_xbt_automaton_transition_t t);
82 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_transition_get_destination(const_xbt_automaton_transition_t t);
83 XBT_PUBLIC void xbt_automaton_transition_set_source(xbt_automaton_transition_t t, xbt_automaton_state_t src);
84 XBT_PUBLIC void xbt_automaton_transition_set_destination(xbt_automaton_transition_t t, xbt_automaton_state_t dst);
85 XBT_PUBLIC xbt_dynar_t xbt_automaton_state_get_out_transitions(const_xbt_automaton_state_t s);
86 XBT_PUBLIC xbt_dynar_t xbt_automaton_state_get_in_transitions(const_xbt_automaton_state_t s);
87 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_state_exists(const_xbt_automaton_t a, const char* id);
88 XBT_PUBLIC void xbt_automaton_display(const_xbt_automaton_t a);
89 XBT_PUBLIC void xbt_automaton_exp_label_display(const_xbt_automaton_exp_label_t l);
91 // xbt_automaton_propositional_symbol constructors:
92 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new(const_xbt_automaton_t a,
95 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new_pointer(const_xbt_automaton_t a,
98 XBT_PUBLIC xbt_automaton_propositional_symbol_t xbt_automaton_propositional_symbol_new_callback(
99 const_xbt_automaton_t a, const char* id, xbt_automaton_propositional_symbol_callback_type callback, void* data,
100 xbt_automaton_propositional_symbol_free_function_type free_function);
102 // xbt_automaton_propositional_symbol accessors:
103 XBT_PUBLIC xbt_automaton_propositional_symbol_callback_type
104 xbt_automaton_propositional_symbol_get_callback(const_xbt_automaton_propositional_symbol_t symbol);
105 XBT_PUBLIC void* xbt_automaton_propositional_symbol_get_data(const_xbt_automaton_propositional_symbol_t symbol);
106 XBT_PUBLIC const char* xbt_automaton_propositional_symbol_get_name(const_xbt_automaton_propositional_symbol_t symbol);
108 // xbt_automaton_propositional_symbol methods!
109 XBT_PUBLIC int xbt_automaton_propositional_symbol_evaluate(const_xbt_automaton_propositional_symbol_t symbol);
111 XBT_PUBLIC xbt_automaton_state_t xbt_automaton_get_current_state(const_xbt_automaton_t a);
112 XBT_PUBLIC int xbt_automaton_state_compare(const_xbt_automaton_state_t s1, const_xbt_automaton_state_t s2);
113 XBT_PUBLIC int xbt_automaton_propositional_symbols_compare_value(const_xbt_dynar_t s1, const_xbt_dynar_t s2);
114 XBT_PUBLIC int xbt_automaton_transition_compare(const_xbt_automaton_transition_t t1,
115 const_xbt_automaton_transition_t t2);
116 XBT_PUBLIC int xbt_automaton_exp_label_compare(const_xbt_automaton_exp_label_t l1, const_xbt_automaton_exp_label_t l2);
117 XBT_PUBLIC void xbt_automaton_state_free_voidp(void* s);
118 XBT_PUBLIC void xbt_automaton_state_free(xbt_automaton_state_t s);
119 XBT_PUBLIC void xbt_automaton_transition_free_voidp(void* t);
120 XBT_PUBLIC void xbt_automaton_exp_label_free_voidp(void* e);
121 XBT_PUBLIC void xbt_automaton_propositional_symbol_free_voidp(void* ps);
122 XBT_PUBLIC void xbt_automaton_free(xbt_automaton_t a);