Debian Codegraph @

Source/Reasoner/Query/CVariableBindingsAnswersOrderedMapResult.cpp

raw
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 "CVariableBindingsAnswersOrderedMapResult.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Query {
29
30
31 CVariableBindingsAnswersOrderedMapResult::CVariableBindingsAnswersOrderedMapResult(const QStringList& varNames, CVariableBindingsAnswerResultMapOrdering* mapOrdering) {
32 mVariableNames = varNames;
33 mMapOrdering = mapOrdering;
34 }
35
36
37 CVariableBindingsAnswersOrderedMapResult::~CVariableBindingsAnswersOrderedMapResult() {
38 qDeleteAll(mBindingsContainer);
39 delete mMapOrdering;
40 }
41
42
43 CVariableBindingsAnswersOrderedMapResult* CVariableBindingsAnswersOrderedMapResult::addResultVariableBindings(CVariableBindingsAnswerResult* varBindings, cint64 cardinality) {
44 CVariableBindingsListAnswerResult* listVarBindings = dynamic_cast<CVariableBindingsListAnswerResult*>(varBindings);
45 if (listVarBindings) {
46 return addResultVariableBindings(listVarBindings);
47 } else {
48 mBindingsContainer.append(varBindings);
49 return this;
50 }
51 }
52
53 CVariableBindingsAnswersOrderedMapResult* CVariableBindingsAnswersOrderedMapResult::addResultVariableBindings(CVariableBindingsListAnswerResult* varBindings, cint64 cardinality) {
54 for (cint64 i = 0; i < cardinality; ++i) {
55 mOrderedBindingsMap.insertMulti(CVariableBindingsAnswerResultMapOrderer(varBindings, mMapOrdering), varBindings);
56 }
57 mBindingsContainer.append(varBindings);
58 return this;
59 }
60
61 CVariableBindingsAnswersOrderedMapResult* CVariableBindingsAnswersOrderedMapResult::setResultVariableBindingsList(const QMap<CVariableBindingsAnswerResultMapOrderer, CVariableBindingsAnswerResult*>& indiBindingSet) {
62 mOrderedBindingsMap = indiBindingSet;
63 return this;
64 }
65
66
67
68 QMap<CVariableBindingsAnswerResultMapOrderer, CVariableBindingsAnswerResult*>* CVariableBindingsAnswersOrderedMapResult::getResult() {
69 return &mOrderedBindingsMap;
70 }
71
72
73
74 QString CVariableBindingsAnswersOrderedMapResult::getQueryResultString() {
75 return QString();
76 }
77
78
79 bool CVariableBindingsAnswersOrderedMapResult::isResultEquivalentTo(CQueryResult *otherQueryResult) {
80 if (otherQueryResult) {
81 CVariableBindingsAnswersOrderedMapResult *otherBoolQueryResult = dynamic_cast<CVariableBindingsAnswersOrderedMapResult *>(otherQueryResult);
82 if (otherBoolQueryResult) {
83 return isResultEquivalentTo(otherBoolQueryResult);
84 }
85 }
86 return false;
87 }
88
89
90 bool CVariableBindingsAnswersOrderedMapResult::isResultEquivalentTo(CVariableBindingsAnswersOrderedMapResult *otherQueryResult) {
91 if (otherQueryResult) {
92 if (mOrderedBindingsMap.count() != otherQueryResult->mOrderedBindingsMap.count()) {
93 return false;
94 }
95 return mOrderedBindingsMap == otherQueryResult->mOrderedBindingsMap;
96 } else {
97 return false;
98 }
99 }
100
101
102 const QStringList& CVariableBindingsAnswersOrderedMapResult::getVariableNames() {
103 return mVariableNames;
104 }
105
106
107
108 CVariableBindingsAnswersResultIterator* CVariableBindingsAnswersOrderedMapResult::getVariableBindingsAnswersIterator(CVariableBindingsAnswersResultIterator* reuseIt) {
109 class CVariableBindingsListAnswerResultIterator : public CVariableBindingsAnswersResultIterator {
110 public:
111 CVariableBindingsListAnswerResultIterator(const QMap<CVariableBindingsAnswerResultMapOrderer, CVariableBindingsAnswerResult*>& set) {
112 init(set);
113 }
114
115 CVariableBindingsListAnswerResultIterator* init(const QMap<CVariableBindingsAnswerResultMapOrderer, CVariableBindingsAnswerResult*>& set) {
116 mIt = set.constBegin();
117 mItEnd = set.constEnd();
118 return this;
119 }
120
121
122 virtual CVariableBindingsAnswerResult* getNext(bool moveNext = true) {
123 QMap<CVariableBindingsAnswerResultMapOrderer, CVariableBindingsAnswerResult*>::const_iterator it = mIt;
124 if (it != mItEnd) {
125 if (moveNext) {
126 ++mIt;
127 }
128 return it.value();
129 }
130 return nullptr;
131 }
132
133 virtual bool hasNext() {
134 return mIt != mItEnd;
135 }
136
137 QMap<CVariableBindingsAnswerResultMapOrderer, CVariableBindingsAnswerResult*>::const_iterator mIt, mItEnd;
138
139 };
140 if (reuseIt) {
141 CVariableBindingsListAnswerResultIterator* listReuseIt = (CVariableBindingsListAnswerResultIterator*)reuseIt;
142 return listReuseIt->init(mOrderedBindingsMap);
143 }
144 return new CVariableBindingsListAnswerResultIterator(mOrderedBindingsMap);
145
146 }
147
148
149 cint64 CVariableBindingsAnswersOrderedMapResult::getResultCount() {
150 return mOrderedBindingsMap.count();
151 }
152
153
154 }; // end namespace Query
155
156 }; // end namespace Reasoner
157
158 }; // end namespace Konclude