2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 * @file AthContainers/tools/ElementProxy.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Proxy for lvalue access to @c DataVector/@c DataList elements.
12 #include "AthContainers/tools/DVLCast.h"
13 #include "AthContainers/tools/ATHCONTAINERS_ASSERT.h"
16 namespace DataModel_detail {
21 * @param i The underlying container iterator pointing at
22 * the element which we're proxying.
23 * @param container The container that the iterator references.
27 ElementProxy<DVL>::ElementProxy (typename DVL::BaseContainer::iterator i,
30 m_container (container)
36 * @brief Assignment operator, from an @c Element proxy.
37 * @param rhs The proxy from which we're assigning.
39 * If @a rhs is the same as the element we're proxying, then
40 * we don't need to do anything. Otherwise, @c can_insert must
41 * be true. If the parent @c DataVector/List owns its elements,
42 * we then need to delete the proxied object before making
43 * the assignment. We also disallow copying between two
44 * @c DataVector/List's, both of which own their elements.
47 // cppcheck-suppress operatorEqVarError
48 ElementProxy<DVL>& ElementProxy<DVL>::operator= (const ElementProxy& rhs)
50 static_assert (!DVL::must_own);
51 if (*rhs.m_proxied != *m_proxied) {
52 // cppcheck-suppress assertWithSideEffect
53 ATHCONTAINERS_ASSERT (! (container()->ownPolicy() == SG::OWN_ELEMENTS &&
54 rhs.container()->ownPolicy() == SG::OWN_ELEMENTS));
55 container()->assignBaseElement (m_proxied, *rhs.m_proxied);
62 * @brief Assignment operator, from a pointer.
63 * @param rhs The pointer from which we're assigning.
65 * If @a rhs is the same as the element we're proxying, then
66 * we don't need to do anything. Otherwise, @c can_insert must
67 * be true. If the parent @c DataVector/List owns its elements,
68 * we then need to delete the proxied object before making
73 requires(!DVL::must_own)
75 ElementProxy<DVL>::operator= (typename DVL::value_type rhs)
77 if (rhs != *m_proxied)
78 m_container->assignElement(m_proxied, rhs);
84 * @brief Assignment operator, from a pointer.
85 * @param rhs The pointer from which we're assigning.
87 * If @a rhs is the same as the element we're proxying, then
88 * we don't need to do anything. Otherwise, @c can_insert must
89 * be true. The container must own its elements in order
90 * to use this interface.
94 ElementProxy<DVL>::operator= (typename DVL::unique_type rhs)
96 if (rhs.get() != *m_proxied)
97 m_container->assignElement(m_proxied, std::move(rhs));
103 * @brief Conversion to a (const) pointer.
105 * We just need to do a cast here.
109 ElementProxy<DVL>::operator typename DVL::value_type const() const
111 return DataModel_detail::DVLCast<DVL>::cast (*m_proxied);
116 * @brief Conversion to a (const) pointer.
118 * We just need to do a cast here.
122 typename DVL::value_type const ElementProxy<DVL>::operator-> () const
124 return DataModel_detail::DVLCast<DVL>::cast (*m_proxied);
129 * @brief Return the container holding the element that this object proxies.
133 DVL* ElementProxy<DVL>::container()
140 * @brief Return the container holding the element that this object proxies.
144 const DVL* ElementProxy<DVL>::container() const
150 } // namespace DataModel_detail