Debian Codegraph @

Source/Reasoner/Kernel/Process/CDatatypeValueSpaceValuesCounter.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 "CDatatypeValueSpaceValuesCounter.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Process {
31
32
33 CDatatypeValueSpaceValuesCounter::CDatatypeValueSpaceValuesCounter() {
34 initValueCounter((cint64)0);
35 }
36
37 CDatatypeValueSpaceValuesCounter* CDatatypeValueSpaceValuesCounter::initValueCounter(cint64 valueCount) {
38 mValueCount = valueCount;
39 mInfinite = false;
40 return this;
41 }
42
43
44 CDatatypeValueSpaceValuesCounter* CDatatypeValueSpaceValuesCounter::resetValueCounter() {
45 initValueCounter((cint64)0);
46 return this;
47 }
48
49
50 CDatatypeValueSpaceValuesCounter* CDatatypeValueSpaceValuesCounter::initValueCounter(CDatatypeValueSpaceValuesCounter* valueCounter) {
51 mValueCount = valueCounter->mValueCount;
52 mInfinite = valueCounter->mInfinite;
53 return this;
54 }
55
56
57 bool CDatatypeValueSpaceValuesCounter::incValueCount(cint64 incCount) {
58 if (!mInfinite) {
59 mValueCount += incCount;
60 return true;
61 }
62 return false;
63 }
64
65 bool CDatatypeValueSpaceValuesCounter::incInfinite() {
66 if (!mInfinite) {
67 mInfinite = true;
68 return true;
69 }
70 return false;
71 }
72
73 bool CDatatypeValueSpaceValuesCounter::isInfinite() {
74 return mInfinite;
75 }
76
77 cint64 CDatatypeValueSpaceValuesCounter::getValueCount() {
78 return mValueCount;
79 }
80
81 CDatatypeValueSpaceValuesCounter::VALUES_COUNTER_TYPE CDatatypeValueSpaceValuesCounter::getCounterType() {
82 return VCT_VALUE_COUNTER;
83 }
84
85
86 bool CDatatypeValueSpaceValuesCounter::hasValueAchieved(cint64 value) {
87 if (mInfinite) {
88 return true;
89 }
90 return mValueCount >= value;
91 }
92
93
94 bool CDatatypeValueSpaceValuesCounter::combineWithValueCounter(CDatatypeValueSpaceValuesCounter* counter, cint64 additionalDiff) {
95 if (counter->isInfinite()) {
96 return incInfinite();
97 } else {
98 cint64 otherValueCount = counter->getValueCount() - additionalDiff;
99 if (otherValueCount > 0) {
100 return incValueCount(otherValueCount);
101 }
102 return false;
103 }
104 }
105
106
107
108 }; // end namespace Process
109
110 }; // end namespace Kernel
111
112 }; // end namespace Reasoner
113
114 }; // end namespace Konclude