Debian Codegraph @

Source/Reasoner/Ontology/CRBox.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 "CRBox.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Ontology {
29
30
31 CRBox::CRBox(CBoxContext* boxContext) {
32 mBoxContext = boxContext;
33 mMemMan = CContext::getMemoryAllocationManager(mBoxContext);
34 roles = nullptr;
35 mRoleChainVec = nullptr;
36 mDeleteBoxContext = nullptr;
37
38 mActiveRoleSet = nullptr;
39
40 mBottomObjectRoleTag = 0;
41 mTopObjectRoleTag = 1;
42
43 mBottomDataRoleTag = 2;
44 mTopDataRoleTag = 3;
45 }
46
47
48 CRBox::~CRBox() {
49 delete mDeleteBoxContext;
50 COPADestroyAndRelease(roles,mMemMan);
51 COPADestroyAndRelease(mRoleChainVec,mMemMan);
52 COPADestroyAndRelease(mActiveRoleSet,mMemMan);
53 }
54
55
56 CRBox *CRBox::setRoleVector(CRoleVector* roleVec) {
57 COPADestroyAndRelease(roles,mMemMan);
58 roles = roleVec;
59 return this;
60 }
61
62 CRoleVector* CRBox::getRoleVector(bool create) {
63 if (!roles && create) {
64 roles = CObjectParameterizingAllocator<CRoleVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext);
65 }
66 return roles;
67 }
68
69 CRBox *CRBox::setRoleChainVector(CRoleChainVector* roleChainVec) {
70 COPADestroyAndRelease(mRoleChainVec,mMemMan);
71 mRoleChainVec = roleChainVec;
72 return this;
73 }
74
75 CRoleChainVector* CRBox::getRoleChainVector(bool create) {
76 if (!mRoleChainVec && create) {
77 mRoleChainVec = CObjectParameterizingAllocator<CRoleChainVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext);
78 }
79 return mRoleChainVec;
80 }
81
82 qint64 CRBox::getRoleCount() {
83 cint64 roleCount = 0;
84 if (roles) {
85 roleCount = roles->getItemCount();
86 }
87 return roleCount;
88 }
89
90 qint64 CRBox::getRoleChainCount() {
91 cint64 roleChainCount = 0;
92 if (mRoleChainVec) {
93 roleChainCount = mRoleChainVec->getItemCount();
94 }
95 return roleChainCount;
96 }
97
98
99 CRBox *CRBox::getRBoxReferenceCopy(CBoxContext *boxContext) {
100 CRBox *rBox = CObjectParameterizingAllocator<CRBox,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(boxContext),boxContext);
101 rBox->referenceRBox(this);
102 return rBox;
103 }
104
105
106 CRBox *CRBox::referenceRBox(CRBox *rBox) {
107 if (rBox->roles) {
108 getRoleVector();
109 roles->referenceVector(rBox->roles);
110 } else if (roles) {
111 roles->clear();
112 }
113 if (rBox->mRoleChainVec) {
114 getRoleChainVector();
115 mRoleChainVec->referenceVector(rBox->mRoleChainVec);
116 } else if (mRoleChainVec) {
117 mRoleChainVec->clear();
118 }
119 if (rBox->mActiveRoleSet) {
120 if (!mActiveRoleSet) {
121 mActiveRoleSet = CObjectParameterizingAllocator< CBOXSET<CRole*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext);
122 }
123 mActiveRoleSet->init(rBox->mActiveRoleSet,mBoxContext);
124 } else if (mActiveRoleSet) {
125 mActiveRoleSet->clear();
126 }
127
128 return this;
129 }
130
131
132 CBoxContext *CRBox::getBoxContext(bool create) {
133 if (!mBoxContext && create) {
134 mBoxContext = new CConcreteOntologyContextBase();
135 mDeleteBoxContext = mBoxContext;
136 }
137 return mBoxContext;
138 }
139
140
141
142 CRole* CRBox::getTopObjectRole() {
143 CRole* role = nullptr;
144 if (roles) {
145 role = roles->getData(mTopObjectRoleTag);
146 }
147 return role;
148 }
149
150 CRBox* CRBox::setTopObjectRole(CRole* role) {
151 getRoleVector()->setData(mTopObjectRoleTag,role);
152 return this;
153 }
154
155 CRole* CRBox::getBottomObjectRole() {
156 CRole* role = nullptr;
157 if (roles) {
158 role = roles->getData(mBottomObjectRoleTag);
159 }
160 return role;
161 }
162
163 CRBox* CRBox::setBottomObjectRole(CRole* role) {
164 getRoleVector()->setData(mBottomObjectRoleTag,role);
165 return this;
166 }
167
168
169 cint64 CRBox::getTopObjectRoleIndex() {
170 return mTopObjectRoleTag;
171 }
172
173 cint64 CRBox::getBottomObjectRoleIndex() {
174 return mBottomObjectRoleTag;
175 }
176
177
178
179
180
181 CRole* CRBox::getTopDataRole() {
182 CRole* role = nullptr;
183 if (roles) {
184 role = roles->getData(mTopDataRoleTag);
185 }
186 return role;
187 }
188
189 CRBox* CRBox::setTopDataRole(CRole* role) {
190 getRoleVector()->setData(mTopDataRoleTag,role);
191 return this;
192 }
193
194 CRole* CRBox::getBottomDataRole() {
195 CRole* role = nullptr;
196 if (roles) {
197 role = roles->getData(mBottomDataRoleTag);
198 }
199 return role;
200 }
201
202 CRBox* CRBox::setBottomDataRole(CRole* role) {
203 getRoleVector()->setData(mBottomDataRoleTag,role);
204 return this;
205 }
206
207
208 cint64 CRBox::getTopDataRoleIndex() {
209 return mTopDataRoleTag;
210 }
211
212 cint64 CRBox::getBottomDataRoleIndex() {
213 return mBottomDataRoleTag;
214 }
215
216
217
218 CBOXSET<CRole*>* CRBox::getActivePropertyRoleSet(bool create) {
219 if (!mActiveRoleSet && create) {
220 mActiveRoleSet = CObjectParameterizingAllocator< CBOXSET<CRole*>,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext);
221 }
222 return mActiveRoleSet;
223 }
224
225 CRBox* CRBox::setActivePropertyRoleSet(CBOXSET<CRole*>* takeActiveRoleSet) {
226 COPADestroyAndRelease(mActiveRoleSet,mMemMan);
227 mActiveRoleSet = takeActiveRoleSet;
228 return this;
229 }
230
231
232 }; // end namespace Ontology
233
234 }; // end namespace Reasoner
235
236 }; // end namespace Konclude