浏览代码

Merge branch 'master' of git.fangmeier.tech:caleb/filval

Caleb 6 年之前
父节点
当前提交
f1f245f8d9
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      tools/generate_class.py

+ 7 - 1
tools/generate_class.py

@@ -63,8 +63,10 @@ struct {obj_name} {{
     for field in obj_attrs['fields']:
         name = field['name']
         type_ = field['type']
+        # Because vector<bool> is packed, a temporary object is created so we can't return a reference.
+        ret_type = f'{type_}&' if type_ != 'bool' else type_
         src.append(f'''\
-    const {type_}& {name}() const {{
+    const {ret_type} {name}() const {{
         if (!collection->{name}_loaded) {{
             collection->val_{name} = collection->tds->track_branch_obj<vector<{type_}>>("{prefix}_{name}");
             collection->{name}_loaded = true;
@@ -75,6 +77,10 @@ struct {obj_name} {{
     src.append('};')
 
     src.append(f'''
+bool operator==(const {obj_name}& obj1, const {obj_name}& obj2) {{
+    return obj1.idx == obj2.idx;
+}}
+
 {obj_name} {obj_name}Collection::iter::operator*() {{
     return {{collection, idx}};
 }}