| 102 | |
| 103 | |
| 104 | def generate_cpp_header(stm): |
| 105 | code = "// This is an autogenerated file. It should be included at header\n" |
| 106 | code += "public:\n" |
| 107 | code += "/// for the header / class\n\n" |
| 108 | code += "enum state_e{\n" |
| 109 | for state in stm.states: |
| 110 | code += f" {state},\n" |
| 111 | code += "};\n\n" |
| 112 | code += "static const char *to_string(state_e state);\n\n" |
| 113 | |
| 114 | code += "enum event_e{\n" |
| 115 | for event in stm.events: |
| 116 | code += f" {event},\n" |
| 117 | code += "};\n\n" |
| 118 | code += "static const char *to_string(event_e event);\n\n" |
| 119 | |
| 120 | code += "state_e state = state_e::" + list(stm.states)[1] + ";\n\n" |
| 121 | code += "void handle_event(event_e event);\n\n" |
| 122 | |
| 123 | code += "protected:\n" |
| 124 | # A function for each state |
| 125 | for state in stm.states: |
| 126 | snake_name = re.sub(r"([a-z])([A-Z])", r"\1_\2", state).lower() |
| 127 | code += f"void state_{snake_name}();\n" |
| 128 | |
| 129 | return code |
| 130 | |
| 131 | |
| 132 | def generate_cpp_source(stm): |