Debian Codegraph @

Source/Parser/Expressions/CListVariableAssociator.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 "CListVariableAssociator.h"
22
23
24 namespace Konclude {
25
26 namespace Parser {
27
28 namespace Expression {
29
30
31 CListVariableAssociator::CListVariableAssociator(CExpressionVariable *variable1, CExpressionVariable *variable2, CExpressionVariable *variable3) {
32 if (variable1) {
33 mVariableList.append(variable1);
34 }
35 if (variable2) {
36 mVariableList.append(variable2);
37 }
38 if (variable3) {
39 mVariableList.append(variable3);
40 }
41 }
42
43 CListVariableAssociator::CListVariableAssociator(const CEXPRESSIONLIST<CExpressionVariable*>& variableList) : mVariableList(variableList) {
44 }
45
46 CListVariableAssociator::CListVariableAssociator(CEXPRESSIONLIST<CExpressionVariable*>* variableList) : mVariableList(*variableList) {
47 }
48
49
50 CListVariableAssociator* CListVariableAssociator::initExpressionAssociator(CExpressionVariable *variable1, CExpressionVariable *variable2, CExpressionVariable *variable3) {
51 if (variable1) {
52 if (mVariableList.isEmpty()) {
53 mVariableList.append(variable1);
54 } else {
55 mVariableList.replace(0,variable1);
56 }
57
58 if (variable2) {
59 if (mVariableList.size() < 2) {
60 mVariableList.append(variable2);
61 } else {
62 mVariableList.replace(1,variable2);
63 }
64
65 if (variable3) {
66 if (mVariableList.size() < 3) {
67 mVariableList.append(variable3);
68 } else {
69 mVariableList.replace(2,variable3);
70 }
71 } else {
72 while (mVariableList.size() > 2) {
73 mVariableList.removeLast();
74 }
75 }
76
77 } else {
78 while (mVariableList.size() > 1) {
79 mVariableList.removeLast();
80 }
81 }
82
83 } else {
84 mVariableList.clear();
85 }
86 return this;
87 }
88
89
90 CEXPRESSIONLIST<CExpressionVariable*>* CListVariableAssociator::getVariableList() {
91 return &mVariableList;
92 }
93
94 const CEXPRESSIONLIST<CExpressionVariable*>* CListVariableAssociator::getConstVariableList() const {
95 return &mVariableList;
96 }
97
98
99 cint64 CListVariableAssociator::getVariableCount() {
100 return mVariableList.count();
101 }
102
103 cint64 CListVariableAssociator::getStructuralHashValue() {
104 cint64 hashValue = 0;
105 cint64 tmpValue1 = 0;
106 cint64 tmpValue2 = 1;
107 FOREACHIT (CExpressionVariable* variable, mVariableList) {
108 tmpValue1 += cint64(variable);
109 tmpValue2 *= cint64(variable);
110 }
111 hashValue = tmpValue1+tmpValue2;
112 return hashValue;
113 }
114
115 bool CListVariableAssociator::compareStructuralEquivalence(const CListVariableAssociator& listExpressionAssociator) {
116 if (mVariableList.count() != listExpressionAssociator.mVariableList.count()) {
117 return false;
118 }
119 FOREACHIT (CExpressionVariable* variable, mVariableList) {
120 cint64 containedCount = listExpressionAssociator.mVariableList.count(variable);
121 if (containedCount <= 0) {
122 return false;
123 } else if (containedCount > 1) {
124 if (mVariableList.count(variable) != containedCount) {
125 return false;
126 }
127 }
128 }
129 return true;
130 }
131
132
133
134 }; // end namespace Expression
135
136 }; // end namespace Parser
137
138 }; // end namespace Konclude