| 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 "CReapplyConceptSaturationLabelSetIterator.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
CReapplyConceptSaturationLabelSetIterator::CReapplyConceptSaturationLabelSetIterator(const CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>::const_iterator& itBegin, const CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>::const_iterator& itEnd, const CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>::const_iterator& itAdditionalBegin, const CPROCESSHASH<cint64,CConceptSaturationDescriptorReapplyData>::const_iterator& itAdditionalEnd, bool iterateConSatDes, bool iterateReapplies) |
| 35 |
: mItBegin(itBegin), mItEnd(itEnd), mItAdditionalBegin(itAdditionalBegin), mItAdditionalEnd(itAdditionalEnd), mIterateConSatDes(iterateConSatDes), mIterateReapplies(iterateReapplies) { |
| 36 |
|
| 37 |
while (!isIteratorValid()) { |
| 38 |
++mItBegin; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
bool CReapplyConceptSaturationLabelSetIterator::isIteratorValid() { |
| 43 |
return isIteratorValid(mIterateConSatDes,mIterateReapplies); |
| 44 |
} |
| 45 |
|
| 46 |
bool CReapplyConceptSaturationLabelSetIterator::isIteratorValid(bool allowConSatDes, bool allowReapplies) { |
| 47 |
if (mItBegin == mItEnd) { |
| 48 |
if (mItAdditionalBegin == mItAdditionalEnd) { |
| 49 |
return true; |
| 50 |
} |
| 51 |
} |
| 52 |
if (mItBegin != mItEnd) { |
| 53 |
const CConceptSaturationDescriptorReapplyData& data = mItBegin.value(); |
| 54 |
if (data.mConSatDes && allowConSatDes) { |
| 55 |
return true; |
| 56 |
} |
| 57 |
if (data.mImpReapplyConSatDes && allowReapplies) { |
| 58 |
return true; |
| 59 |
} |
| 60 |
} else { |
| 61 |
const CConceptSaturationDescriptorReapplyData& data = mItAdditionalBegin.value(); |
| 62 |
if (data.mConSatDes && allowConSatDes) { |
| 63 |
return true; |
| 64 |
} |
| 65 |
if (data.mImpReapplyConSatDes && allowReapplies) { |
| 66 |
return true; |
| 67 |
} |
| 68 |
} |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
cint64 CReapplyConceptSaturationLabelSetIterator::getDataTag() { |
| 75 |
if (mItBegin != mItEnd) { |
| 76 |
cint64 dataTag = mItBegin.key(); |
| 77 |
return dataTag; |
| 78 |
} else { |
| 79 |
cint64 dataTag = mItAdditionalBegin.key(); |
| 80 |
return dataTag; |
| 81 |
} |
| 82 |
//CConceptSaturationDescriptor* conDes = mItBegin.value().mConSatDes; |
| 83 |
//if (conDes) { |
| 84 |
// return conDes->getConceptTag(); |
| 85 |
//} else { |
| 86 |
// return 0; |
| 87 |
//} |
| 88 |
} |
| 89 |
|
| 90 |
CConceptSaturationDescriptor* CReapplyConceptSaturationLabelSetIterator::getConceptSaturationDescriptor() { |
| 91 |
if (mItBegin != mItEnd) { |
| 92 |
return mItBegin.value().mConSatDes; |
| 93 |
} else { |
| 94 |
return mItAdditionalBegin.value().mConSatDes; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
CImplicationReapplyConceptSaturationDescriptor* CReapplyConceptSaturationLabelSetIterator::getImplicationReapplyConceptSaturationDescriptor() { |
| 99 |
if (mItBegin != mItEnd) { |
| 100 |
return mItBegin.value().mImpReapplyConSatDes; |
| 101 |
} else { |
| 102 |
return mItAdditionalBegin.value().mImpReapplyConSatDes; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
bool CReapplyConceptSaturationLabelSetIterator::hasNext() { |
| 108 |
if (mItBegin != mItEnd) { |
| 109 |
return true; |
| 110 |
} else { |
| 111 |
return mItAdditionalBegin != mItAdditionalEnd; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
cint64 CReapplyConceptSaturationLabelSetIterator::next(bool moveToNext) { |
| 116 |
cint64 tag = getDataTag(); |
| 117 |
if (moveToNext) { |
| 118 |
if (mItBegin != mItEnd) { |
| 119 |
++mItBegin; |
| 120 |
} else { |
| 121 |
++mItAdditionalBegin; |
| 122 |
} |
| 123 |
while (!isIteratorValid()) { |
| 124 |
if (mItBegin != mItEnd) { |
| 125 |
++mItBegin; |
| 126 |
} else { |
| 127 |
++mItAdditionalBegin; |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
return tag; |
| 132 |
} |
| 133 |
|
| 134 |
CReapplyConceptSaturationLabelSetIterator* CReapplyConceptSaturationLabelSetIterator::moveNext() { |
| 135 |
if (mItBegin != mItEnd) { |
| 136 |
++mItBegin; |
| 137 |
} else { |
| 138 |
++mItAdditionalBegin; |
| 139 |
} |
| 140 |
while (!isIteratorValid()) { |
| 141 |
if (mItBegin != mItEnd) { |
| 142 |
++mItBegin; |
| 143 |
} else { |
| 144 |
++mItAdditionalBegin; |
| 145 |
} |
| 146 |
} |
| 147 |
return this; |
| 148 |
} |
| 149 |
|
| 150 |
bool CReapplyConceptSaturationLabelSetIterator::operator!=(CReapplyConceptSaturationLabelSetIterator& const_iterator) { |
| 151 |
return mItBegin != const_iterator.mItBegin && mItAdditionalBegin != const_iterator.mItAdditionalBegin; |
| 152 |
} |
| 153 |
|
| 154 |
bool CReapplyConceptSaturationLabelSetIterator::operator==(CReapplyConceptSaturationLabelSetIterator& const_iterator) { |
| 155 |
return mItBegin == const_iterator.mItBegin && mItAdditionalBegin == const_iterator.mItAdditionalBegin; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
}; // end namespace Process |
| 160 |
|
| 161 |
}; // end namespace Kernel |
| 162 |
|
| 163 |
}; // end namespace Reasoner |
| 164 |
|
| 165 |
}; // end namespace Konclude |