MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / autogen_cpp_struct

Function autogen_cpp_struct

crates/codegen/src/unrealcpp.rs:6053–6203  ·  view source on GitHub ↗
(
    module_prefix: &str,
    module: &ModuleDef,
    name: &str, // Changed to &str
    product_type: &ProductTypeDef,
    api_macro: &str,
    module_name: &str,
)

Source from the content-addressed store, hash-verified

6051}
6052
6053fn autogen_cpp_struct(
6054 module_prefix: &str,
6055 module: &ModuleDef,
6056 name: &str, // Changed to &str
6057 product_type: &ProductTypeDef,
6058 api_macro: &str,
6059 module_name: &str,
6060) -> String {
6061 let mut headers = HashSet::<String>::new();
6062
6063 for (_, field_ty) in product_type {
6064 collect_includes_for_type(module_prefix, module, field_ty, &mut headers, module_name);
6065 }
6066
6067 // Convert to `Vec<&str>` so UnrealCppAutogen::new works
6068 let mut slices: Vec<&str> = headers.iter().map(|s| s.as_str()).collect();
6069 slices.sort(); // make output deterministic
6070
6071 // --------- start writing file ---------
6072 let type_name = format!("{name}Type");
6073 let mut output = UnrealCppAutogen::new(&slices, &type_name, false);
6074
6075 writeln!(output, "USTRUCT(BlueprintType)");
6076 writeln!(output, "struct {api_macro} F{name}Type");
6077 writeln!(output, "{{");
6078 output.indent(1);
6079 writeln!(output, "GENERATED_BODY()");
6080 writeln!(output);
6081
6082 for (orig_name, ty) in product_type.into_iter() {
6083 let field_name = orig_name.deref().to_case(Case::Pascal);
6084 let ty_str = cpp_ty_fmt_with_module(module_prefix, module, ty, module_name).to_string();
6085 let init_str = cpp_ty_init_fmt_impl(module_prefix, module, ty);
6086 let field_decl = format!("{ty_str} {field_name}{init_str}");
6087
6088 // Check if the type is blueprintable
6089 if is_blueprintable(module, ty) {
6090 writeln!(
6091 output,
6092 "UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"SpacetimeDB\")"
6093 );
6094 } else {
6095 // Add comment explaining why the field isn't exposed as UPROPERTY
6096 writeln!(
6097 output,
6098 "// NOTE: {ty_str} field not exposed to Blueprint due to non-blueprintable elements"
6099 );
6100 }
6101 writeln!(output, "{field_decl};");
6102 writeln!(output);
6103 }
6104
6105 // Generate operator== and operator!=
6106 writeln!(output, "FORCEINLINE bool operator==(const F{name}Type& Other) const");
6107 writeln!(output, "{{");
6108 output.indent(1);
6109
6110 // Generate comparison for each field

Callers 1

generate_type_filesMethod · 0.85

Calls 15

cpp_ty_fmt_with_moduleFunction · 0.85
cpp_ty_init_fmt_implFunction · 0.85
is_blueprintableFunction · 0.85
to_caseMethod · 0.80
skipMethod · 0.80
iterMethod · 0.65
newFunction · 0.50
collectMethod · 0.45
mapMethod · 0.45
as_strMethod · 0.45
indentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…