MCPcopy Create free account
hub / github.com/IENT/YUView / writeItemToFiles

Function writeItemToFiles

tools/standardTextToCode/writeTablesC++.py:115–177  ·  view source on GitHub ↗
(item, files)

Source from the content-addressed store, hash-verified

113 files[1].spaces -= 2
114
115def writeItemToFiles(item, files):
116 header = files[0]
117 cpp = files[1]
118 if (type(item) == Variable):
119 typeString = "unsigned"
120 arguments = ""
121 if (item.coding.codingType == Coding.UNSIGNED_VARIABLE and item.coding.length == 0):
122 # Length for code should be known. Write the info and something that will not compile
123 header.write(f"int {item.name} {{}};\n")
124 cpp.write(f"""this->{item.name} = reader.readBits("{item.name}", unknown)\n""")
125 return
126 if (item.coding.codingType in [Coding.FIXED_CODE, Coding.UNSIGNED_VARIABLE, Coding.UNSIGNED_FIXED]):
127 if (item.coding.length == 1):
128 typeString = "bool"
129 parseFunction = "readFlag"
130 else:
131 parseFunction = "readBits"
132 arguments = f", {item.coding.length}"
133 elif (item.coding.codingType == Coding.UNSIGNED_EXP):
134 parseFunction = "readUEV"
135 elif (item.coding.codingType == Coding.SIGNED_EXP):
136 parseFunction = "readSEV"
137 typeString = "int"
138
139 name = item.name
140 if (item.arrayIndex != None):
141 for index in item.arrayIndex:
142 name += f"[{index}]"
143 typeString = f"std::vector<{typeString}>"
144 cpp.write(f"""this->{item.name}.push_back(reader.{parseFunction}("{item.name}"{arguments}));\n""")
145 else:
146 cpp.write(f"""this->{name} = reader.{parseFunction}("{item.name}"{arguments});\n""")
147 header.write(f"{typeString} {item.name} {{}};\n")
148
149 elif (type(item) == CommentEntry):
150 header.write(f"//{item.text}\n")
151 elif (type(item) == FunctionCall):
152 header.write(f"{item.functionName} {item.functionName}_instance;\n")
153 cpp.write(f"this->{item.functionName}_instance.parse(reader{argumentsToString(item.arguments)});\n")
154 elif (type(item) == ContainerIf):
155 cpp.write(f"if ({item.condition})\n")
156 cpp.write("{\n")
157 writeItemsInContainer(item, files)
158 cpp.write("}\n")
159 elif (type(item) == ContainerWhile):
160 cpp.write(f"while ({item.condition})\n")
161 cpp.write("{\n")
162 writeItemsInContainer(item, files)
163 cpp.write("}\n")
164 elif (type(item) == ContainerDo):
165 cpp.write("do\n")
166 cpp.write("{\n")
167 writeItemsInContainer(item, files)
168 cpp.write("} ")
169 cpp.write(f"while({item.condition})\n")
170 elif (type(item) == ContainerFor):
171 variableType = "unsigned"
172 if ("--" in item.increment):

Callers 1

writeItemsInContainerFunction · 0.85

Calls 3

argumentsToStringFunction · 0.85
writeItemsInContainerFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected