Main MRPT website > C++ reference
MRPT logo
list_searchable.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-2015, 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 #ifndef list_searchable_H
10 #define list_searchable_H
11 
12 #include <list>
13 #include <algorithm>
14 
15 namespace mrpt
16 {
17  namespace utils
18  {
19  using std::for_each;
20  using std::string;
21 
22  /** This class implements a STL container with features of both, a std::set and a std::list.
23  * \ingroup stlext_grp
24  */
25  template <class T>
26  class list_searchable : public std::list<T>
27  {
28  public:
29  void insert( const T &o ) { std::list<T>::push_back(o); }
30 
31  typename std::list<T>::iterator find( const T& i ) {
32  return std::find(std::list<T>::begin(),std::list<T>::end(),i);
33  }
34 
35  typename std::list<T>::const_iterator find( const T& i ) const {
36  return std::find(std::list<T>::begin(),std::list<T>::end(),i);
37  }
38 
39  /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
40  template <typename PTR>
41  typename std::list<T>::iterator find_ptr_to( const PTR ptr )
42  {
43  for (typename std::list<T>::iterator it=std::list<T>::begin();it!=std::list<T>::end();it++)
44  if (it->pointer()==ptr)
45  return it;
46  return std::list<T>::end();
47  }
48 
49  /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
50  template <typename PTR>
51  typename std::list<T>::const_iterator find_ptr_to( const PTR ptr ) const
52  {
54  if (it->pointer()==ptr)
55  return it;
56  return std::list<T>::end();
57  }
58 
59  };
60 
61  } // End of namespace
62 } // End of namespace
63 #endif
This class implements a STL container with features of both, a std::set and a std::list.
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
Scalar * iterator
Definition: eigen_plugins.h:23
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
const Scalar * const_iterator
Definition: eigen_plugins.h:24
std::list< T >::iterator find_ptr_to(const PTR ptr)
Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::list< T >::const_iterator find(const T &i) const
std::list< T >::iterator find(const T &i)
std::list< T >::const_iterator find_ptr_to(const PTR ptr) const
Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain ...



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015