{% macro decl_units(meta) %} {%- for u in meta.getunits ~%} {%- if u.object is instanceof('\\mtgMetaStruct') -%} {{ _self.decl_struct(u.object) }} {%- elseif u.object is instanceof('\\mtgMetaEnum') -%} {{ _self.decl_enum(u.object) }} {%- endif ~%} {%- endfor ~%} {% endmacro %} {% macro decl_struct(o, extra = '') %} {%- if o.parent and has_token(o, 'bitfields') -%} {{Error("@bitfields structs can't have a parent: " ~ o.name)}} {%- endif -%} {{_self.attributes(o)}} public {{_self.struct_type(o)}} {{o.name}} {{_self.base_class(o)}} { {{_self.decl_struct_fields(o)}} public {{o.parent ? 'new'}} const uint STATIC_CLASS_ID = {{o.classid}}; public {{_self.override(o)}} uint CLASS_ID() { return {{o.classid}}; } {{_self.comment_POD_begin(o)}} public {{o.name}}() { reset(); } {{_self.comment_POD_end(o)}} public {{_self.override(o)}} void reset() { {{_self.struct_fields_reset(o)}} } {{_self.comment_non_cloneable_begin(o)}} public {{_self.virtual_clone(o)}} void copy(IMetaStruct other) { copyFrom(({{o.name}})other); } public void copyFrom({{o.name}} other) { var ctx = Meta.PrepareForClone(ref other); ctx.factory = AutogenBundle.createById; ctx.reader.BeginContainer(); reset(); syncFields(ctx); ctx.reader.EndContainer(); {{_self.copy_fields(o)}} } public {{_self.virtual_clone(o)}} IMetaStruct clone() { var copy = new {{o.name}}(); copy.copy(this); return copy; } {{_self.comment_non_cloneable_end(o)}} public {{_self.override(o)}} void syncFields(MetaSyncContext ctx) { %bitfields_sync_context% %sync_buffer% } public {{_self.override(o)}} int getFieldsCount() { return %fields_count%; } public {{_self.override(o)}} int getWritableFieldsCount() { return %dirty_fields_count%; } {{extra}} } {% endmacro %} {%- macro decl_struct_fields(o) -%} {%- if has_token(o, 'bitfields') ~%} public long fields_mask; {%- endif -%} {%- for f in o.fields ~%} {{_self.decl_struct_field(o, f)}} {%- endfor -%} {%- endmacro -%} {%- macro decl_struct_field(o, f) -%} {{_self.attributes(f)}} public {{f.type|cs_type}} {{f.name}} {% if not has_token(f, 'POD') -%} {{_self.decl_init_value(f.type)}} {%- endif -%}; {%- endmacro -%} {% macro decl_init_value(type) %} {%- if type is instanceof('\\mtgBuiltinType') -%} {%- if type.isstring -%} = ""{%- endif -%} {%- else -%} = new {{type|cs_type}}() {%- endif -%} {% endmacro %} {% macro struct_fields_reset(o) %} {%- if o.parent ~%} base.reset(); {%- endif -%} {%- for f in o.fields ~%} {{var_reset(f.name, f.type, token_or(f, 'default', null))}} {%- endfor -%} {%- if has_token(o, 'bitfields') ~%} fields_mask = 0L; {%- endif -%} {% endmacro %} {%- macro attributes(o) %} {%- if has_token(o, 'cs_attributes') -%} {%- for attr in token(o, 'cs_attributes')|split(',') -%} [{{attr}}] {%- endfor -%} {%- endif -%} {%- endmacro %} {%- macro struct_type(o) -%} {{has_token(o, 'POD') ? 'struct' : 'class'}} {%- endmacro -%} {%- macro base_class(o) -%} {%- if not has_token(o, 'POD') -%} : {{o.parent ? o.parent.name : 'BaseMetaStruct'}} {{has_token(o, 'cloneable')?',IMetaCloneable'}} {%- endif -%} {%- endmacro -%} {%- macro override(o) -%} {%- if not has_token(o, 'POD') -%} override {%- endif -%} {%- endmacro -%} {%- macro comment_POD_begin(o) -%} {%- if has_token(o, 'POD') -%} /* {%- endif -%} {%- endmacro -%} {%- macro comment_POD_end(o) -%} {%- if has_token(o, 'POD') -%} */ {%- endif -%} {%- endmacro -%} {%- macro comment_non_cloneable_begin(o) -%} {%- if not has_token(o, 'cloneable') -%} /* {%- endif -%} {%- endmacro -%} {%- macro comment_non_cloneable_end(o) -%} {%- if not has_token(o, 'cloneable') -%} */ {%- endif -%} {%- endmacro -%} {%- macro virtual_clone(o) -%} {%- if not has_token(o, 'POD') -%} {%- if o.parent and has_token_in_parent(o.parent, 'cloneable') -%} override {%- else -%} virtual {%- endif -%} {%- endif -%} {%- endmacro -%} {%- macro copy_fields(o) -%} {%- if has_token(o, 'POD') ~%} fields_mask = other.fields_mask; {%- endif -%} {%- endmacro -%} {% macro decl_enum(o) %} {% endmacro %}