GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cppl/false_reason_printer.cc at master · SSICLOPS/cppl
This repository was archived by the owner on Jan 26, 2021. It is now read-only.
Expand file tree/ Copy pathfalse_reason_printer.ccMore file actions 229 lines (205 loc) · 5.81 KB / Copy pathfalse_reason_printer.ccFile metadata and controls229 lines (205 loc) · 5.81 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 // Copyright 2015-2018 RWTH Aachen University // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "false_reason_printer.hh" #include<queue> void FalseReasonPrinter::print(bool result, vector<PolicyStackProcessorNode> reason){ if (!result){ PolicyStackProcessorNode pspn = reason[1]; while (pspn.type == PolicyStackProcessorNodeType::AND && pspn.reason[1] == 0){ pspn = reason[pspn.reason[0]]; } reasonTree.push_back(pspn); for (uint64_t current = 0; current != reasonTree.size(); ++current){ if (reasonTree[current].type != PolicyStackProcessorNodeType::RELATION){ pspn = reason[reasonTree[current].reason[0]]; while (pspn.type == PolicyStackProcessorNodeType::AND && pspn.reason[1] == 0) pspn = reason[pspn.reason[0]]; reasonTree.push_back(pspn); reasonTree[current].reason[0] = reasonTree.size() - 1; pspn = reason[reasonTree[current].reason[1]]; while (pspn.type == PolicyStackProcessorNodeType::AND && pspn.reason[1] == 0) pspn = reason[pspn.reason[0]]; reasonTree.push_back(pspn); reasonTree[current].reason[1] = reasonTree.size() - 1; } } } } void FalseReasonPrinter::printDNF(){ unsigned long i = 0; if (mDNF.size() == 0) return; while(true){ std::cout<<"( "; set<uint64_t>::iterator it = mDNF[i].begin(); while(true){ std::cout<< _relationToString(*it); ++it; if (it != mDNF[i].end()) std::cout<<" && "; else break; } std::cout<<" )"; ++i; if (i != mDNF.size()) std::cout<<" || "; else break; } std::cout<<std::endl; } string FalseReasonPrinter::printReasonToString(){ stack<PolicyStackProcessorNode> workStack; ostringstream oss; PolicyStackProcessorNode closeParenthesis; closeParenthesis.type = PolicyStackProcessorNodeType::OR; closeParenthesis.reason[0] = -2; //means a ")" should be outputed PolicyStackProcessorNode pspn = reasonTree[0]; while (pspn.type != PolicyStackProcessorNodeType::RELATION){ oss<<"("; workStack.push(closeParenthesis); workStack.push(pspn); pspn = reasonTree[pspn.reason[0]]; } oss<<_relationToString(pspn.reason[0]); while(!workStack.empty()){ pspn = workStack.top(); workStack.pop(); if (pspn.reason[0] == -2){// when the first child id is -2, means ")" should be printed oss<<")"; } else{ if (pspn.type == PolicyStackProcessorNodeType::OR) oss << " OR "; else oss << " AND "; pspn = reasonTree[pspn.reason[1]]; while (pspn.type != PolicyStackProcessorNodeType::RELATION){ oss << "("; workStack.push(closeParenthesis); workStack.push(pspn); pspn = reasonTree[pspn.reason[0]]; } oss<<_relationToString(pspn.reason[0]); } } oss<<endl; return oss.str(); } string FalseReasonPrinter::_relationToString(uint64_t relationId){ string str = ""; vector<int64_t> variableIds = mRelationSet->getRelationVariableIds(relationId); Variable vLHS = mVariableSet->getVariableById(variableIds[0]); RelationSetType type = mRelationSet->getRelationType(relationId); if (vLHS.isFunction()){ if (type == RelationSetType::IS_TRUE){ str += _variableToString(vLHS); } else if (type == RelationSetType::IS_FALSE){ str += "!" + _variableToString(vLHS); } } else{ str += _variableToString(vLHS) + _relationTypeToString(type); if (variableIds[1] >= 0){ Variable vRHS = mVariableSet->getVariableById(variableIds[1]); str += _variableToString(vRHS); } } return str; } string FalseReasonPrinter::_relationTypeToString(RelationSetType t){ string str = ""; switch(t){ case RelationSetType::EQUAL: str = "="; break; case RelationSetType::NEQ: str = "!="; break; case RelationSetType::GEQ: str = ">="; break; case RelationSetType::LEQ: str = "<="; break; case RelationSetType::GREATER: str = ">"; break; case RelationSetType::LESS: str = "<"; break; case RelationSetType::IS_TRUE: str = "=true"; break; case RelationSetType::IS_FALSE: str = "=false"; break; case RelationSetType::END: break; }; return str; } string FalseReasonPrinter::_variableToString(Variable v, string str_surrounding){ //string str; ostringstream oss; if (v.isReference()){ oss<< mPolicyDefinition->getIdName(v.idInPolicyDef); if (v.isFunction()){ oss<< "( " << _variableToString(v.funcParams->at(0), str_surrounding); for (vector<Variable>::iterator it = v.funcParams->begin() + 1; it != v.funcParams->end(); ++it){ oss << ", " << _variableToString(*it, str_surrounding); } oss<< " )"; } } else { switch (v.type){ case VariableSetType::STRING: oss<< str_surrounding <<*(v.value.asString)<< str_surrounding; break; case VariableSetType::BOOLEAN: if (v.value.asBoolean) oss<< "true"; else oss<< "false"; break; //ENUM_VALUE not used case VariableSetType::INT8: //uint8_t is defined as char. print directly will meet problem. oss<< (int)(v.value.asInt8); break; case VariableSetType::INT16: oss<< v.value.asInt16; break; case VariableSetType::INT32: oss<< v.value.asInt32; break; case VariableSetType::UINT8: //uint8_t is defined as char. print directly will meet problem. oss<< (unsigned int)(v.value.asUInt8); break; case VariableSetType::UINT16: oss<< v.value.asUInt16; break; case VariableSetType::UINT32: oss<< v.value.asUInt32; break; default: break; } } return oss.str(); } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |