Skip to content

Commit

Permalink
add missing max_size implementation, add collection methods and ali…
Browse files Browse the repository at this point in the history
…ases to `UserDataCollection`
  • Loading branch information
m-fila committed May 7, 2024
1 parent 315ab01 commit 670ea5c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/podio/CollectionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class CollectionBase {
/// number of elements in the collection
virtual size_t size() const = 0;

/// maximal number of elements in the collection
virtual std::size_t max_size() const = 0;

/// Is the collection empty
virtual bool empty() const = 0;

Expand Down
17 changes: 17 additions & 0 deletions include/podio/UserDataCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class UserDataCollection : public CollectionBase {
VectorMembersInfo m_vecmem_info{};

public:
using value_type = typename decltype(_vec)::value_type;
using const_iterator = typename decltype(_vec)::const_iterator;
using iterator = typename decltype(_vec)::iterator;
using difference_type = typename decltype(_vec)::difference_type;
using size_type = typename decltype(_vec)::size_type;

UserDataCollection() = default;
/// Constructor from an existing vector (which will be moved from!)
UserDataCollection(std::vector<BasicType>&& vec) : _vec(std::move(vec)) {
Expand Down Expand Up @@ -133,6 +139,11 @@ class UserDataCollection : public CollectionBase {
return _vec.size();
}

/// maximal number of elements in the collection
size_t max_size() const override {
return _vec.max_size();
}

/// Is the collection empty
bool empty() const override {
return _vec.empty();
Expand Down Expand Up @@ -206,6 +217,12 @@ class UserDataCollection : public CollectionBase {
typename std::vector<BasicType>::const_iterator end() const {
return _vec.end();
}
typename std::vector<BasicType>::const_iterator cbegin() const {
return _vec.cbegin();
}
typename std::vector<BasicType>::const_iterator cend() const {
return _vec.cend();
}

typename std::vector<BasicType>::reference operator[](size_t idx) {
return _vec[idx];
Expand Down
4 changes: 4 additions & 0 deletions python/templates/Collection.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ std::size_t {{ collection_type }}::size() const {
return m_storage.entries.size();
}

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

bool {{ collection_type }}::empty() const {
return m_storage.entries.empty();
}
Expand Down
2 changes: 1 addition & 1 deletion python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public:
std::size_t size() const final;

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

/// Is the collection empty
bool empty() const final;
Expand Down

0 comments on commit 670ea5c

Please sign in to comment.