Skip to content

Commit 7ddb151

Browse files
committed
align constness with track edm
1 parent 1ed080c commit 7ddb151

File tree

2 files changed

+62
-17
lines changed

2 files changed

+62
-17
lines changed

Core/include/Acts/EventData/SpacePointColumnProxy2.hpp

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,30 @@ class SpacePointColumnProxy {
2626
public:
2727
constexpr static bool ReadOnly = read_only;
2828
using Index = SpacePointIndex2;
29-
using Value = const_if_t<ReadOnly, T>;
29+
using Value = T;
3030
using Container = const_if_t<ReadOnly, SpacePointContainer2>;
31-
using Column = const_if_t<ReadOnly, std::vector<T>>;
32-
using Span = std::span<Value>;
33-
using Reference = Value &;
31+
using Column = const_if_t<ReadOnly, std::vector<Value>>;
3432

33+
/// Constructs a space point column proxy for the given container and column.
34+
/// @param container The container holding the space point.
35+
/// @param column The column of data to access.
3536
SpacePointColumnProxy(Container &container, Column &column)
3637
: m_container{&container}, m_column(&column) {}
3738

39+
/// Copy construct a space point column proxy.
40+
/// @param other The space point column proxy to copy.
41+
SpacePointColumnProxy(const SpacePointColumnProxy &other) noexcept = default;
42+
43+
/// Copy construct a mutable space point column proxy.
44+
/// @param other The mutable space point column proxy to copy.
45+
explicit SpacePointColumnProxy(
46+
const SpacePointColumnProxy<T, false> &other) noexcept
47+
requires ReadOnly
48+
: m_container(&other.container()), m_column(&other.column()) {}
49+
3850
/// Gets the container holding the space point.
3951
/// @return A reference to the container holding the space point.
40-
SpacePointContainer2 &container() const noexcept
52+
SpacePointContainer2 &container() noexcept
4153
requires(!ReadOnly)
4254
{
4355
return *m_container;
@@ -50,18 +62,42 @@ class SpacePointColumnProxy {
5062

5163
/// Returns a const reference to the column container.
5264
/// @return A const reference to the column container.
53-
const Column &column() const noexcept { return *m_column; }
65+
const std::vector<Value> &column() const noexcept { return *m_column; }
5466

55-
/// Returns a span to the column data.
56-
/// @return A span to the column data.
57-
Span data() const noexcept { return Span(column().data(), column().size()); }
67+
/// Returns a mutable span to the column data.
68+
/// @return A mutable span to the column data.
69+
std::span<Value> data() noexcept
70+
requires(!ReadOnly)
71+
{
72+
return std::span<Value>(column().data(), column().size());
73+
}
74+
/// Returns a const span to the column data.
75+
/// @return A const span to the column data.
76+
std::span<const Value> data() const noexcept {
77+
return std::span<const Value>(column().data(), column().size());
78+
}
5879

59-
/// Returns a reference to the column entry at the given index.
80+
/// Returns a mutable reference to the column entry at the given index.
81+
/// If the index is out of range, an exception is thrown.
82+
/// @param index The index of the space point to access.
83+
/// @return A mutable reference to the column entry at the given index.
84+
/// @throws std::out_of_range if the index is out of range.
85+
Value &at(Index index)
86+
requires(!ReadOnly)
87+
{
88+
if (index >= column().size()) {
89+
throw std::out_of_range("Index out of range in SpacePointContainer2: " +
90+
std::to_string(index) +
91+
" >= " + std::to_string(size()));
92+
}
93+
return data()[index];
94+
}
95+
/// Returns a const reference to the column entry at the given index.
6096
/// If the index is out of range, an exception is thrown.
6197
/// @param index The index of the space point to access.
62-
/// @return A reference to the column entry at the given index.
98+
/// @return A const reference to the column entry at the given index.
6399
/// @throws std::out_of_range if the index is out of range.
64-
Reference at(Index index) const {
100+
const Value &at(Index index) const {
65101
if (index >= column().size()) {
66102
throw std::out_of_range("Index out of range in SpacePointContainer2: " +
67103
std::to_string(index) +
@@ -70,10 +106,19 @@ class SpacePointColumnProxy {
70106
return data()[index];
71107
}
72108

73-
/// Returns a reference to the column entry at the given index.
109+
/// Returns a mutable reference to the column entry at the given index.
110+
/// @param index The index of the space point to access.
111+
/// @return A mutable reference to the column entry at the given index.
112+
Value &operator[](Index index) noexcept
113+
requires(!ReadOnly)
114+
{
115+
assert(index < column().size() && "Index out of bounds");
116+
return data()[index];
117+
}
118+
/// Returns a const reference to the column entry at the given index.
74119
/// @param index The index of the space point to access.
75-
/// @return A reference to the column entry at the given index.
76-
Reference operator[](Index index) const noexcept {
120+
/// @return A const reference to the column entry at the given index.
121+
const Value &operator[](Index index) const noexcept {
77122
assert(index < column().size() && "Index out of bounds");
78123
return data()[index];
79124
}
@@ -84,7 +129,7 @@ class SpacePointColumnProxy {
84129

85130
std::uint32_t size() const noexcept { return column().size(); }
86131

87-
Column &column() const noexcept
132+
std::vector<Value> &column() noexcept
88133
requires(!ReadOnly)
89134
{
90135
return *m_column;

Core/include/Acts/EventData/SpacePointProxy2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class SpacePointProxy2 {
185185
/// @param column The extra column proxy to access.
186186
/// @return A mutable reference to the value in the extra column for the space point.
187187
template <typename T>
188-
T &extra(const MutableSpacePointColumnProxy<T> &column) const noexcept {
188+
T &extra(MutableSpacePointColumnProxy<T> &column) const noexcept {
189189
return column[m_index];
190190
}
191191

0 commit comments

Comments
 (0)