00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00157 QVCombinationIterator& operator++ () { increment(); return *this; }
00158
00162
00163 void operator++ (int) { ++(*this); }
00164
00169 double getSubsetNumber() const { return qvCombination(numElements, size()); }
00170
00173 bool finished() const { return endCondition; }
00174
00177 int firstIndex() const { return first(); }
00178
00181 int lastIndex() const { return last(); }
00182
00185 int getSetCardinallity() const { return numElements; }
00186
00189 int getSubsetsSize() const { return size(); }
00190 };
00191
00199 std::ostream& operator << ( std::ostream &os, const QVCombinationIterator &combination);
00200
00201 #endif