Helper function to generate table .cpp implementation files
(
module_prefix: &str,
module: &ModuleDef,
table: &TableDef,
module_name: &str,
schema: &TableSchema,
)
| 1148 | |
| 1149 | // Helper function to generate table .cpp implementation files |
| 1150 | fn generate_table_cpp( |
| 1151 | module_prefix: &str, |
| 1152 | module: &ModuleDef, |
| 1153 | table: &TableDef, |
| 1154 | module_name: &str, |
| 1155 | schema: &TableSchema, |
| 1156 | ) -> String { |
| 1157 | let table_pascal = format!("{module_prefix}{}", table.name.deref().to_case(Case::Pascal)); |
| 1158 | let struct_name = type_ref_name(module_prefix, module, table.product_type_ref); |
| 1159 | let row_struct = format!("F{struct_name}Type"); |
| 1160 | |
| 1161 | // Include the table header and other necessary headers |
| 1162 | let table_header = format!("ModuleBindings/Tables/{table_pascal}Table.g.h"); |
| 1163 | let includes = vec![ |
| 1164 | table_header.as_str(), |
| 1165 | "DBCache/UniqueIndex.h", |
| 1166 | "DBCache/BTreeUniqueIndex.h", |
| 1167 | "DBCache/ClientCache.h", |
| 1168 | "DBCache/TableCache.h", |
| 1169 | ]; |
| 1170 | |
| 1171 | let mut output = UnrealCppAutogen::new_cpp(&includes); |
| 1172 | |
| 1173 | // Get unique indexes and non-unique BTree indexes |
| 1174 | let product_type = module.typespace_for_generate()[table.product_type_ref].as_product(); |
| 1175 | |
| 1176 | let mut unique_indexes = Vec::new(); |
| 1177 | let mut multi_key_indexes = Vec::new(); |
| 1178 | |
| 1179 | for idx in iter_indexes(table) { |
| 1180 | let Some(accessor_name) = idx.accessor_name.as_ref() else { |
| 1181 | continue; |
| 1182 | }; |
| 1183 | // Whatever the index algorithm on the host, |
| 1184 | // the client can still use btrees. |
| 1185 | let columns = idx.algorithm.columns(); |
| 1186 | if schema.is_unique(&columns) { |
| 1187 | if let Some(col) = columns.as_singleton() { |
| 1188 | let (f_name, f_ty) = &product_type.unwrap().elements[col.idx()]; |
| 1189 | let _field_name = f_name.deref().to_case(Case::Pascal); |
| 1190 | let field_type = cpp_ty_fmt_with_module(module_prefix, module, f_ty, module_name).to_string(); |
| 1191 | let index_name = accessor_name.deref().to_case(Case::Pascal); |
| 1192 | unique_indexes.push((index_name, field_type, f_name.deref().to_string())); |
| 1193 | } |
| 1194 | } else { |
| 1195 | // Non-unique BTree index |
| 1196 | let index_name = accessor_name.deref().to_case(Case::Pascal); |
| 1197 | let index_class_name = format!("U{table_pascal}{index_name}Index"); |
| 1198 | |
| 1199 | // Collect column information for AddMultiKeyBTreeIndex call |
| 1200 | let column_info: Vec<_> = columns |
| 1201 | .iter() |
| 1202 | .map(|col| { |
| 1203 | let (f_name, f_ty) = &product_type.unwrap().elements[col.idx()]; |
| 1204 | let field_name = f_name.deref().to_case(Case::Pascal); |
| 1205 | let field_type = cpp_ty_fmt_with_module(module_prefix, module, f_ty, module_name).to_string(); |
| 1206 | (field_name, field_type) |
| 1207 | }) |
no test coverage detected
searching dependent graphs…