![]() |
University of Murcia, Spain ![]() |
src/qvmath/qvcombinationiterator.hGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008, 2009. 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 <qvmath.h> 00029 #include <QVector> 00030 00110 class QVCombinationIterator: public QVector<int> 00111 { 00112 private: 00113 int numElements; 00114 bool endCondition; 00115 00116 public: 00120 QVCombinationIterator(): QVector<int>(1), numElements(1), endCondition(true) 00121 { } 00122 00126 QVCombinationIterator(const QVCombinationIterator &combinationIterator): QVector<int>(combinationIterator), 00127 numElements(combinationIterator.numElements), endCondition(combinationIterator.endCondition) 00128 { } 00129 00135 QVCombinationIterator(const int numElements, const int elementsXSet): QVector<int>(elementsXSet), 00136 numElements(numElements), endCondition(false) 00137 { 00138 Q_ASSERT(numElements > 0); 00139 Q_ASSERT(numElements >= elementsXSet); 00140 for (int i=0; i < elementsXSet; i++) 00141 operator[](i) = i; 00142 } 00143 00144 virtual ~QVCombinationIterator() { } 00145 00151 virtual bool increment(); 00152 00156 // infix ++ operator 00157 QVCombinationIterator& operator++ () { increment(); return *this; } 00158 00162 // postfix ++ operator 00163 void operator++ (int) { ++(*this); } 00164 00169 const double getSubsetNumber() const { return qvCombination(numElements, size()); } 00170 00173 const bool finished() const { return endCondition; } 00174 00177 const int firstIndex() const { return first(); } 00178 00181 const int lastIndex() const { return last(); } 00182 00185 const int getSetCardinallity() const { return numElements; } 00186 00189 const int getSubsetsSize() const { return size(); } 00190 }; 00191 00199 std::ostream& operator << ( std::ostream &os, const QVCombinationIterator &combination); 00200 00201 #endif |