/* * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. * * This file is part of the reasoning system Konclude. * For details and support, see . * * Konclude is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU Lesser General Public * License (LGPLv3) as published by the Free Software Foundation. * * Konclude is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU (Lesser) General Public License for more details. * * You should have received a copy of the GNU (Lesser) General Public * License along with Konclude. If not, see . * */ #ifndef KONCLUDE_UTILITIES_CONTAINER_CDYNAMICREFERENCEVECTOR_CPP #define KONCLUDE_UTILITIES_CONTAINER_CDYNAMICREFERENCEVECTOR_CPP #include "CDynamicReferenceVector.h" namespace Konclude { namespace Utilities { namespace Container { template CDynamicReferenceVectorBase::CDynamicReferenceVectorBase(CContext* context) : mContext(context) { clear(); } template CDynamicReferenceVectorBase::~CDynamicReferenceVectorBase() { } template const T CDynamicReferenceVectorBase::getData(cint64 index, const T& defaultValue) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->getData(index,defaultValue); } return defaultValue; } template const T CDynamicReferenceVectorBase::getData(cint64 index, const T& defaultValue, bool* localFlag) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->getData(index,defaultValue,localFlag); } return defaultValue; } template const T CDynamicReferenceVectorBase::getLocalData(cint64 index, const T& defaultValue) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->getLocalData(index,defaultValue); } return defaultValue; } template const T CDynamicReferenceVectorBase::getReferenceData(cint64 index, const T& defaultValue) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->getReferenceData(index,defaultValue); } return defaultValue; } template S* CDynamicReferenceVectorBase::setLocalData(cint64 index, const T& data) { mMaxItem = qMax(index,mMaxItem); if (!mRootBucket) { mRootBucket = CObjectParameterizingAllocator< CDynamicReferenceBucketBase,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mContext),mContext); mRootBucket->initBucket(0,nullptr); mRootBucketDepth = 0; mMaxIndex = 2<= mMaxIndex) { CDynamicReferenceBucketBase* newRootBucket = CObjectParameterizingAllocator< CDynamicReferenceBucketBase,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mContext),mContext); mRootBucketDepth += bucket2Size+1; newRootBucket->initBucket(mRootBucketDepth,nullptr); newRootBucket->installBucket(0,mRootBucket); mRootBucket = newRootBucket; if (mMaxIndex == 0) { mMaxIndex = 2<setLocalData(index,data); return (S*)this; } template S* CDynamicReferenceVectorBase::setData(cint64 index, const T& data) { setLocalData(index,data); return (S*)this; } template bool CDynamicReferenceVectorBase::hasLocalData(cint64 index) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->hasLocalData(index); } return false; } template bool CDynamicReferenceVectorBase::hasData(cint64 index) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->hasData(index); } return false; } template bool CDynamicReferenceVectorBase::hasReferencedData(cint64 index) { if (mRootBucket && index >= 0 && index < mMaxIndex) { return mRootBucket->hasReferencedData(index); } return false; } template S* CDynamicReferenceVectorBase::clear() { mMaxIndex = 0; mRootBucketDepth = 0; mMaxItem = -1; mRootBucket = nullptr; mReferenceVector = nullptr; mReferencedMaxItem = -1; return (S*)this; } template S* CDynamicReferenceVectorBase::referenceVector(CDynamicReferenceVectorBase* refVector) { clear(); mReferenceVector = refVector; if (mReferenceVector && mReferenceVector->mMaxIndex > 0) { mRootBucket = CObjectParameterizingAllocator< CDynamicReferenceBucketBase,CContext* >::allocateAndConstructAndParameterize(CContext::getMemoryAllocationManager(mContext),mContext); mRootBucket->initBucket(refVector->mRootBucketDepth,mReferenceVector->mRootBucket); mRootBucketDepth = refVector->mRootBucketDepth; mMaxIndex = refVector->mMaxIndex; mMaxItem = refVector->mMaxItem; mReferencedMaxItem = refVector->mMaxItem; } return (S*)this; } template cint64 CDynamicReferenceVectorBase::getItemCount() { return mMaxItem+1; } template cint64 CDynamicReferenceVectorBase::getItemMaxIndex() { return mMaxItem; } template cint64 CDynamicReferenceVectorBase::getReferencedItemCount() { return mReferencedMaxItem+1; } template cint64 CDynamicReferenceVectorBase::getReferencedItemMaxIndex() { return mReferencedMaxItem; } }; // end namespace Container }; // end namespace Utilities }; // end namespace Konclude #endif // KONCLUDE_UTILITIES_CONTAINER_CDYNAMICREFERENCEVECTOR_CPP