| 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 "CMBox.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Ontology { |
| 29 |
|
| 30 |
|
| 31 |
CMBox::CMBox(CBoxContext* boxContext) { |
| 32 |
conceptDep = nullptr; |
| 33 |
roleDep = nullptr; |
| 34 |
indiDep = nullptr; |
| 35 |
mConDataVector = nullptr; |
| 36 |
mBranchTriggVector = nullptr; |
| 37 |
mImpRepVector = nullptr; |
| 38 |
mNomSchemaTemplVector = nullptr; |
| 39 |
mValueSpacesTriggers = nullptr; |
| 40 |
|
| 41 |
mBoxContext = boxContext; |
| 42 |
mMemMan = CContext::getMemoryAllocationManager(mBoxContext); |
| 43 |
mDeleteBoxContext = nullptr; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
CMBox::~CMBox() { |
| 48 |
delete mDeleteBoxContext; |
| 49 |
COPADestroyAndRelease(conceptDep,mMemMan); |
| 50 |
COPADestroyAndRelease(roleDep,mMemMan); |
| 51 |
COPADestroyAndRelease(indiDep,mMemMan); |
| 52 |
COPADestroyAndRelease(mConDataVector,mMemMan); |
| 53 |
COPADestroyAndRelease(mBranchTriggVector,mMemMan); |
| 54 |
COPADestroyAndRelease(mImpRepVector,mMemMan); |
| 55 |
COPADestroyAndRelease(mNomSchemaTemplVector,mMemMan); |
| 56 |
COPADestroyAndRelease(mValueSpacesTriggers,mMemMan); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
CConceptDependenceVector *CMBox::getConceptDependenceVector(bool create) { |
| 61 |
if (!conceptDep && create) { |
| 62 |
conceptDep = CObjectParameterizingAllocator<CConceptDependenceVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 63 |
} |
| 64 |
return conceptDep; |
| 65 |
} |
| 66 |
|
| 67 |
CMBox *CMBox::setConceptDependenceVector(CConceptDependenceVector *conceptDependenceVector) { |
| 68 |
COPADestroyAndRelease(conceptDep,mMemMan); |
| 69 |
conceptDep = conceptDependenceVector; |
| 70 |
return this; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
CRoleDependenceVector *CMBox::getRoleDependenceVector(bool create) { |
| 76 |
if (!roleDep && create) { |
| 77 |
roleDep = CObjectParameterizingAllocator<CRoleDependenceVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 78 |
} |
| 79 |
return roleDep; |
| 80 |
} |
| 81 |
|
| 82 |
CMBox *CMBox::setRoleDependenceVector(CRoleDependenceVector *roleDependenceVector) { |
| 83 |
COPADestroyAndRelease(roleDep,mMemMan); |
| 84 |
roleDep = roleDependenceVector; |
| 85 |
return this; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
CIndividualDependenceVector *CMBox::getIndividualDependenceVector(bool create) { |
| 90 |
if (!indiDep && create) { |
| 91 |
indiDep = CObjectParameterizingAllocator<CIndividualDependenceVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 92 |
} |
| 93 |
return indiDep; |
| 94 |
} |
| 95 |
|
| 96 |
CMBox *CMBox::setIndividualDependenceVector(CIndividualDependenceVector *indiDependenceVector) { |
| 97 |
COPADestroyAndRelease(indiDep,mMemMan); |
| 98 |
indiDep = indiDependenceVector; |
| 99 |
return this; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
CMBox *CMBox::getMBoxReferenceCopy(CBoxContext *boxContext) { |
| 105 |
CMBox *mBox = CObjectParameterizingAllocator<CMBox,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(boxContext),boxContext); |
| 106 |
mBox->referenceMBox(this); |
| 107 |
return mBox; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
CConceptDataVector *CMBox::getConceptDataVector(bool create) { |
| 113 |
if (!mConDataVector && create) { |
| 114 |
mConDataVector = CObjectParameterizingAllocator<CConceptDataVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 115 |
} |
| 116 |
return mConDataVector; |
| 117 |
} |
| 118 |
|
| 119 |
CMBox *CMBox::setConceptDataVector(CConceptDataVector *conceptDataVector) { |
| 120 |
COPADestroyAndRelease(mConDataVector,mMemMan); |
| 121 |
mConDataVector = conceptDataVector; |
| 122 |
return this; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
CBranchingTriggerVector *CMBox::getBranchingTriggerVector(bool create) { |
| 127 |
if (!mBranchTriggVector && create) { |
| 128 |
mBranchTriggVector = CObjectParameterizingAllocator<CBranchingTriggerVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 129 |
} |
| 130 |
return mBranchTriggVector; |
| 131 |
} |
| 132 |
|
| 133 |
CMBox *CMBox::setBranchingTriggerVector(CBranchingTriggerVector *branchTriggVector) { |
| 134 |
COPADestroyAndRelease(mBranchTriggVector,mMemMan); |
| 135 |
mBranchTriggVector = branchTriggVector; |
| 136 |
return this; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
CImplicationReplacementVector *CMBox::getImplicationReplacementVector(bool create) { |
| 141 |
if (!mImpRepVector && create) { |
| 142 |
mImpRepVector = CObjectParameterizingAllocator<CImplicationReplacementVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 143 |
} |
| 144 |
return mImpRepVector; |
| 145 |
} |
| 146 |
|
| 147 |
CMBox *CMBox::setImplicationReplacementVector(CImplicationReplacementVector* impRepVector) { |
| 148 |
COPADestroyAndRelease(mImpRepVector,mMemMan); |
| 149 |
mImpRepVector = impRepVector; |
| 150 |
return this; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
CNominalSchemaTemplateVector *CMBox::getNominalSchemaTemplateVector(bool create) { |
| 155 |
if (!mNomSchemaTemplVector && create) { |
| 156 |
mNomSchemaTemplVector = CObjectParameterizingAllocator<CNominalSchemaTemplateVector,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 157 |
} |
| 158 |
return mNomSchemaTemplVector; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
CDatatypeValueSpacesTriggers* CMBox::getValueSpacesTriggers(bool create) { |
| 163 |
if (!mValueSpacesTriggers && create) { |
| 164 |
mValueSpacesTriggers = CObjectParameterizingAllocator<CDatatypeValueSpacesTriggers,CBoxContext*>::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mBoxContext),mBoxContext); |
| 165 |
mValueSpacesTriggers->initValueSpacesTriggers(nullptr); |
| 166 |
} |
| 167 |
return mValueSpacesTriggers; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
CMBox *CMBox::setNominalSchemaTemplateVector(CNominalSchemaTemplateVector* nomSchTemplVector) { |
| 172 |
COPADestroyAndRelease(mNomSchemaTemplVector,mMemMan); |
| 173 |
mNomSchemaTemplVector = nomSchTemplVector; |
| 174 |
return this; |
| 175 |
} |
| 176 |
|
| 177 |
CMBox *CMBox::referenceMBox(CMBox *mBox) { |
| 178 |
if (mBox->conceptDep) { |
| 179 |
getConceptDependenceVector(); |
| 180 |
conceptDep->referenceVector(mBox->conceptDep); |
| 181 |
} else if (conceptDep) { |
| 182 |
conceptDep->clear(); |
| 183 |
} |
| 184 |
if (mBox->roleDep) { |
| 185 |
getRoleDependenceVector(); |
| 186 |
roleDep->referenceVector(mBox->roleDep); |
| 187 |
} else if (roleDep) { |
| 188 |
roleDep->clear(); |
| 189 |
} |
| 190 |
if (mBox->indiDep) { |
| 191 |
getIndividualDependenceVector(); |
| 192 |
indiDep->referenceVector(mBox->indiDep); |
| 193 |
} else if (indiDep) { |
| 194 |
indiDep->clear(); |
| 195 |
} |
| 196 |
if (mBox->mConDataVector) { |
| 197 |
getConceptDataVector(); |
| 198 |
mConDataVector->referenceVector(mBox->mConDataVector); |
| 199 |
} else if (mConDataVector) { |
| 200 |
mConDataVector->clear(); |
| 201 |
} |
| 202 |
if (mBox->mBranchTriggVector) { |
| 203 |
getBranchingTriggerVector(); |
| 204 |
mBranchTriggVector->referenceVector(mBox->mBranchTriggVector); |
| 205 |
} else if (mBranchTriggVector) { |
| 206 |
mBranchTriggVector->clear(); |
| 207 |
} |
| 208 |
if (mBox->mImpRepVector) { |
| 209 |
getImplicationReplacementVector(); |
| 210 |
mImpRepVector->referenceVector(mBox->mImpRepVector); |
| 211 |
} else if (mImpRepVector) { |
| 212 |
mImpRepVector->clear(); |
| 213 |
} |
| 214 |
if (mBox->mNomSchemaTemplVector) { |
| 215 |
getNominalSchemaTemplateVector(); |
| 216 |
mNomSchemaTemplVector->referenceVector(mBox->mNomSchemaTemplVector); |
| 217 |
} else if (mNomSchemaTemplVector) { |
| 218 |
mNomSchemaTemplVector->clear(); |
| 219 |
} |
| 220 |
if (mBox->mValueSpacesTriggers) { |
| 221 |
getValueSpacesTriggers(); |
| 222 |
mValueSpacesTriggers->initValueSpacesTriggers(mBox->mValueSpacesTriggers); |
| 223 |
} else if (mValueSpacesTriggers) { |
| 224 |
mValueSpacesTriggers->initValueSpacesTriggers(nullptr); |
| 225 |
} |
| 226 |
return this; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
CBoxContext *CMBox::getBoxContext(bool create) { |
| 232 |
if (!mBoxContext && create) { |
| 233 |
mBoxContext = new CConcreteOntologyContextBase(); |
| 234 |
mDeleteBoxContext = mBoxContext; |
| 235 |
} |
| 236 |
return mBoxContext; |
| 237 |
} |
| 238 |
|
| 239 |
}; // end namespace Ontology |
| 240 |
|
| 241 |
}; // end namespace Reasoner |
| 242 |
|
| 243 |
}; // end namespace Konclude |