Main MRPT website > C++ reference for MRPT 1.5.7
ContainerReadOnlyProxyAccessor.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <cstdlib> // size_t
12 #include <mrpt/utils/mrpt_macros.h>
13 
14 namespace mrpt
15 {
16  namespace utils
17  {
18  /** \addtogroup stlext_grp
19  * @{ */
20 
21  /** A generic proxy accessor template that only allows read-only access to the original binded STL container object. */
22  template <typename STLCONTAINER>
24  {
25  ContainerReadOnlyProxyAccessor(STLCONTAINER &source) : m_source(source) { } //!< ctor: binds to source object
26  ContainerReadOnlyProxyAccessor(const ContainerReadOnlyProxyAccessor<STLCONTAINER> &) MRPT_DELETED_FUNC; //!< (Deleted ctor) ignore copies (keep reference to original object)
27  /** Don't copy the reference to the source object, but copy the contained data. This is only allowed if the size of the buffers coincide. */
29  {
30  ASSERT_EQUAL_(m_source.size(), o.m_source.size());
31  m_source = o.m_source;
32  return *this;
33  }
34  /** Transparent conversion to const ref to original source object. */
35  operator const STLCONTAINER & () const { return m_source; }
36 
37  size_t size() const { return m_source.size(); }
38  const typename STLCONTAINER::value_type & operator [](const int i) const { return m_source[i]; }
39 
40  typename STLCONTAINER::const_iterator begin() const { return m_source.begin(); }
41  typename STLCONTAINER::const_iterator end() const { return m_source.end(); }
42  typename STLCONTAINER::const_reverse_iterator rbegin() const { return m_source.rbegin(); }
43  typename STLCONTAINER::const_reverse_iterator rend() const { return m_source.rend(); }
44 
45  private:
46  STLCONTAINER & m_source;
47  };
48 
49  /** @} */ // end of grouping
50  }
51 }
52 
#define ASSERT_EQUAL_(__A, __B)
ContainerReadOnlyProxyAccessor(STLCONTAINER &source)
ctor: binds to source object
STLCONTAINER::const_reverse_iterator rbegin() const
const Scalar * const_iterator
Definition: eigen_plugins.h:24
ContainerReadOnlyProxyAccessor< STLCONTAINER > & operator=(const ContainerReadOnlyProxyAccessor< STLCONTAINER > &o)
Don&#39;t copy the reference to the source object, but copy the contained data.
#define MRPT_DELETED_FUNC
C++11 deleted function declarations.
A generic proxy accessor template that only allows read-only access to the original binded STL contai...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const STLCONTAINER::value_type & operator[](const int i) const
GLsizei GLsizei GLchar * source
Definition: glext.h:3908
STLCONTAINER::const_reverse_iterator rend() const



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 8277875f6 Mon Jun 11 02:47:32 2018 +0200 at lun oct 28 01:50:49 CET 2019