2 Copyright (C) 2002-2021 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
72 ATH_MEMBER_REQUIRES_DEF(!DVL::must_own, ElementProxy<DVL>&)
73 ElementProxy<DVL>::operator= (typename DVL::value_type rhs)
75 if (rhs != *m_proxied)
76 m_container->assignElement(m_proxied, rhs);
82 * @brief Assignment operator, from a pointer.
83 * @param rhs The pointer from which we're assigning.
85 * If @a rhs is the same as the element we're proxying, then
86 * we don't need to do anything. Otherwise, @c can_insert must
87 * be true. The container must own its elements in order
88 * to use this interface.
92 ElementProxy<DVL>::operator= (typename DVL::unique_type rhs)
94 if (rhs.get() != *m_proxied)
95 m_container->assignElement(m_proxied, std::move(rhs));
101 * @brief Conversion to a (const) pointer.
103 * We just need to do a cast here.
107 ElementProxy<DVL>::operator typename DVL::value_type const() const
109 return DataModel_detail::DVLCast<DVL>::cast (*m_proxied);
114 * @brief Conversion to a (const) pointer.
116 * We just need to do a cast here.
120 typename DVL::value_type const ElementProxy<DVL>::operator-> () const
122 return DataModel_detail::DVLCast<DVL>::cast (*m_proxied);
127 * @brief Return the container holding the element that this object proxies.
131 DVL* ElementProxy<DVL>::container()
138 * @brief Return the container holding the element that this object proxies.
142 const DVL* ElementProxy<DVL>::container() const
148 } // namespace DataModel_detail