latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiSortExpensive.h 00027 * authors ....: Joerg Zieren 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 24.06.2002 00030 * revisions ..: $Id: ltiSortExpensive.h,v 1.3 2006/02/08 12:45:01 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_SORT_EXPENSIVE_H_ 00034 #define _LTI_SORT_EXPENSIVE_H_ 00035 00036 #include <ltiObject.h> 00037 #include <list> 00038 00039 namespace lti { 00040 /** 00041 * Sorts elements in a list that are computationally expensive to compare. 00042 * You need to provide a pointer to a class member function that performs the 00043 * expensive computation (e.g. area computation). This class sorts the list 00044 * while performing the expensive computation exactly once for each element. 00045 */ 00046 template <class T, class TValue> 00047 class sortExpensive : public lti::object { 00048 protected: 00049 /** Helper class for sorting. */ 00050 class sortHelper { 00051 public: 00052 typename std::list<T>::iterator theIterator; 00053 TValue value; 00054 sortHelper(const typename std::list<T>::iterator& it, 00055 const TValue& val) : theIterator(it),value(val) {}; 00056 bool operator<(const sortHelper& other) { 00057 return value < other.value; 00058 }; 00059 }; 00060 00061 public: 00062 /** Constructor */ 00063 sortExpensive(); 00064 /** Copy constructor (same as sortExpensive() - no memory.) */ 00065 sortExpensive(const sortExpensive& other); 00066 00067 /** 00068 * Destructor 00069 */ 00070 virtual ~sortExpensive(); 00071 00072 /** 00073 * Sort the elements in the given list. Requires a function 00074 * pointer that computes a double value for an object of type 00075 * T. The function is assumed to be a class member function, 00076 * therefore a pointer to an instance of that class 00077 * (<code>callbackPtr</code>) is required (see 00078 * <code>www.function-pointer.org</code>). See ltiObjectsFromMask 00079 * for a usage example. 00080 */ 00081 void apply(std::list<T>& aList, void* callbackPtr, 00082 TValue (*computeValue)(void* callbackPtr, const T&)); 00083 00084 /** returns the name of this type */ 00085 virtual const char* getTypeName() const; 00086 }; 00087 } 00088 00089 #include "ltiSortExpensive_template.h" 00090 00091 #endif