|
@@ -11,16 +11,16 @@ class {obj_name}Collection {{
|
|
|
public:
|
|
|
class iter {{
|
|
|
public:
|
|
|
- iter(const {obj_name}Collection* collection, size_t idx)
|
|
|
+ iter({obj_name}Collection* collection, size_t idx)
|
|
|
:collection(collection), idx(idx) {{ }}
|
|
|
iter operator++() {{ ++idx; return *this; }}
|
|
|
bool operator!=(const iter & other) {{ return idx != other.idx; }}
|
|
|
- const {obj_name} operator*() const;
|
|
|
- TrackingDataSet* tds;
|
|
|
+ {obj_name} operator*();
|
|
|
private:
|
|
|
- const {obj_name}Collection* collection;
|
|
|
+ {obj_name}Collection* collection;
|
|
|
size_t idx;
|
|
|
}};
|
|
|
+ TrackingDataSet* tds;
|
|
|
|
|
|
'''.splitlines()
|
|
|
|
|
@@ -36,39 +36,49 @@ class {obj_name}Collection {{
|
|
|
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')
|
|
|
- src.append(f' const {obj_name} operator[](size_t) const;')
|
|
|
- src.append(' iter begin() const { return iter(this, 0); }')
|
|
|
- src.append(' iter end() const { return iter(this, size()); }')
|
|
|
+ first_obj_type = list(obj_attrs['fields'])[0]['type']
|
|
|
+ prefix = obj_attrs['treename_prefix']
|
|
|
+ src.append(f'''\
|
|
|
+ size_t size() {{
|
|
|
+ if (!this->{first_obj_name}_loaded) {{
|
|
|
+ this->val_{first_obj_name} = this->tds->track_branch_obj<vector<{first_obj_type}>>("{prefix}_{first_obj_name}");
|
|
|
+ this->{first_obj_name}_loaded = true;
|
|
|
+ }}
|
|
|
+ return (*this->val_{first_obj_name})().size();
|
|
|
+ }}
|
|
|
+\n''')
|
|
|
+ src.append(f' {obj_name} operator[](size_t);')
|
|
|
+ src.append(' iter begin() { return iter(this, 0); }')
|
|
|
+ src.append(' iter end() { return iter(this, size()); }')
|
|
|
src.append('};')
|
|
|
|
|
|
src += f'''
|
|
|
struct {obj_name} {{
|
|
|
- const {obj_name}Collection* collection;
|
|
|
- const size_t idx;
|
|
|
- {obj_name}(const {obj_name}Collection* collection, const size_t idx)
|
|
|
+ {obj_name}Collection* collection;
|
|
|
+ size_t idx;
|
|
|
+ {obj_name}({obj_name}Collection* collection, const size_t idx)
|
|
|
:collection(collection), idx(idx) {{ }}\n
|
|
|
'''.splitlines()
|
|
|
|
|
|
for field in obj_attrs['fields']:
|
|
|
name = field['name']
|
|
|
type_ = field['type']
|
|
|
- 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->val_{name} = collection->tds->track_branch_obj<vector<{type_}>>("{prefix}_{name}");
|
|
|
collection->{name}_loaded = true;
|
|
|
}}
|
|
|
- return (*collection->val_{name})().at(idx);}}
|
|
|
+ return (*collection->val_{name})().at(idx);
|
|
|
+ }}
|
|
|
''')
|
|
|
src.append('};')
|
|
|
|
|
|
src.append(f'''
|
|
|
-const {obj_name} {obj_name}Collection::iter::operator*() const {{
|
|
|
+{obj_name} {obj_name}Collection::iter::operator*() {{
|
|
|
return {{collection, idx}};
|
|
|
}}
|
|
|
-const {obj_name} {obj_name}Collection::operator[](size_t idx) const {{
|
|
|
+{obj_name} {obj_name}Collection::operator[](size_t idx) {{
|
|
|
return {{this, idx}};
|
|
|
}}
|
|
|
''')
|