00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 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 */ 00045 template <class T> 00046 class list_searchable : public std::list<T> 00047 { 00048 public: 00049 void insert( const T &o ) { std::list<T>::push_back(o); } 00050 00051 typename std::list<T>::iterator find( const T& i ) { 00052 return std::find(std::list<T>::begin(),std::list<T>::end(),i); 00053 } 00054 00055 typename std::list<T>::const_iterator find( const T& i ) const { 00056 return std::find(std::list<T>::begin(),std::list<T>::end(),i); 00057 } 00058 00059 /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */ 00060 template <typename PTR> 00061 typename std::list<T>::iterator find_ptr_to( const PTR ptr ) 00062 { 00063 for (typename std::list<T>::iterator it=std::list<T>::begin();it!=std::list<T>::end();it++) 00064 if (it->pointer()==ptr) 00065 return it; 00066 return std::list<T>::end(); 00067 } 00068 00069 /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */ 00070 template <typename PTR> 00071 typename std::list<T>::const_iterator find_ptr_to( const PTR ptr ) const 00072 { 00073 for (typename std::list<T>::const_iterator it=std::list<T>::begin();it!=std::list<T>::end();it++) 00074 if (it->pointer()==ptr) 00075 return it; 00076 return std::list<T>::end(); 00077 } 00078 00079 }; 00080 00081 } // End of namespace 00082 } // End of namespace 00083 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011 |