std::string Unifier::createEquivalentClass(std::string var) { bool appeared = false; MultimapStr::iterator m_pos; String1Dim new_eq_class; int e_pos; new_eq_class.push_back(var); e_pos = 0; while (e_pos < new_eq_class.size()) { std::string varname = new_eq_class[e_pos]; for (m_pos = unifier.begin(); m_pos != unifier.end(); m_pos++) { std::string fst = m_pos->first; std::string scd = m_pos->second; if ((varname.compare(fst) == 0) && (!gotThisVar(new_eq_class, scd))) { appeared = true; if (!strVar(scd)) { new_eq_class.insert(new_eq_class.begin(), scd); } else { new_eq_class.push_back(scd); } } if ((varname.compare(scd) == 0) && (!gotThisVar(new_eq_class, fst))) { appeared = true; if (!strVar(fst)) { new_eq_class.insert(new_eq_class.begin(), fst); } else { new_eq_class.push_back(fst); } } } e_pos++; } if (appeared) { equivalent_classes.push_back(new_eq_class); return (*new_eq_class.begin()); } return "_"; }
bool Unifier::isConsistent(Unifier& u2) { MultimapStr::iterator u_pos; MultimapStr u2_unifier = u2.unifier; for (u_pos = u2_unifier.begin(); u_pos != u2_unifier.end(); u_pos++) { if ((strVar(u_pos->first) && (!strVar(u_pos->second))) && (!isConsistent(u_pos->first, u_pos->second))) { return false; } } return true; }
double CAdjustStock::calcExpr( const Tree &tree ) { //int num = tree.childNum(); for (int i = 0; i < tree.childNum() ; i++) { const Tree& tmp_tree = tree.child(i) ; calcExpr(tmp_tree); } double calResult=0; //当前节点类型 //cout << "tree type =" << tree->getType(tree) << endl; switch (tree.type()) { case LT_: case GT: case OR: case AND: { double a1=numbers.top(); numbers.pop(); double a2=numbers.top(); numbers.pop(); calResult = OP(tree.type(),a1,a2); break; } case DOUBLE: { numbers.push( ChToInt(tree.text().c_str(), tree.text().length()) ); break; } case VAR: { //取到语法树的变量节点 a,b string strVar( tree.text() ); map<string, double>::iterator iter; iter = m_parseMap.find(strVar); if ( iter != m_parseMap.end() ) { //查找,转换成变量对应的数值 numbers.push( iter->second ); } } default: { break; } } return calResult; }
bool Settings::Check_bool(const String& strSection, const String& strKey, bool& out_bResult, bool& out_bKeyExist) const { if (!strSection.Exists()) { otErr << __FUNCTION__ << ": Error: " << "strSection" << " is Empty!\n"; OT_FAIL; } if (strSection.Compare("")) { otErr << __FUNCTION__ << ": Error: " << "strSection" << " is Blank!\n"; OT_FAIL; } if (!strKey.Exists()) { otErr << __FUNCTION__ << ": Error: " << "strKey" << " is Empty!\n"; OT_FAIL; } if (strKey.Compare("")) { otErr << __FUNCTION__ << ": Error: " << "strKey" << " is Blank!\n"; OT_FAIL; } const char* szVar = pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr); String strVar(szVar); if (strVar.Exists() && (strVar.Compare("false") || strVar.Compare("true"))) { out_bKeyExist = true; if (strVar.Compare("true")) out_bResult = true; else out_bResult = false; } else { out_bKeyExist = false; out_bResult = false; } return true; }
const bool OTSettings::Check_str (const OTString & strSection, const OTString & strKey, OTString & out_strResult, bool & out_bKeyExist) const { if (! strSection.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); } if (strSection.Compare("")) { OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); } if (! strKey.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); } if (strKey.Compare("")) { OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); } const char * szVar = p_iniSimple -> GetValue(strSection.Get(), strKey.Get(),NULL); OTString strVar(szVar); if (strVar.Exists() && !strVar.Compare("")) {out_bKeyExist = true; out_strResult = strVar; } else { out_bKeyExist = false; out_strResult = ""; } return true; }