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
10 changes: 5 additions & 5 deletions python/templates/Collection.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@
m_storage.clear(m_isSubsetColl);
}

{{ class.bare_type }} {{ collection_type }}::operator[](unsigned int index) const {
{{ class.bare_type }} {{ collection_type }}::operator[](std::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(std::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[](std::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(std::size_t index) {
return Mutable{{ class.bare_type }}(m_storage.entries.at(index));
}

size_t {{ collection_type }}::size() const {
std::size_t {{ collection_type }}::size() const {
return m_storage.entries.size();
}

Expand Down
11 changes: 6 additions & 5 deletions python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <ostream>
#include <mutex>
#include <memory>
#include <cstddef>

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

Expand Down Expand Up @@ -74,7 +75,7 @@ public:
Mutable{{ class.bare_type }} create(Args&&... args);

/// number of elements in the collection
size_t size() const final;
std::size_t size() const final;

/// fully qualified type name
std::string getTypeName() const final { return std::string("{{ (class | string ).strip(':')+"Collection" }}"); }
Expand All @@ -92,13 +93,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[](std::size_t index) const;
/// Returns the object of a given index
Mutable{{ class.bare_type }} operator[](unsigned int index);
Mutable{{ class.bare_type }} operator[](std::size_t index);
/// Returns the const object of given index
{{ class.bare_type }} at(unsigned int index) const;
{{ class.bare_type }} at(std::size_t index) const;
/// Returns the object of given index
Mutable{{ class.bare_type }} at(unsigned int index);
Mutable{{ class.bare_type }} at(std::size_t index);


/// Append object to the collection
Expand Down
1 change: 1 addition & 0 deletions python/templates/MutableObject.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{% endfor %}
#include "podio/ObjectID.h"
#include <ostream>
#include <cstddef>

#ifdef PODIO_JSON_OUTPUT
#include "nlohmann/json.hpp"
Expand Down
1 change: 1 addition & 0 deletions python/templates/Object.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{% endfor %}
#include "podio/ObjectID.h"
#include <ostream>
#include <cstddef>

#ifdef PODIO_JSON_OUTPUT
#include "nlohmann/json.hpp"
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;
std::size_t {{ relation.name }}_size() const;
{{ relation.full_type }} {{ relation.getter_name(get_syntax) }}(std::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 {
std::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) }}(std::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