| 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 "CRepresentativeVariableBindingPathSetData.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Reasoner { |
| 27 |
|
| 28 |
namespace Kernel { |
| 29 |
|
| 30 |
namespace Process { |
| 31 |
|
| 32 |
|
| 33 |
CRepresentativeVariableBindingPathSetData::CRepresentativeVariableBindingPathSetData(CProcessContext* processContext) : CLinkerBase<cint64,CRepresentativeVariableBindingPathSetData>(0),CLocalizationTag(processContext->getUsedProcessTagger()->getCurrentLocalizationTag()) { |
| 34 |
mProcessContext = processContext; |
| 35 |
} |
| 36 |
|
| 37 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::initRepresentativeVariableBindingPathData(CRepresentativeVariableBindingPathSetData* data) { |
| 38 |
if (data) { |
| 39 |
setData(data->getData()); |
| 40 |
mMigratable = data->mMigratable; |
| 41 |
mUseCount = data->mUseCount; |
| 42 |
mShareCount = data->mShareCount; |
| 43 |
mUseMigrateData = data->mUseMigrateData; |
| 44 |
mSigKey.initSignature(&data->mSigKey); |
| 45 |
mUseJoiningHash = data->mUseJoiningHash; |
| 46 |
mLocMigrateData = nullptr; |
| 47 |
mLocJoiningHash = nullptr; |
| 48 |
} else { |
| 49 |
setData(0); |
| 50 |
mMigratable = true; |
| 51 |
mUseMigrateData = nullptr; |
| 52 |
mLocMigrateData = nullptr; |
| 53 |
mUseJoiningHash = nullptr; |
| 54 |
mLocJoiningHash = nullptr; |
| 55 |
mSigKey.initSignature(nullptr); |
| 56 |
mUseCount = 0; |
| 57 |
mShareCount = 0; |
| 58 |
} |
| 59 |
return this; |
| 60 |
} |
| 61 |
|
| 62 |
cint64 CRepresentativeVariableBindingPathSetData::getRepresentativeKey() { |
| 63 |
return mSigKey.getSignatureValue(); |
| 64 |
} |
| 65 |
|
| 66 |
cint64 CRepresentativeVariableBindingPathSetData::getRepresentativeID() { |
| 67 |
return getData(); |
| 68 |
} |
| 69 |
|
| 70 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::setRepresentativeID(cint64 repID) { |
| 71 |
setData(repID); |
| 72 |
return this; |
| 73 |
} |
| 74 |
|
| 75 |
cint64 CRepresentativeVariableBindingPathSetData::getUseCount() { |
| 76 |
return mUseCount; |
| 77 |
} |
| 78 |
|
| 79 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::setUseCount(cint64 useCount) { |
| 80 |
mUseCount = useCount; |
| 81 |
return this; |
| 82 |
} |
| 83 |
|
| 84 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::incUseCount(cint64 incCount) { |
| 85 |
mUseCount += incCount; |
| 86 |
return this; |
| 87 |
} |
| 88 |
|
| 89 |
cint64 CRepresentativeVariableBindingPathSetData::getShareCount() { |
| 90 |
return mShareCount; |
| 91 |
} |
| 92 |
|
| 93 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::setShareCount(cint64 shareCount) { |
| 94 |
mShareCount = shareCount; |
| 95 |
return this; |
| 96 |
} |
| 97 |
|
| 98 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::incShareCount(cint64 incCount) { |
| 99 |
mShareCount += incCount; |
| 100 |
return this; |
| 101 |
} |
| 102 |
|
| 103 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::decShareCount(cint64 decCount) { |
| 104 |
mShareCount -= decCount; |
| 105 |
return this; |
| 106 |
} |
| 107 |
|
| 108 |
bool CRepresentativeVariableBindingPathSetData::isMigratable() { |
| 109 |
return mMigratable; |
| 110 |
} |
| 111 |
|
| 112 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::setMigratable(bool migratable) { |
| 113 |
mMigratable = migratable; |
| 114 |
return this; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
bool CRepresentativeVariableBindingPathSetData::hasMigrateData() { |
| 119 |
return mUseMigrateData != nullptr; |
| 120 |
} |
| 121 |
|
| 122 |
CRepresentativeVariableBindingPathSetData* CRepresentativeVariableBindingPathSetData::addKeySignatureValue(cint64 keySignatureValue) { |
| 123 |
mSigKey.addKey(keySignatureValue); |
| 124 |
return this; |
| 125 |
} |
| 126 |
|
| 127 |
CRepresentativeVariableBindingPathSetDataSignature* CRepresentativeVariableBindingPathSetData::getKeySignature() { |
| 128 |
return &mSigKey; |
| 129 |
} |
| 130 |
|
| 131 |
CRepresentativeVariableBindingPathSetMigrateData* CRepresentativeVariableBindingPathSetData::getMigrateData(bool localizeOrCreate) { |
| 132 |
CRepresentativeVariableBindingPathSetMigrateData* data = nullptr; |
| 133 |
if (!mLocMigrateData && localizeOrCreate) { |
| 134 |
mLocMigrateData = CObjectParameterizingAllocator<CRepresentativeVariableBindingPathSetMigrateData,CProcessContext*>::allocateAndConstructAndParameterize(mProcessContext->getMemoryAllocationManager(),mProcessContext); |
| 135 |
mLocMigrateData->initRepresentativeVariableBindingPathSetMigrateData(mUseMigrateData); |
| 136 |
mUseMigrateData = mLocMigrateData; |
| 137 |
} |
| 138 |
return mUseMigrateData; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
CRepresentativeVariableBindingPathSetMigrateData* CRepresentativeVariableBindingPathSetData::takeMigrateDataFrom(CRepresentativeVariableBindingPathSetData* repData) { |
| 143 |
mLocMigrateData = repData->mUseMigrateData; |
| 144 |
mUseMigrateData = mLocMigrateData; |
| 145 |
mSigKey.initSignature(&repData->mSigKey); |
| 146 |
repData->mUseMigrateData = nullptr; |
| 147 |
repData->mLocMigrateData = nullptr; |
| 148 |
return mUseMigrateData; |
| 149 |
} |
| 150 |
|
| 151 |
CRepresentativeVariableBindingPathSetMigrateData* CRepresentativeVariableBindingPathSetData::copyMigrateDataFrom(CRepresentativeVariableBindingPathSetData* repData) { |
| 152 |
mLocMigrateData = CObjectParameterizingAllocator<CRepresentativeVariableBindingPathSetMigrateData,CProcessContext*>::allocateAndConstructAndParameterize(mProcessContext->getMemoryAllocationManager(),mProcessContext); |
| 153 |
mLocMigrateData->initRepresentativeVariableBindingPathSetMigrateData(repData->mUseMigrateData); |
| 154 |
mSigKey.initSignature(&repData->mSigKey); |
| 155 |
mUseMigrateData = mLocMigrateData; |
| 156 |
return mUseMigrateData; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
CRepresentativeVariableBindingPathSetJoiningHash* CRepresentativeVariableBindingPathSetData::getJoiningHash(bool create) { |
| 161 |
if (create && !mLocJoiningHash) { |
| 162 |
mLocJoiningHash = CObjectParameterizingAllocator< CRepresentativeVariableBindingPathSetJoiningHash,CProcessContext* >::allocateAndConstructAndParameterize(mProcessContext->getUsedMemoryAllocationManager(),mProcessContext); |
| 163 |
mLocJoiningHash->initRepresentativeVariableBindingPathSetJoiningHash(mUseJoiningHash); |
| 164 |
mUseJoiningHash = mLocJoiningHash; |
| 165 |
} |
| 166 |
return mUseJoiningHash; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
bool CRepresentativeVariableBindingPathSetData::hasJoiningData(CConcept* joinConcept) { |
| 171 |
if (!mUseJoiningHash) { |
| 172 |
return false; |
| 173 |
} |
| 174 |
const CRepresentativeVariableBindingPathSetJoiningHashData& joiningData = mUseJoiningHash->value(joinConcept); |
| 175 |
return joiningData.mUseJoiningData != nullptr; |
| 176 |
} |
| 177 |
|
| 178 |
cint64 CRepresentativeVariableBindingPathSetData::getRepresentatedVariableCount() { |
| 179 |
cint64 varCount = 0; |
| 180 |
if (mUseMigrateData) { |
| 181 |
varCount = mUseMigrateData->getRepresentativeVariableBindingPathMap()->count(); |
| 182 |
} |
| 183 |
return varCount; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
}; // end namespace Process |
| 188 |
|
| 189 |
}; // end namespace Kernel |
| 190 |
|
| 191 |
}; // end namespace Reasoner |
| 192 |
|
| 193 |
}; // end namespace Konclude |