Skip to content

Commit

Permalink
Move function implementations into .cc files for Components
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 11, 2023
1 parent 2a293fb commit aa8d4b7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
1 change: 0 additions & 1 deletion python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def get_fn_format(tmpl):

endings = {
'Data': ('h',),
'Component': ('h',),
'PrintInfo': ('h',)
}.get(template_base, ('h', 'cc'))

Expand Down
1 change: 1 addition & 0 deletions python/templates/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(PODIO_TEMPLATES
${CMAKE_CURRENT_LIST_DIR}/CollectionData.cc.jinja2
${CMAKE_CURRENT_LIST_DIR}/CollectionData.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Component.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Component.cc.jinja2
${CMAKE_CURRENT_LIST_DIR}/Data.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Obj.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Obj.cc.jinja2
Expand Down
39 changes: 39 additions & 0 deletions python/templates/Component.cc.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% import "macros/utils.jinja2" as utils %}
// AUTOMATICALLY GENERATED FILE - DO NOT EDIT

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

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#endif

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

std::ostream& operator<<(std::ostream& o, const {{class.full_type}}& value) {
{% for member in Members %}
{% if member.is_array %}
for (int i = 0; i < {{ member.array_size }}; ++i) {
o << value.{{ member.name }}[i] << "|";
}
o << " ";
{% else %}
o << value.{{ member.name }} << " ";
{% endif %}
{% endfor %}

return o;
}

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
void to_json(nlohmann::json& j, const {{ class.bare_type }}& value) {
j = nlohmann::json{
{% set comma = joiner(",") %}
{% for member in Members %}
{{ comma() }}{"{{ member.name }}", value.{{ member.name }}}
{% endfor %}
};
}
#endif

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

26 changes: 3 additions & 23 deletions python/templates/Component.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <ostream>

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#include "nlohmann/json_fwd.hpp"
#endif

{{ utils.namespace_open(class.namespace) }}
Expand All @@ -25,30 +25,10 @@ public:
{{ utils.if_present(ExtraCode, "declaration") }}
};

inline std::ostream& operator<<(std::ostream& o, const {{class.full_type}}& value) {
{% for member in Members %}
{% if member.is_array %}
for (int i = 0; i < {{ member.array_size }}; ++i) {
o << value.{{ member.name }}[i] << "|";
}
o << " ";
{% else %}
o << value.{{ member.name }} << " ";
{% endif %}
{% endfor %}

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

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
inline void to_json(nlohmann::json& j, const {{ class.bare_type }}& value) {
j = nlohmann::json{
{% set comma = joiner(",") %}
{% for member in Members %}
{{ comma() }}{"{{ member.name }}", value.{{ member.name }}}
{% endfor %}
};
}
void to_json(nlohmann::json& j, const {{ class.bare_type }}& value);
#endif

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

0 comments on commit aa8d4b7

Please sign in to comment.