Debian Codegraph @

Source/Reasoner/Kernel/Process/CRoleSuccessorLinkIterator.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 "CRoleSuccessorLinkIterator.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32 CRoleSuccessorLinkIterator::CRoleSuccessorLinkIterator()
33 : mLinkLinker(nullptr),mLastLink(nullptr) {
34 mIterator1 = false;
35 mIterator2 = false;
36 }
37
38 CRoleSuccessorLinkIterator::CRoleSuccessorLinkIterator(const CPROCESSHASH<cint64,CIndividualLinkEdge*>::iterator& beginIt, const CPROCESSHASH<cint64,CIndividualLinkEdge*>::iterator& endIt)
39 : mLinkLinker(nullptr),mBeginIt1(beginIt),mEndIt1(endIt),mLastLink(nullptr) {
40 mIterator1 = true;
41 mIterator2 = false;
42 }
43
44 CRoleSuccessorLinkIterator::CRoleSuccessorLinkIterator(const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& beginIt1, const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& endIt1, const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& beginIt2, const CPROCESSHASH<cint64, CIndividualLinkEdge*>::iterator& endIt2)
45 : mLinkLinker(nullptr), mBeginIt1(beginIt1), mEndIt1(endIt1), mBeginIt2(beginIt2), mEndIt2(endIt2), mLastLink(nullptr) {
46 mIterator1 = true;
47 mIterator2 = true;
48 }
49
50
51 CRoleSuccessorLinkIterator::CRoleSuccessorLinkIterator(CIndividualLinkEdge* linkLinker, CIndividualLinkEdge* lastLink)
52 : mLinkLinker(linkLinker),mLastLink(lastLink) {
53 mIterator1 = false;
54 mIterator2 = false;
55 }
56
57
58 bool CRoleSuccessorLinkIterator::hasNext() {
59 return (mLinkLinker && mLinkLinker != mLastLink) || mIterator1 && mBeginIt1 != mEndIt1 || mIterator2 && mBeginIt2 != mEndIt2;
60 }
61
62 CIndividualLinkEdge* CRoleSuccessorLinkIterator::next(bool moveNext) {
63 CIndividualLinkEdge* link = nullptr;
64 if (mLinkLinker) {
65 link = mLinkLinker;
66 if (moveNext) {
67 mLinkLinker = mLinkLinker->getNext();
68 }
69 } else {
70 if (mIterator1 && mBeginIt1 != mEndIt1) {
71 link = mBeginIt1.value();
72 if (moveNext) {
73 ++mBeginIt1;
74 }
75 } else if (mIterator2 && mBeginIt2 != mEndIt2) {
76 link = mBeginIt2.value();
77 if (moveNext) {
78 ++mBeginIt2;
79 }
80 }
81 }
82 return link;
83 }
84
85
86
87 }; // end namespace Process
88
89 }; // end namespace Kernel
90
91 }; // end namespace Reasoner
92
93 }; // end namespace Konclude