| 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 "CReapplyQueue.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
|
| 33 |
CReapplyQueue::CReapplyQueue() { |
| 34 |
mStaticReapplyDesLinker = nullptr; |
| 35 |
mDynamicReapplyDesLinker = nullptr; |
| 36 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 37 |
mDesStaticCount = 0; |
| 38 |
mDesDynamicCount = 0; |
| 39 |
#endif |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
CReapplyQueue* CReapplyQueue::initReapplyQueue(CReapplyQueue* prevReapplyQueue) { |
| 45 |
if (prevReapplyQueue) { |
| 46 |
mStaticReapplyDesLinker = prevReapplyQueue->mStaticReapplyDesLinker; |
| 47 |
mDynamicReapplyDesLinker = prevReapplyQueue->mDynamicReapplyDesLinker; |
| 48 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 49 |
mDesDynamicCount = prevReapplyQueue->mDesDynamicCount; |
| 50 |
mDesStaticCount = prevReapplyQueue->mDesStaticCount; |
| 51 |
#endif |
| 52 |
} else { |
| 53 |
mStaticReapplyDesLinker = nullptr; |
| 54 |
mDynamicReapplyDesLinker = nullptr; |
| 55 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 56 |
mDesStaticCount = 0; |
| 57 |
mDesDynamicCount = 0; |
| 58 |
#endif |
| 59 |
} |
| 60 |
return this; |
| 61 |
} |
| 62 |
|
| 63 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 64 |
qint64 CReapplyQueue::getReapplyCount() { |
| 65 |
return mDesStaticCount + mDesDynamicCount; |
| 66 |
} |
| 67 |
#endif |
| 68 |
|
| 69 |
bool CReapplyQueue::isEmpty() { |
| 70 |
return !mDynamicReapplyDesLinker && !mStaticReapplyDesLinker; |
| 71 |
} |
| 72 |
|
| 73 |
bool CReapplyQueue::hasConceptDescriptor(CConceptDescriptor* conceptDescriptor) { |
| 74 |
CReapplyConceptDescriptor* desLinker = mStaticReapplyDesLinker; |
| 75 |
while (desLinker) { |
| 76 |
if (desLinker->hasConceptDescriptor(conceptDescriptor)) { |
| 77 |
return true; |
| 78 |
} |
| 79 |
desLinker = desLinker->getNext(); |
| 80 |
} |
| 81 |
desLinker = mDynamicReapplyDesLinker; |
| 82 |
while (desLinker) { |
| 83 |
if (desLinker->hasConceptDescriptor(conceptDescriptor)) { |
| 84 |
return true; |
| 85 |
} |
| 86 |
desLinker = desLinker->getNext(); |
| 87 |
} |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
CReapplyQueue* CReapplyQueue::addReapplyConceptDescriptor(CReapplyConceptDescriptor *conProDes) { |
| 93 |
if (conProDes) { |
| 94 |
if (conProDes->isStaticDescriptor()) { |
| 95 |
mStaticReapplyDesLinker = conProDes->append(mStaticReapplyDesLinker); |
| 96 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 97 |
++mDesStaticCount; |
| 98 |
#endif |
| 99 |
} else { |
| 100 |
mDynamicReapplyDesLinker = conProDes->append(mDynamicReapplyDesLinker); |
| 101 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 102 |
++mDesDynamicCount; |
| 103 |
#endif |
| 104 |
} |
| 105 |
} |
| 106 |
return this; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
CReapplyQueueIterator CReapplyQueue::getIterator(bool clearDynamicReapplyQueue) { |
| 111 |
CReapplyQueueIterator it(mStaticReapplyDesLinker,mDynamicReapplyDesLinker); |
| 112 |
if (clearDynamicReapplyQueue) { |
| 113 |
mDynamicReapplyDesLinker = nullptr; |
| 114 |
#ifdef KONCLUDE_EMPLOY_REASONER_KERNEL_PROCESS_REAPPLY_QUEUE_COUNT |
| 115 |
mDesDynamicCount = 0; |
| 116 |
#endif |
| 117 |
} |
| 118 |
return it; |
| 119 |
} |
| 120 |
|
| 121 |
}; // end namespace Process |
| 122 |
|
| 123 |
}; // end namespace Kernel |
| 124 |
|
| 125 |
}; // end namespace Reasoner |
| 126 |
|
| 127 |
}; // end namespace Konclude |