Skip to content

Commit

Permalink
Pass an argument by const reference instead of value and other minor …
Browse files Browse the repository at this point in the history
…fixes (#633)

* Pass value by const reference in the relation setter

* Don't check for nullptr before delete

* Remove unnecessary include

* Remove unnecessary ostream

* Remove another check before delete

Co-authored-by: Mateusz Jakub Fila <[email protected]>

* Remove if - else

---------

Co-authored-by: jmcarcell <[email protected]>
Co-authored-by: Mateusz Jakub Fila <[email protected]>
  • Loading branch information
3 people authored Jun 24, 2024
1 parent d353b0e commit 1b6c811
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
2 changes: 0 additions & 2 deletions python/templates/MutableObject.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "nlohmann/json.hpp"
#endif

#include <ostream>

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

{{ macros.constructors_destructors(class.bare_type, Members, multi_relations=OneToManyRelations + VectorMembers, prefix='Mutable') }}
Expand Down
2 changes: 1 addition & 1 deletion python/templates/Obj.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{%- endwith %}

{% for relation in OneToOneRelations %}
if (m_{{ relation.name }}) delete m_{{ relation.name }};
delete m_{{ relation.name }};
{% endfor %}
}
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion python/templates/macros/declarations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
{% macro single_relation_setters(relations, get_syntax) %}
{% for relation in relations %}
/// Set the {{ relation.description }}
void {{ relation.setter_name(get_syntax) }}({{ relation.full_type }} value);
void {{ relation.setter_name(get_syntax) }}(const {{ relation.full_type }}& value);
{% endfor %}
{%- endmacro %}

Expand Down
11 changes: 3 additions & 8 deletions python/templates/macros/implementations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ const {{ relation.full_type }} {{ class_type }}::{{ relation.getter_name(get_syn
{% macro single_relation_setters(class, relations, get_syntax, prefix='') %}
{% set class_type = prefix + class.bare_type %}
{% for relation in relations %}
void {{ class_type }}::{{ relation.setter_name(get_syntax) }}({{ relation.full_type }} value) {
if (m_obj->m_{{ relation.name }}) {
delete m_obj->m_{{ relation.name }};
}
void {{ class_type }}::{{ relation.setter_name(get_syntax) }}(const {{ relation.full_type }}& value) {
delete m_obj->m_{{ relation.name }};
m_obj->m_{{ relation.name }} = new {{ relation.full_type }}(value);
}

Expand Down Expand Up @@ -182,10 +180,7 @@ podio::RelationRange<{{ relation.full_type }}> {{ class_type }}::{{ relation.get
{% macro common_object_funcs(class, prefix='') %}
{% set full_type = prefix + class.bare_type %}
bool {{ full_type }}::isAvailable() const {
if (m_obj) {
return true;
}
return false;
return m_obj;
}

const podio::ObjectID {{ full_type }}::getObjectID() const {
Expand Down
1 change: 0 additions & 1 deletion python/templates/macros/utils.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace {{ nsp }} {
#include "{{ incfolder }}Mutable{{ type }}.h"
#include "{{ incfolder }}{{ type }}Obj.h"
#include "{{ incfolder }}{{ type }}Data.h"
#include "{{ incfolder }}{{ type }}Collection.h"
{%- endmacro %}


Expand Down

0 comments on commit 1b6c811

Please sign in to comment.