Main MRPT website > C++ reference
MRPT logo
list_searchable.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef  list_searchable_H
00029 #define  list_searchable_H
00030 
00031 // Note: This file is included from "stl_extensions.h"
00032 
00033 #include <list>
00034 
00035 namespace mrpt
00036 {
00037         namespace utils
00038         {
00039                 using namespace mrpt::utils::metaprogramming;
00040                 using std::for_each;
00041                 using std::string;
00042 
00043                 /** This class implements a STL container with features of both, a std::set and a std::list.
00044                  * \ingroup stlext_grp
00045                   */
00046                 template <class T>
00047                 class list_searchable : public std::list<T>
00048                 {
00049                 public:
00050                         void insert( const T &o ) { std::list<T>::push_back(o); }
00051 
00052                         typename std::list<T>::iterator find( const T& i ) {
00053                                 return std::find(std::list<T>::begin(),std::list<T>::end(),i);
00054                         }
00055 
00056                         typename std::list<T>::const_iterator find( const T& i ) const {
00057                                 return std::find(std::list<T>::begin(),std::list<T>::end(),i);
00058                         }
00059 
00060                         /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
00061                         template <typename PTR>
00062                         typename std::list<T>::iterator find_ptr_to( const PTR ptr )
00063                         {
00064                                 for (typename std::list<T>::iterator it=std::list<T>::begin();it!=std::list<T>::end();it++)
00065                                         if (it->pointer()==ptr)
00066                                                 return it;
00067                                 return std::list<T>::end();
00068                         }
00069 
00070                         /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
00071                         template <typename PTR>
00072                         typename std::list<T>::const_iterator find_ptr_to( const PTR ptr ) const
00073                         {
00074                                 for (typename std::list<T>::const_iterator it=std::list<T>::begin();it!=std::list<T>::end();it++)
00075                                         if (it->pointer()==ptr)
00076                                                 return it;
00077                                 return std::list<T>::end();
00078                         }
00079 
00080                 };
00081 
00082         } // End of namespace
00083 } // End of namespace
00084 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011