Main MRPT website > C++ reference
MRPT logo
list_searchable.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef list_searchable_H
29 #define list_searchable_H
30 
31 // Note: This file is included from "stl_extensions.h"
32 
33 #include <list>
34 
35 namespace mrpt
36 {
37  namespace utils
38  {
39  using namespace mrpt::utils::metaprogramming;
40  using std::for_each;
41  using std::string;
42 
43  /** This class implements a STL container with features of both, a std::set and a std::list.
44  * \ingroup stlext_grp
45  */
46  template <class T>
47  class list_searchable : public std::list<T>
48  {
49  public:
50  void insert( const T &o ) { std::list<T>::push_back(o); }
51 
52  typename std::list<T>::iterator find( const T& i ) {
53  return std::find(std::list<T>::begin(),std::list<T>::end(),i);
54  }
55 
56  typename std::list<T>::const_iterator find( const T& i ) const {
57  return std::find(std::list<T>::begin(),std::list<T>::end(),i);
58  }
59 
60  /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
61  template <typename PTR>
62  typename std::list<T>::iterator find_ptr_to( const PTR ptr )
63  {
64  for (typename std::list<T>::iterator it=std::list<T>::begin();it!=std::list<T>::end();it++)
65  if (it->pointer()==ptr)
66  return it;
67  return std::list<T>::end();
68  }
69 
70  /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
71  template <typename PTR>
72  typename std::list<T>::const_iterator find_ptr_to( const PTR ptr ) const
73  {
75  if (it->pointer()==ptr)
76  return it;
77  return std::list<T>::end();
78  }
79 
80  };
81 
82  } // End of namespace
83 } // End of namespace
84 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013