MRPT  1.9.9
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-2019, 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 */
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 
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:178
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
GLsizei GLsizei GLchar * source
Definition: glext.h:4097
const Scalar * const_iterator
Definition: eigen_plugins.h:27
STLCONTAINER::const_reverse_iterator rend() const



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 5887d2b31 Wed Apr 24 13:03:27 2019 +0200 at miƩ abr 24 13:10:13 CEST 2019