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
A generic proxy accessor template that only allows read-only access to the original binded STL contai...
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
const STLCONTAINER::value_type & operator[](const int i) const
ContainerReadOnlyProxyAccessor< STLCONTAINER > & operator=(const ContainerReadOnlyProxyAccessor< STLCONTAINER > &o)
Don&#39;t copy the reference to the source object, but copy the contained data.
STLCONTAINER::const_reverse_iterator rbegin() const
ContainerReadOnlyProxyAccessor(STLCONTAINER &source)
ctor: binds to source object
STLCONTAINER::const_reverse_iterator rend() const



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020