Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use type std::size_t for index in Collection element accessors and size() #408

Merged
merged 7 commits into from
Apr 22, 2023
8 changes: 4 additions & 4 deletions python/templates/Collection.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
m_storage.clear(m_isSubsetColl);
}

{{ class.bare_type }} {{ collection_type }}::operator[](unsigned int index) const {
{{ class.bare_type }} {{ collection_type }}::operator[](size_t index) const {
return {{ class.bare_type }}(m_storage.entries[index]);
}

{{ class.bare_type }} {{ collection_type }}::at(unsigned int index) const {
{{ class.bare_type }} {{ collection_type }}::at(size_t index) const {
return {{ class.bare_type }}(m_storage.entries.at(index));
}

Mutable{{ class.bare_type }} {{ collection_type }}::operator[](unsigned int index) {
Mutable{{ class.bare_type }} {{ collection_type }}::operator[](size_t index) {
return Mutable{{ class.bare_type }}(m_storage.entries[index]);
}

Mutable{{ class.bare_type }} {{ collection_type }}::at(unsigned int index) {
Mutable{{ class.bare_type }} {{ collection_type }}::at(size_t index) {
return Mutable{{ class.bare_type }}(m_storage.entries.at(index));
}

Expand Down
8 changes: 4 additions & 4 deletions python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public:
void setSubsetCollection(bool setSubset=true) final;

/// Returns the const object of given index
{{ class.bare_type }} operator[](unsigned int index) const;
{{ class.bare_type }} operator[](size_t index) const;
/// Returns the object of a given index
Mutable{{ class.bare_type }} operator[](unsigned int index);
Mutable{{ class.bare_type }} operator[](size_t index);
/// Returns the const object of given index
{{ class.bare_type }} at(unsigned int index) const;
{{ class.bare_type }} at(size_t index) const;
/// Returns the object of given index
Mutable{{ class.bare_type }} at(unsigned int index);
Mutable{{ class.bare_type }} at(size_t index);


/// Append object to the collection
Expand Down
4 changes: 2 additions & 2 deletions python/templates/Data.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public:
{% endfor %}

{% for member in VectorMembers + OneToManyRelations %}
unsigned int {{ member.name }}_begin{};
unsigned int {{ member.name }}_end{};
size_t {{ member.name }}_begin{};
c-dilks marked this conversation as resolved.
Show resolved Hide resolved
size_t {{ member.name }}_end{};
{% endfor %}
};

Expand Down
4 changes: 2 additions & 2 deletions python/templates/macros/declarations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
{% if with_adder %}
void {{ relation.setter_name(get_syntax, is_relation=True) }}({{ relation.full_type }});
{% endif %}
unsigned int {{ relation.name }}_size() const;
{{ relation.full_type }} {{ relation.getter_name(get_syntax) }}(unsigned int) const;
size_t {{ relation.name }}_size() const;
{{ relation.full_type }} {{ relation.getter_name(get_syntax) }}(size_t) const;
std::vector<{{ relation.full_type }}>::const_iterator {{ relation.name }}_begin() const;
std::vector<{{ relation.full_type }}>::const_iterator {{ relation.name }}_end() const;
podio::RelationRange<{{ relation.full_type }}> {{ relation.getter_name(get_syntax) }}() const;
Expand Down
4 changes: 2 additions & 2 deletions python/templates/macros/implementations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ std::vector<{{ relation.full_type }}>::const_iterator {{ class_type }}::{{ relat
return ret_value;
}

unsigned int {{ class_type }}::{{ relation.name }}_size() const {
size_t {{ class_type }}::{{ relation.name }}_size() const {
return m_obj->data.{{ relation.name }}_end - m_obj->data.{{ relation.name }}_begin;
}

{{ relation.full_type }} {{ class_type }}::{{ relation.getter_name(get_syntax) }}(unsigned int index) const {
{{ relation.full_type }} {{ class_type }}::{{ relation.getter_name(get_syntax) }}(size_t index) const {
if ({{ relation.name }}_size() > index) {
return m_obj->m_{{ relation.name }}->at(m_obj->data.{{ relation.name }}_begin + index);
}
Expand Down