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

add mutable_type typedef to collection and user collection #718

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/podio/UserDataCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class UserDataCollection : public CollectionBase {

public:
using value_type = typename std::vector<BasicType>::value_type;
using mutable_type = value_type;
using const_iterator = typename std::vector<BasicType>::const_iterator;
using iterator = typename std::vector<BasicType>::iterator;
using difference_type = typename std::vector<BasicType>::difference_type;
Expand Down
1 change: 1 addition & 0 deletions python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ A Collection is identified by an ID.
class {{ class.bare_type }}Collection : public podio::CollectionBase {
public:
using value_type = {{ class.bare_type }};
using mutable_type = Mutable{{ class.bare_type }};
using const_iterator = {{ class.bare_type }}CollectionIterator;
using iterator = {{ class.bare_type }}MutableCollectionIterator;
using difference_type = ptrdiff_t;
Expand Down
15 changes: 7 additions & 8 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,23 +749,23 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {
// *r = o
// iterator
DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_v<iterator, CollectionType::value_type>);
STATIC_REQUIRE(traits::has_dereference_assignment_v<iterator, CollectionType::value_type::mutable_type>);
STATIC_REQUIRE(traits::has_dereference_assignment_v<iterator, CollectionType::mutable_type>);
{
auto coll = CollectionType{};
auto item = coll.create(13ull, 0., 0., 0., 0.);
REQUIRE(coll.begin()->cellID() == 13ull);
auto new_item = CollectionType::value_type::mutable_type{42ull, 0., 0., 0., 0.};
auto new_item = CollectionType::mutable_type{42ull, 0., 0., 0., 0.};
*coll.begin() = new_item;
DOCUMENTED_FAILURE(coll.begin()->cellID() == 42ull);
}
// const_iterator
STATIC_REQUIRE(traits::has_dereference_assignment_v<const_iterator, CollectionType::value_type>);
STATIC_REQUIRE(traits::has_dereference_assignment_v<const_iterator, CollectionType::value_type::mutable_type>);
STATIC_REQUIRE(traits::has_dereference_assignment_v<const_iterator, CollectionType::mutable_type>);
{
auto coll = CollectionType{};
auto item = coll.create(13ull, 0., 0., 0., 0.);
REQUIRE(coll.cbegin()->cellID() == 13ull);
auto new_item = CollectionType::value_type::mutable_type{42ull, 0., 0., 0., 0.};
auto new_item = CollectionType::mutable_type{42ull, 0., 0., 0., 0.};
*coll.cbegin() = new_item;
DOCUMENTED_FAILURE(coll.cbegin()->cellID() == 42ull);
new_item.cellID(44ull);
Expand All @@ -792,14 +792,13 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {
// *r++ = o
// iterator
DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_increment_v<iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(
traits::has_dereference_assignment_increment_v<iterator, CollectionType::value_type::mutable_type>);
DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_increment_v<iterator, CollectionType::mutable_type>);
// TODO add runtime check for assignment validity like in '*r = o' case
// const_iterator
DOCUMENTED_STATIC_FAILURE(
traits::has_dereference_assignment_increment_v<const_iterator, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(
traits::has_dereference_assignment_increment_v<const_iterator, CollectionType::value_type::mutable_type>);
traits::has_dereference_assignment_increment_v<const_iterator, CollectionType::mutable_type>);
// TODO add runtime check for assignment validity like in '*r = o' case

// iterator_category - not strictly necessary but advised
Expand Down Expand Up @@ -852,7 +851,7 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt
// insert immutable to not-SubsetCollection
REQUIRE_THROWS_AS(it = CollectionType::value_type{}, std::invalid_argument);
// insert mutable (implicit cast to immutable) to not-SubsetCollection
REQUIRE_THROWS_AS(it = CollectionType::value_type::mutable_type{}, std::invalid_argument);
REQUIRE_THROWS_AS(it = CollectionType::mutable_type{}, std::invalid_argument);
auto subColl = CollectionType{};
subColl.setSubsetCollection(true);
auto subIt = std::back_inserter(subColl);
Expand Down
Loading