Selaa lähdekoodia

Fixes class generation to only load used branches

Caleb 6 vuotta sitten
vanhempi
commit
a83921cf4b
1 muutettua tiedostoa jossa 13 lisäystä ja 7 poistoa
  1. 13 7
      tools/generate_class.py

+ 13 - 7
tools/generate_class.py

@@ -16,6 +16,7 @@ class {obj_name}Collection {{
         iter operator++() {{ ++idx; return *this; }}
         bool operator!=(const iter & other) {{ return idx != other.idx; }}
         const {obj_name} operator*() const;
+        TrackingDataSet* tds;
       private:
         const {obj_name}Collection* collection;
         size_t idx;
@@ -27,15 +28,12 @@ class {obj_name}Collection {{
         name = field['name']
         type_ = field['type']
         src.append(f'    Value<vector<{type_}>>* val_{name};')
+        src.append(f'    bool {name}_loaded;')
 
     src.append(f'\n    {obj_name}Collection() {{ }}\n')
 
-    src.append('    void init(TrackingDataSet& tds){')
-    for field in obj_attrs['fields']:
-        name = field['name']
-        type_ = field['type']
-        prefix = obj_attrs['treename_prefix']+'_'
-        src.append(f'        val_{name} = tds.track_branch_obj<vector<{type_}>>("{prefix}{name}");')
+    src.append('    void init(TrackingDataSet* tds){')
+    src.append('        this->tds = tds;')
     src.append('    }\n')
     first_obj_name = list(obj_attrs['fields'])[0]['name']
     src.append(f'    size_t size() const {{ return (*val_{first_obj_name})().size();}}\n')
@@ -55,7 +53,15 @@ struct {obj_name} {{
     for field in obj_attrs['fields']:
         name = field['name']
         type_ = field['type']
-        src.append(f'    const {type_}& {name}() const {{return (*collection->val_{name})().at(idx);}}')
+        prefix = obj_attrs['treename_prefix']+'_'
+        src.append(f'''\
+    const {type_}& {name}() const {{
+        if (!collection->{name}_loaded) {{
+            collection->val_{name} = collection->tds->track_branch_obj<vector<{type_}>>("{prefix}{name}");
+            collection->{name}_loaded = true;
+        }}
+        return (*collection->val_{name})().at(idx);}}
+''')
     src.append('};')
 
     src.append(f'''