src/qvmath/qvcombinationiterator.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      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 QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #ifndef QVCOMBINATIONITERATOR_H
00026 #define QVCOMBINATIONITERATOR_H
00027 
00028 #include <QVector>
00029 
00030 #include <qvmath/qvmath.h>
00031 
00111 class QVCombinationIterator: public QVector<int>
00112         {
00113         private:
00114                 int numElements;
00115                 bool endCondition;
00116 
00117         public:
00121                 QVCombinationIterator(): QVector<int>(1), numElements(1), endCondition(true)
00122                         { }
00123 
00127                 QVCombinationIterator(const QVCombinationIterator &combinationIterator): QVector<int>(combinationIterator),
00128                         numElements(combinationIterator.numElements), endCondition(combinationIterator.endCondition)
00129                         { }
00130 
00136                 QVCombinationIterator(const int numElements, const int elementsXSet): QVector<int>(elementsXSet),
00137                         numElements(numElements), endCondition(false)
00138                         {
00139                         Q_ASSERT(numElements > 0);
00140                         Q_ASSERT(numElements >= elementsXSet);
00141                         for (int i=0; i < elementsXSet; i++)
00142                                 operator[](i) = i;
00143                         }
00144  
00150                 virtual bool increment();
00151 
00155                 // infix ++ operator
00156                 QVCombinationIterator& operator++ ()    { increment(); return *this; }
00157 
00161                 // postfix ++ operator
00162                 void operator++ (int)                   { ++(*this); }
00163 
00168                 const double getSubsetNumber()  const   { return qvCombination(numElements, size()); }
00169 
00172                 const bool finished()           const   { return endCondition; }
00173 
00176                 const int firstIndex()          const   { return first(); }
00177 
00180                 const int lastIndex()           const   { return last(); }
00181 
00184                 const int getSetCardinallity()  const   { return numElements; }
00185 
00188                 const int getSubsetsSize()      const   { return size(); }
00189         };
00190 
00198 std::ostream& operator << ( std::ostream &os, const QVCombinationIterator &combination);
00199 
00200 #endif

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3