MRPT  2.0.4
ContainerReadOnlyProxyAccessor.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/core/exceptions.h>
12 #include <cstdlib> // size_t
13 
14 namespace mrpt::containers
15 {
16 /** \addtogroup stlext_grp
17  * @{ */
18 
19 /** A generic proxy accessor template that only allows read-only access to the
20  * original binded STL container object. */
21 template <typename STLCONTAINER>
23 {
24  /** ctor: binds to source object */
25  ContainerReadOnlyProxyAccessor(STLCONTAINER& source) : m_source(source) {}
26  /** (Deleted ctor) ignore copies (keep reference to original object) */
29  /** Don't copy the reference to the source object, but copy the contained
30  * data. This is only allowed if the size of the buffers coincide. */
33  {
34  ASSERT_EQUAL_(m_source.size(), o.m_source.size());
35  m_source = o.m_source;
36  return *this;
37  }
38  /** Transparent conversion to const ref to original source object. */
39  operator const STLCONTAINER&() const { return m_source; }
40  size_t size() const { return m_source.size(); }
41  const typename STLCONTAINER::value_type& operator[](const int i) const
42  {
43  return m_source[i];
44  }
45 
46  typename STLCONTAINER::const_iterator begin() const
47  {
48  return m_source.begin();
49  }
50  typename STLCONTAINER::const_iterator end() const { return m_source.end(); }
51  typename STLCONTAINER::const_reverse_iterator rbegin() const
52  {
53  return m_source.rbegin();
54  }
55  typename STLCONTAINER::const_reverse_iterator rend() const
56  {
57  return m_source.rend();
58  }
59 
60  private:
61  STLCONTAINER& m_source;
62 };
63 
64 /** @} */ // end of grouping
65 } // namespace mrpt::containers
mrpt::containers::ContainerReadOnlyProxyAccessor::m_source
STLCONTAINER & m_source
Definition: ContainerReadOnlyProxyAccessor.h:61
exceptions.h
mrpt::containers::ContainerReadOnlyProxyAccessor::end
STLCONTAINER::const_iterator end() const
Definition: ContainerReadOnlyProxyAccessor.h:50
ASSERT_EQUAL_
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
mrpt::containers::ContainerReadOnlyProxyAccessor::operator=
ContainerReadOnlyProxyAccessor< STLCONTAINER > & operator=(const ContainerReadOnlyProxyAccessor< STLCONTAINER > &o)
Don't copy the reference to the source object, but copy the contained data.
Definition: ContainerReadOnlyProxyAccessor.h:31
mrpt::containers::ContainerReadOnlyProxyAccessor::ContainerReadOnlyProxyAccessor
ContainerReadOnlyProxyAccessor(STLCONTAINER &source)
ctor: binds to source object
Definition: ContainerReadOnlyProxyAccessor.h:25
mrpt::containers::ContainerReadOnlyProxyAccessor::size
size_t size() const
Definition: ContainerReadOnlyProxyAccessor.h:40
mrpt::containers::ContainerReadOnlyProxyAccessor::begin
STLCONTAINER::const_iterator begin() const
Definition: ContainerReadOnlyProxyAccessor.h:46
mrpt::containers::ContainerReadOnlyProxyAccessor
A generic proxy accessor template that only allows read-only access to the original binded STL contai...
Definition: ContainerReadOnlyProxyAccessor.h:22
mrpt::containers::ContainerReadOnlyProxyAccessor::operator[]
const STLCONTAINER::value_type & operator[](const int i) const
Definition: ContainerReadOnlyProxyAccessor.h:41
mrpt::containers::ContainerReadOnlyProxyAccessor::rend
STLCONTAINER::const_reverse_iterator rend() const
Definition: ContainerReadOnlyProxyAccessor.h:55
mrpt::containers
Definition: bimap.h:14
mrpt::containers::ContainerReadOnlyProxyAccessor::rbegin
STLCONTAINER::const_reverse_iterator rbegin() const
Definition: ContainerReadOnlyProxyAccessor.h:51



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Fri Jul 17 08:43:33 UTC 2020