Debian Codegraph @

Source/Reasoner/Kernel/Cache/CComputedConsequencesCacheContext.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 "CComputedConsequencesCacheContext.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Cache {
31
32
33 CComputedConsequencesCacheContext::CComputedConsequencesCacheContext() {
34 mMemoryPoolProvider = new CNewAllocationMemoryPoolProvider();
35 mMemMan = new CLimitedReserveMemoryPoolAllocationManager(mMemoryPoolProvider);
36 mAddRelMemory = 0;
37 mConLinker = nullptr;
38 }
39
40
41 CComputedConsequencesCacheContext::~CComputedConsequencesCacheContext() {
42 delete mMemMan;
43 delete mMemoryPoolProvider;
44 }
45
46
47 CMemoryPoolAllocationManager* CComputedConsequencesCacheContext::getMemoryPoolAllocationManager() {
48 return mMemMan;
49 }
50
51
52 CMemoryAllocationManager* CComputedConsequencesCacheContext::getMemoryAllocationManager() {
53 return mMemMan;
54 }
55
56 CMemoryPoolProvider* CComputedConsequencesCacheContext::getMemoryPoolProvider() {
57 return mMemoryPoolProvider;
58 }
59
60 cint64 CComputedConsequencesCacheContext::getMemoryConsumption() {
61 return mAddRelMemory + mMemoryPoolProvider->getAllocatedReleaseDifferencePoolSize();
62 }
63
64 CComputedConsequencesCacheContext* CComputedConsequencesCacheContext::releaseTemporaryMemoryPools(CMemoryPool* memoryPools) {
65 CMemoryPool* memoryPoolIt = memoryPools;
66 while (memoryPoolIt) {
67 mAddRelMemory += memoryPoolIt->getMemoryBlockSize();
68 memoryPoolIt = memoryPoolIt->getNext();
69 }
70 mMemMan->releaseTemporaryMemoryPools(memoryPools);
71 return this;
72 }
73
74
75 CSortedNegLinker<CConcept*>* CComputedConsequencesCacheContext::createConceptLinker(bool create) {
76 CSortedNegLinker<CConcept*>* conLinker = mConLinker;
77 if (!conLinker && create) {
78 conLinker = CObjectAllocator< CSortedNegLinker<CConcept*> >::allocateAndConstruct(mMemMan);
79 }
80 conLinker->setNext(nullptr);
81 if (mConLinker) {
82 mConLinker = mConLinker->getNext();
83 }
84 return conLinker;
85 }
86
87
88 CComputedConsequencesCacheContext* CComputedConsequencesCacheContext::addConceptLinker(CSortedNegLinker<CConcept*>* linker) {
89 if (linker) {
90 linker->setNext(nullptr);
91 linker = linker->append(mConLinker);
92 }
93 return this;
94 }
95
96
97 }; // end namespace Cache
98
99 }; // end namespace Kernel
100
101 }; // end namespace Reasoner
102
103 }; // end namespace Konclude