| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "CVariableBindingsAnswersSetResult.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Query { |
| 29 |
|
| 30 |
|
| 31 |
CVariableBindingsAnswersSetResult::CVariableBindingsAnswersSetResult(const QStringList& varNames) { |
| 32 |
mVariableNames = varNames; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
CVariableBindingsAnswersSetResult::~CVariableBindingsAnswersSetResult() { |
| 37 |
qDeleteAll(mBindingsContainer); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
CVariableBindingsAnswersSetResult* CVariableBindingsAnswersSetResult::addResultVariableBindings(CVariableBindingsAnswerResult* varBindings, cint64 cardinality) { |
| 42 |
mBindingsSet.insert(varBindings); |
| 43 |
mBindingsContainer.append(varBindings); |
| 44 |
return this; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
bool CVariableBindingsAnswersSetResult::hasResultVariableBindings(CVariableBindingsAnswerResult* varBindings) { |
| 49 |
return mBindingsSet.contains(varBindings); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
CVariableBindingsAnswersSetResult* CVariableBindingsAnswersSetResult::setResultVariableBindingsList(const QSet<CVariableBindingsAnswerResultHasher>& indiBindingSet) { |
| 54 |
mBindingsSet = indiBindingSet; |
| 55 |
return this; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
QSet<CVariableBindingsAnswerResultHasher>* CVariableBindingsAnswersSetResult::getResult() { |
| 61 |
return &mBindingsSet; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
QString CVariableBindingsAnswersSetResult::getQueryResultString() { |
| 67 |
return QString(); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
bool CVariableBindingsAnswersSetResult::isResultEquivalentTo(CQueryResult *otherQueryResult) { |
| 72 |
if (otherQueryResult) { |
| 73 |
CVariableBindingsAnswersSetResult *otherBoolQueryResult = dynamic_cast<CVariableBindingsAnswersSetResult *>(otherQueryResult); |
| 74 |
if (otherBoolQueryResult) { |
| 75 |
return isResultEquivalentTo(otherBoolQueryResult); |
| 76 |
} |
| 77 |
} |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
bool CVariableBindingsAnswersSetResult::isResultEquivalentTo(CVariableBindingsAnswersSetResult *otherQueryResult) { |
| 83 |
if (otherQueryResult) { |
| 84 |
if (mBindingsSet.count() != otherQueryResult->mBindingsSet.count()) { |
| 85 |
return false; |
| 86 |
} |
| 87 |
return mBindingsSet == otherQueryResult->mBindingsSet; |
| 88 |
} else { |
| 89 |
return false; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
const QStringList& CVariableBindingsAnswersSetResult::getVariableNames() { |
| 95 |
return mVariableNames; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
CVariableBindingsAnswersResultIterator* CVariableBindingsAnswersSetResult::getVariableBindingsAnswersIterator(CVariableBindingsAnswersResultIterator* reuseIt) { |
| 101 |
class CVariableBindingsListAnswerResultIterator : public CVariableBindingsAnswersResultIterator { |
| 102 |
public: |
| 103 |
CVariableBindingsListAnswerResultIterator(const QSet<CVariableBindingsAnswerResultHasher>& set) { |
| 104 |
init(set); |
| 105 |
} |
| 106 |
|
| 107 |
CVariableBindingsListAnswerResultIterator* init(const QSet<CVariableBindingsAnswerResultHasher>& set) { |
| 108 |
mIt = set.constBegin(); |
| 109 |
mItEnd = set.constEnd(); |
| 110 |
return this; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
virtual CVariableBindingsAnswerResult* getNext(bool moveNext = true) { |
| 115 |
QSet<CVariableBindingsAnswerResultHasher>::const_iterator it = mIt; |
| 116 |
if (it != mItEnd) { |
| 117 |
if (moveNext) { |
| 118 |
++mIt; |
| 119 |
} |
| 120 |
return it->getBindingResult(); |
| 121 |
} |
| 122 |
return nullptr; |
| 123 |
} |
| 124 |
|
| 125 |
virtual bool hasNext() { |
| 126 |
return mIt != mItEnd; |
| 127 |
} |
| 128 |
|
| 129 |
QSet<CVariableBindingsAnswerResultHasher>::const_iterator mIt, mItEnd; |
| 130 |
|
| 131 |
}; |
| 132 |
if (reuseIt) { |
| 133 |
CVariableBindingsListAnswerResultIterator* listReuseIt = (CVariableBindingsListAnswerResultIterator*)reuseIt; |
| 134 |
return listReuseIt->init(mBindingsSet); |
| 135 |
} |
| 136 |
return new CVariableBindingsListAnswerResultIterator(mBindingsSet); |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
cint64 CVariableBindingsAnswersSetResult::getResultCount() { |
| 142 |
return mBindingsSet.count(); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
}; // end namespace Query |
| 147 |
|
| 148 |
}; // end namespace Reasoner |
| 149 |
|
| 150 |
}; // end namespace Konclude |