Debian Codegraph @

Source/Reasoner/Kernel/Process/CDisjointSuccessorRoleHash.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 "CDisjointSuccessorRoleHash.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33 CDisjointSuccessorRoleHash::CDisjointSuccessorRoleHash(CProcessContext* context) : mSuccNegDisEdgeHash(context),mContext(context) {
34 }
35
36 CDisjointSuccessorRoleHash::~CDisjointSuccessorRoleHash() {
37 }
38
39 CDisjointSuccessorRoleHash* CDisjointSuccessorRoleHash::initDisjointSuccessorRoleHash(CDisjointSuccessorRoleHash* prevDisjRoleHash) {
40 if (prevDisjRoleHash) {
41 mSuccNegDisEdgeHash = prevDisjRoleHash->mSuccNegDisEdgeHash;
42 } else {
43 mSuccNegDisEdgeHash.clear();
44 }
45 return this;
46 }
47
48
49 CPROCESSHASH<CRole*,CNegationDisjointEdge*>* CDisjointSuccessorRoleHash::getNegDisRoleHash(cint64 successor, bool located) {
50 if (!located) {
51 CDisjointSuccessorRoleData* data = nullptr;
52 if (mSuccNegDisEdgeHash.tryGetValuePointer(successor,data)) {
53 return data->mUseNegDisSet;
54 }
55 return nullptr;
56 } else {
57 CDisjointSuccessorRoleData& data = mSuccNegDisEdgeHash[successor];
58 if (!data.mLocNegDisSet) {
59 CPROCESSHASH<CRole*,CNegationDisjointEdge*>* newNegDisSet = CObjectParameterizingAllocator< CPROCESSHASH<CRole*,CNegationDisjointEdge*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mContext),mContext);
60 data.mLocNegDisSet = newNegDisSet;
61 data.mUseNegDisSet = newNegDisSet;
62 }
63 return data.mUseNegDisSet;
64 }
65 }
66
67
68 CDisjointSuccessorRoleHash* CDisjointSuccessorRoleHash::insertDisjointSuccessorRoleLink(cint64 succIndi, CNegationDisjointEdge* link) {
69 getNegDisRoleHash(succIndi,true)->insert(link->getLinkRole(),link);
70 return this;
71 }
72
73
74 bool CDisjointSuccessorRoleHash::hasDisjointSuccessorRoleLink(cint64 succIndi, CRole* role) {
75 CPROCESSHASH<CRole*,CNegationDisjointEdge*>* dataHash = getNegDisRoleHash(succIndi,false);
76 if (dataHash) {
77 return dataHash->contains(role);
78 }
79 return false;
80 }
81
82
83
84 CNegationDisjointEdge* CDisjointSuccessorRoleHash::getDisjointSuccessorRoleLink(cint64 succIndi, CRole* role) {
85 CNegationDisjointEdge* link = nullptr;
86 CPROCESSHASH<CRole*,CNegationDisjointEdge*>* dataHash = getNegDisRoleHash(succIndi,false);
87 if (dataHash) {
88 link = dataHash->value(role,nullptr);
89 }
90 return link;
91 }
92
93
94 CDisjointSuccessorRoleHash* CDisjointSuccessorRoleHash::removeDisjointSuccessorRoleLinks(cint64 succIndi) {
95 mSuccNegDisEdgeHash.remove(succIndi);
96 return this;
97 }
98
99
100 CDisjointSuccessorRoleIterator CDisjointSuccessorRoleHash::getDisjointRoleIterator(cint64 succIndi) {
101 CPROCESSHASH<CRole*,CNegationDisjointEdge*>* dataHash = getNegDisRoleHash(succIndi,false);
102 if (dataHash) {
103 return CDisjointSuccessorRoleIterator(succIndi,dataHash->begin(),dataHash->end());
104 }
105 return CDisjointSuccessorRoleIterator();
106 }
107
108
109 }; // end namespace Process
110
111 }; // end namespace Kernel
112
113 }; // end namespace Reasoner
114
115 }; // end namespace Konclude