Skip to content

Commit

Permalink
add detail function for object rank that can be used for comparison
Browse files Browse the repository at this point in the history
add detecting if `uintptr_t` is defined
  • Loading branch information
m-fila committed Nov 29, 2024
1 parent 9942d56 commit 25abd06
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
13 changes: 13 additions & 0 deletions include/podio/detail/RankType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef PODIO_DETAIL_RANKTYPE_H
#define PODIO_DETAIL_RANKTYPE_H
#include <cstdint>

namespace podio::detail {
#ifdef UINTPTR_MAX
using rank_type = uintptr_t;
#else
using rank_type = uintmax_t;
#endif
} // namespace podio::detail

#endif // PODIO_DETAIL_RANKTYPE_H
9 changes: 5 additions & 4 deletions python/templates/Interface.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "podio/ObjectID.h"
#include "podio/utilities/TypeHelpers.h"
#include "podio/detail/RankType.h"

#include <memory>
#include <ostream>
Expand Down Expand Up @@ -59,7 +60,7 @@ private:
{{ macros.member_getters_concept(Members, use_get_syntax) }}
virtual const std::type_info& typeInfo() const = 0;
virtual bool equal(const Concept* rhs) const = 0;
virtual const void* objAddress() const = 0;
virtual podio::detail::rank_type objRank() const = 0;
};

template<typename ValueT>
Expand Down Expand Up @@ -88,8 +89,8 @@ private:
return false;
}

const void* objAddress() const final {
return m_value.m_obj.get();
podio::detail::rank_type objRank() const final {
return podio::detail::getRank(m_value);
}

{{ macros.member_getters_model(Members, use_get_syntax) }}
Expand Down Expand Up @@ -169,7 +170,7 @@ public:
}

friend bool operator<(const {{ class.bare_type }}& lhs, const {{ class.bare_type }}& rhs) {
return lhs.m_self->objAddress() < rhs.m_self->objAddress();
return lhs.m_self->objRank() < rhs.m_self->objRank();
}

{{ macros.member_getters(Members, use_get_syntax) }}
Expand Down
4 changes: 4 additions & 0 deletions python/templates/Object.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
VectorMembers, use_get_syntax)}}

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

podio::detail::rank_type podio::detail::getRank(const {{ class.namespace }}::{{ class.bare_type }}& obj) {
return reinterpret_cast<rank_type>(obj.m_obj.get());
}
9 changes: 6 additions & 3 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/utilities/MaybeSharedPtr.h"
#include "podio/detail/RankType.h"

#include <ostream>
#include <cstdint>
Expand All @@ -22,6 +23,10 @@

{{ utils.forward_decls(forward_declarations) }}

namespace podio::detail {
rank_type getRank(const {{ class.namespace }}::{{ class.bare_type }}& obj);
};

{{ utils.namespace_open(class.namespace) }}
class Mutable{{ class.bare_type }};
class {{ class.bare_type }}Collection;
Expand All @@ -34,9 +39,7 @@ class {{ class.bare_type }} {
friend class {{ class.bare_type }}Collection;
friend class {{ class.full_type }}CollectionData;
friend class {{ class.bare_type }}CollectionIterator;
{% for interface in using_interface_types %}
friend class {{ interface }};
{% endfor %}
friend podio::detail::rank_type podio::detail::getRank(const {{ class.bare_type }} & obj);

public:
using mutable_type = Mutable{{ class.bare_type }};
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 @@ -97,7 +97,7 @@
bool operator!=(const {{ inverse_type }}& other) const { return !(*this == other); }

// less comparison operator, so that objects can be e.g. stored in sets.
bool operator<(const {{ full_type }}& other) const { return m_obj < other.m_obj; }
bool operator<(const {{ full_type }}& other) const { return podio::detail::getRank(*this) < podio::detail::getRank(other); }

podio::ObjectID id() const { return getObjectID(); }

Expand Down

0 comments on commit 25abd06

Please sign in to comment.