MCPcopy Create free account
hub / github.com/davidmoreno/rtpmidid / generate_cpp_header

Function generate_cpp_header

scripts/statemachine_to_cpp.py:104–129  ·  view source on GitHub ↗
(stm)

Source from the content-addressed store, hash-verified

102
103
104def 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
132def generate_cpp_source(stm):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected