Debian Codegraph @

Source/Reasoner/Ontology/CActiveEntityCountVector.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 "CActiveEntityCountVector.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Ontology {
29
30
31 CActiveEntityCountVector::CActiveEntityCountVector(CContext* context) {
32 mContext = context;
33 mCountVector = nullptr;
34 mVectorSize = 0;
35 }
36
37
38 CActiveEntityCountVector* CActiveEntityCountVector::initActiveEntityCountVector(CActiveEntityCountVector* vector) {
39 mVectorSize = 0;
40 mCountVector = nullptr;
41 if (vector) {
42 increaseVectorSize(vector->getVectorSize());
43 for (cint64 i = 0; i < vector->mVectorSize; ++i) {
44 mCountVector[i] = vector->mCountVector[i];
45 }
46 }
47 return this;
48 }
49
50
51 CActiveEntityCountVector* CActiveEntityCountVector::incActiveEntityCount(CExpressionEntity* entity, cint64 incCount) {
52 CActiveEntityCountItem* item = getActiveEntityCountItem(entity);
53 if (item) {
54 item->incActiveCount(incCount);
55 }
56 return this;
57 }
58
59 CActiveEntityCountVector* CActiveEntityCountVector::decActiveEntityCount(CExpressionEntity* entity, cint64 decCount) {
60 CActiveEntityCountItem* item = getActiveEntityCountItem(entity);
61 if (item) {
62 item->decActiveCount(decCount);
63 }
64 return this;
65 }
66
67 CActiveEntityCountItem* CActiveEntityCountVector::getActiveEntityCountItem(CExpressionEntity* entity) {
68 if (entity) {
69 cint64 itemID = entity->getEntityID();
70 if (itemID < mVectorSize) {
71 CActiveEntityCountItem* item = &mCountVector[itemID];
72 item->setEntity(entity);
73 return item;
74 }
75 }
76 return nullptr;
77 }
78
79 bool CActiveEntityCountVector::increaseVectorSize(cint64 newSize) {
80 if (newSize > mVectorSize) {
81 CActiveEntityCountItem* tmpCountVector = CObjectAllocator<CActiveEntityCountItem>::allocateAndConstructArray(mContext->getMemoryAllocationManager(),newSize);
82 if (mCountVector) {
83 for (cint64 i = 0; i < mVectorSize; ++i) {
84 tmpCountVector[i] = mCountVector[i];
85 }
86 CObjectAllocator<CActiveEntityCountItem>::destroyAndReleaseArray(mCountVector,mContext->getMemoryAllocationManager());
87 }
88 mCountVector = tmpCountVector;
89 mVectorSize = newSize;
90 return true;
91 }
92 return false;
93 }
94
95 cint64 CActiveEntityCountVector::getVectorSize() {
96 return mVectorSize;
97 }
98
99 CActiveEntityCountVector* CActiveEntityCountVector::clearActiveEntityCount() {
100 for (cint64 i = 0; i < mVectorSize; ++i) {
101 mCountVector[i].setActiveCount(0);
102 }
103 return this;
104 }
105
106
107 CActiveEntityIterator CActiveEntityCountVector::getActiveEntityIterator() {
108 return CActiveEntityIterator(mCountVector,mVectorSize);
109 }
110
111
112 }; // end namespace Ontology
113
114 }; // end namespace Reasoner
115
116 }; // end namespace Konclude