Skip to content

Commit

Permalink
Make filenames the same as class names
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 3, 2021
1 parent b485a23 commit 6b34968
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
21 changes: 11 additions & 10 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,16 @@ def _get_filenames_templates(template_base, name):
# depending on which category is passed different naming conventions apply
# for the generated files. Additionally not all categories need source files.
# Listing the special cases here
fn_base = {
'Data': 'Data',
'Obj': 'Obj',
'MutableObject': 'Mutable',
'PrintInfo': 'PrintInfo',
'Object': '',
'Component': '',
'SIOBlock': 'SIOBlock',
}.get(template_base, template_base)
def get_fn_format(tmpl):
"""Get a format string for the filename"""
prefix = {'MutableObject': 'Mutable'}
postfix = {'Data': 'Data',
'Obj': 'Obj',
'SIOBlock': 'SIOBlock',
'Collection': 'Collection',
'CollectionData': 'CollectionData'}

return f'{prefix.get(tmpl, "")}{{name}}{postfix.get(tmpl, "")}.{{end}}'

endings = {
'Data': ('h',),
Expand All @@ -179,7 +180,7 @@ def _get_filenames_templates(template_base, name):
fn_templates = []
for ending in endings:
template_name = '{fn}.{end}.jinja2'.format(fn=template_base, end=ending)
filename = '{name}{fn}.{end}'.format(fn=fn_base, name=name, end=ending)
filename = get_fn_format(template_base).format(name=name, end=ending)
fn_templates.append((filename, template_name))

return fn_templates
Expand Down
1 change: 1 addition & 0 deletions python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// datamodel specific includes
#include "{{ incfolder }}{{ class.bare_type }}Data.h"
#include "{{ incfolder }}{{ class.bare_type }}.h"
#include "{{ incfolder }}Mutable{{ class.bare_type }}.h"
#include "{{ incfolder }}{{ class.bare_type }}Obj.h"
#include "{{ incfolder }}{{ class.bare_type }}CollectionData.h"

Expand Down
4 changes: 2 additions & 2 deletions python/templates/MutableObject.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define {{ package_name.upper() }}_Mutable{{ class.bare_type }}_H

#include "{{ incfolder }}{{ class.bare_type }}Obj.h"
// Make the immutable class available from its mutable version but not vice versa
#include "{{ incfolder }}{{ class.bare_type }}.h"

{% for include in includes %}
{{ include }}
Expand Down Expand Up @@ -45,8 +47,6 @@ private:
{{ class.bare_type }}Obj* m_obj;
};

std::ostream& operator<<(std::ostream& o, const {{ class.bare_type }}& value);

{{ utils.namespace_close(class.namespace) }}

#endif
2 changes: 1 addition & 1 deletion python/templates/Object.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define {{ package_name.upper() }}_{{ class.bare_type }}_H

#include "{{ incfolder }}{{ class.bare_type }}Obj.h"
#include "{{ incfolder }}{{ class.bare_type }}Mutable.h"

{% for include in includes %}
{{ include }}
Expand All @@ -17,6 +16,7 @@
{{ utils.forward_decls(forward_declarations) }}

{{ utils.namespace_open(class.namespace) }}
class Mutable{{ class.bare_type }};

{{ macros.class_description(class.bare_type, Description, Author) }}
class {{ class.bare_type }} {
Expand Down
2 changes: 1 addition & 1 deletion python/templates/macros/utils.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace {{ nsp }} {
{% macro datamodel_includes(incfolder, type) %}
// datamodel specific includes
#include "{{ incfolder }}{{ type }}.h"
#include "{{ incfolder }}{{ type }}Mutable.h"
#include "{{ incfolder }}Mutable{{ type }}.h"
#include "{{ incfolder }}{{ type }}Obj.h"
#include "{{ incfolder }}{{ type }}Data.h"
#include "{{ incfolder }}{{ type }}Collection.h"
Expand Down
8 changes: 4 additions & 4 deletions tests/ostream_operator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "datamodel/ExampleMC.h"
#include "datamodel/ExampleForCyclicDependency1.h"
#include "datamodel/ExampleForCyclicDependency2.h"
#include "datamodel/ExampleReferencingType.h"
#include "datamodel/MutableExampleMC.h"
#include "datamodel/MutableExampleForCyclicDependency1.h"
#include "datamodel/MutableExampleForCyclicDependency2.h"
#include "datamodel/MutableExampleReferencingType.h"

#include <iostream>

Expand Down
4 changes: 2 additions & 2 deletions tests/relation_range.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "datamodel/ExampleMCCollection.h"
#include "datamodel/ExampleReferencingType.h"
#include "datamodel/ExampleWithVectorMember.h"
#include "datamodel/MutableExampleReferencingType.h"
#include "datamodel/MutableExampleWithVectorMember.h"

#include "podio/EventStore.h"
#include "podio/ROOTWriter.h"
Expand Down
3 changes: 1 addition & 2 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "datamodel/ExampleForCyclicDependency1Collection.h"
#include "datamodel/ExampleForCyclicDependency2Collection.h"
#include "datamodel/ExampleHitCollection.h"
#include "datamodel/ExampleWithComponent.h"
#include "datamodel/ExampleWithOneRelation.h"
#include "datamodel/MutableExampleWithComponent.h"
#include "datamodel/ExampleWithOneRelationCollection.h"

TEST_CASE("AutoDelete") {
Expand Down

0 comments on commit 6b34968

Please sign in to comment.