Debian Codegraph @

Source/Reasoner/Kernel/Process/CReapplyConceptLabelSetIterator.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 "CReapplyConceptLabelSetIterator.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33
34 CReapplyConceptLabelSetIterator::CReapplyConceptLabelSetIterator(cint64 conceptCount, CConceptDescriptor* conceptDesLinker, const CPROCESSMAP<cint64,CConceptDescriptorDependencyReapplyData>::const_iterator& beginIt, const CPROCESSMAP<cint64,CConceptDescriptorDependencyReapplyData>::const_iterator& endIt, const CPROCESSMAP<cint64,CConceptDescriptorDependencyReapplyData>::const_iterator& addBeginIt, const CPROCESSMAP<cint64,CConceptDescriptorDependencyReapplyData>::const_iterator& addEndIt, bool skipEmptyConceptDescriptors)
35 : mConceptCount(conceptCount),mConceptDesLinkerIt(conceptDesLinker),mConDesDepBeginIt(beginIt),mConDesDepEndIt(endIt),mSkipEmptyConceptDescriptors(skipEmptyConceptDescriptors),mAdditionalConDesDepBeginIt(addBeginIt),mAdditionalConDesDepEndIt(addEndIt) {
36
37 if (mSkipEmptyConceptDescriptors) {
38 while (mConDesDepBeginIt != mConDesDepEndIt && mConDesDepBeginIt.value().mConceptDescriptor == nullptr) {
39 ++mConDesDepBeginIt;
40 }
41 while (mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt && mAdditionalConDesDepBeginIt.value().mConceptDescriptor == nullptr) {
42 ++mAdditionalConDesDepBeginIt;
43 }
44 }
45 }
46
47
48
49 cint64 CReapplyConceptLabelSetIterator::getRemainingConceptCount() {
50 return mConceptCount;
51 }
52
53
54 CReapplyConceptLabelSetIterator& CReapplyConceptLabelSetIterator::operator++() {
55 return *moveNext();
56 }
57
58 CConceptDescriptor* CReapplyConceptLabelSetIterator::operator*() {
59 return getConceptDescriptor();
60 }
61
62
63 CReapplyConceptLabelSetIterator* CReapplyConceptLabelSetIterator::moveNext() {
64 if (mConceptDesLinkerIt) {
65 mConceptDesLinkerIt = mConceptDesLinkerIt->getNext();
66 --mConceptCount;
67 } else {
68 if (mConDesDepBeginIt != mConDesDepEndIt || mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt) {
69 if (mConDesDepBeginIt != mConDesDepEndIt && mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt) {
70 if (mAdditionalConDesDepBeginIt.key() == mConDesDepBeginIt.key()) {
71 ++mAdditionalConDesDepBeginIt;
72 ++mConDesDepBeginIt;
73 } else if (mAdditionalConDesDepBeginIt.key() < mConDesDepBeginIt.key()) {
74 ++mAdditionalConDesDepBeginIt;
75 } else {
76 ++mConDesDepBeginIt;
77 }
78 } else if (mConDesDepBeginIt == mConDesDepEndIt) {
79 ++mAdditionalConDesDepBeginIt;
80 } else {
81 ++mConDesDepBeginIt;
82 }
83 if (mSkipEmptyConceptDescriptors) {
84 while (mConDesDepBeginIt != mConDesDepEndIt && mConDesDepBeginIt.value().mConceptDescriptor == nullptr) {
85 ++mConDesDepBeginIt;
86 }
87 while (mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt && mAdditionalConDesDepBeginIt.value().mConceptDescriptor == nullptr) {
88 ++mAdditionalConDesDepBeginIt;
89 }
90 }
91 --mConceptCount;
92 }
93 }
94 return this;
95 }
96
97 cint64 CReapplyConceptLabelSetIterator::getDataTag() {
98 if (mConceptDesLinkerIt) {
99 return mConceptDesLinkerIt->getConceptTag();
100 } else {
101 if (mConDesDepBeginIt != mConDesDepEndIt && mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt) {
102 if (mAdditionalConDesDepBeginIt.key() < mConDesDepBeginIt.key()) {
103 return mAdditionalConDesDepBeginIt.key();
104 } else {
105 return mConDesDepBeginIt.key();
106 }
107 } else if (mConDesDepBeginIt == mConDesDepEndIt) {
108 return mAdditionalConDesDepBeginIt.key();
109 } else {
110 return mConDesDepBeginIt.key();
111 }
112 }
113 }
114
115
116 CConceptDescriptor* CReapplyConceptLabelSetIterator::getConceptDescriptor() {
117 if (mConceptDesLinkerIt) {
118 return mConceptDesLinkerIt;
119 } else {
120 if (mConDesDepBeginIt != mConDesDepEndIt && mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt) {
121 if (mAdditionalConDesDepBeginIt.key() < mConDesDepBeginIt.key()) {
122 return mAdditionalConDesDepBeginIt.value().mConceptDescriptor;
123 } else {
124 return mConDesDepBeginIt.value().mConceptDescriptor;
125 }
126 } else if (mConDesDepBeginIt == mConDesDepEndIt) {
127 return mAdditionalConDesDepBeginIt.value().mConceptDescriptor;
128 } else {
129 return mConDesDepBeginIt.value().mConceptDescriptor;
130 }
131 }
132 }
133
134 CDependencyTrackPoint* CReapplyConceptLabelSetIterator::getDependencyTrackPoint() {
135 if (mConceptDesLinkerIt) {
136 return mConceptDesLinkerIt->getDependencyTrackPoint();
137 } else {
138 CConceptDescriptor* conDes = getConceptDescriptor();
139 if (conDes) {
140 return conDes->getDependencyTrackPoint();
141 } else {
142 return nullptr;
143 }
144 }
145 }
146
147 const CCondensedReapplyQueue *CReapplyConceptLabelSetIterator::getPosNegReapplyQueue() {
148 if (mConceptDesLinkerIt) {
149 return nullptr;
150 } else {
151 if (mConDesDepBeginIt != mConDesDepEndIt && mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt) {
152 if (mAdditionalConDesDepBeginIt.key() < mConDesDepBeginIt.key()) {
153 return &mAdditionalConDesDepBeginIt.value().mPosNegReapplyQueue;
154 } else {
155 return &mConDesDepBeginIt.value().mPosNegReapplyQueue;
156 }
157 } else if (mConDesDepBeginIt == mConDesDepEndIt) {
158 return &mAdditionalConDesDepBeginIt.value().mPosNegReapplyQueue;
159 } else {
160 return &mConDesDepBeginIt.value().mPosNegReapplyQueue;
161 }
162 }
163 }
164
165
166 CConceptDescriptor* CReapplyConceptLabelSetIterator::next(bool moveToNext) {
167 CConceptDescriptor* conDes = getConceptDescriptor();
168 if (moveToNext) {
169 moveNext();
170 }
171 return conDes;
172 }
173
174 bool CReapplyConceptLabelSetIterator::hasValue() {
175 return mConceptDesLinkerIt || mConDesDepBeginIt != mConDesDepEndIt || mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt;
176 }
177
178 bool CReapplyConceptLabelSetIterator::hasNext() {
179 return mConceptDesLinkerIt || mConDesDepBeginIt != mConDesDepEndIt || mAdditionalConDesDepBeginIt != mAdditionalConDesDepEndIt;
180 }
181
182 bool CReapplyConceptLabelSetIterator::operator!=(CReapplyConceptLabelSetIterator& iterator) {
183 return mConceptDesLinkerIt != iterator.mConceptDesLinkerIt || mConDesDepBeginIt != iterator.mConDesDepBeginIt || mAdditionalConDesDepBeginIt != iterator.mAdditionalConDesDepEndIt;
184 }
185
186 bool CReapplyConceptLabelSetIterator::operator==(CReapplyConceptLabelSetIterator& iterator) {
187 return mConceptDesLinkerIt == iterator.mConceptDesLinkerIt && mConDesDepBeginIt == iterator.mConDesDepBeginIt && mAdditionalConDesDepBeginIt != iterator.mAdditionalConDesDepEndIt;
188 }
189
190 }; // end namespace Process
191
192 }; // end namespace Kernel
193
194 }; // end namespace Reasoner
195
196 }; // end namespace Konclude