// ------------------------------------------------------------------------- int GraphDefinition::multi_dijkstra( edge_t *edges, size_t edge_count, std::vector<int> vertices, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg, std::vector<PDVI> &ruleList) { construct_graph(edges, edge_count, has_reverse_cost, directed); if (ruleList.size() > 0) { m_ruleTable.clear(); LongVector vecsource; for (const auto &rule : ruleList) { std::vector<long> temp_precedencelist; temp_precedencelist.clear(); for (auto const &seq : rule.second) { temp_precedencelist.push_back(seq); } long dest_edge_id = rule.second[0]; if (m_ruleTable.find(dest_edge_id) != m_ruleTable.end()) { m_ruleTable[dest_edge_id].push_back(Rule(rule.first, temp_precedencelist)); } else { std::vector<Rule> temprules; temprules.clear(); temprules.push_back(Rule(rule.first, temp_precedencelist)); m_ruleTable.insert(std::make_pair(dest_edge_id, temprules)); } } m_bIsturnRestrictOn = true; } parent = new PARENT_PATH[edge_count + 1]; m_dCost = new CostHolder[edge_count + 1]; m_vecPath.clear(); size_t i; size_t total_vertices = vertices.size(); for (i = 0; i < total_vertices - 1; i++) { int ret = my_dijkstra(vertices[i], vertices[i + 1], edge_count, err_msg); if (ret < 0) { deleteall(); return -1; } } *path = (path_element_tt *) malloc(sizeof(path_element_tt) * (m_vecPath.size() + 1)); *path_count = static_cast<int>(m_vecPath.size()); for (size_t i = 0; i < *path_count; i++) { (*path)[i].vertex_id = m_vecPath[i].vertex_id; (*path)[i].edge_id = m_vecPath[i].edge_id; (*path)[i].cost = m_vecPath[i].cost; } deleteall(); return 0; }
// ------------------------------------------------------------------------- int GraphDefinition:: my_dijkstra(edge_t *edges, size_t edge_count, long start_vertex, long end_vertex, bool directed, bool has_reverse_cost, path_element_tt **path, size_t *path_count, char **err_msg, std::vector<PDVI> &ruleList) { m_ruleTable.clear(); LongVector vecsource; for (const auto &rule : ruleList) { size_t j; size_t seq_cnt = rule.second.size(); std::vector<long> temp_precedencelist; temp_precedencelist.clear(); for (j = 1; j < seq_cnt; j++) { temp_precedencelist.push_back(rule.second[j]); } long dest_edge_id = rule.second[0]; if (m_ruleTable.find(dest_edge_id) != m_ruleTable.end()) { m_ruleTable[dest_edge_id].push_back(Rule(rule.first, temp_precedencelist)); } else { std::vector<Rule> temprules; temprules.clear(); temprules.push_back(Rule(rule.first, temp_precedencelist)); m_ruleTable.insert(std::make_pair(dest_edge_id, temprules)); } if (isStartVirtual) { if (seq_cnt == 2 && rule.second[1] == m_lStartEdgeId) { vecsource = m_mapNodeId2Edge[start_vertex]; for (const auto &source : vecsource) { temp_precedencelist.clear(); temp_precedencelist.push_back( m_vecEdgeVector[source]->m_lEdgeID); m_ruleTable[dest_edge_id].push_back(Rule(rule.first, temp_precedencelist)); } } } } if (isEndVirtual) { if (m_ruleTable.find(m_lEndEdgeId) != m_ruleTable.end()) { std::vector<Rule> tmpRules = m_ruleTable[m_lEndEdgeId]; vecsource = m_mapNodeId2Edge[end_vertex]; for (const auto &source : vecsource) { m_ruleTable.insert(std::make_pair( m_vecEdgeVector[source]->m_lEdgeID, tmpRules)); } } } m_bIsturnRestrictOn = true; return(my_dijkstra(edges, edge_count, start_vertex, end_vertex, directed, has_reverse_cost, path, path_count, err_msg)); }
std::list<Rule> Proxy::parseRuleString(const char** ruleString) { std::list<Rule> rules; bool inString = false, inAlias = false; std::string name; std::list<std::string> path; bool visible = false; const char* iter = NULL; for (iter = *ruleString; *iter && (*iter != '}' || inString || inAlias); iter++) { if (!inString && *iter == '+') visible = true; else if (!inString && *iter == '-') visible = false; else if (*iter == '\'' && iter[1] != '\''){ inString = !inString; if (iter[1] != '/') { if (!inString){ if (inAlias) rules.back().outputName = name; else { path.push_back(name); rules.push_back(Rule(Rule::NORMAL, path, visible)); path.clear(); } inAlias = false; } name = ""; } } else if (!inString && *iter == '*') { rules.push_back(Rule(Rule::OTHER_ENTRIES_PLACEHOLDER, path, "*", visible)); path.clear(); } else if (inString){ name += *iter; if (*iter == '\'') iter++; } else if (!inString && *iter == 'a' && *++iter == 's') inAlias = true; else if (!inString && !inAlias && *iter == '/'){ path.push_back(name); name = ""; } else if (!inString && !inAlias && *iter == '{'){ iter++; rules.back().subRules = Proxy::parseRuleString(&iter); } } *ruleString = iter; return rules; }
void TCopyParamList::Load(THierarchicalStorage * Storage, intptr_t ACount) { for (intptr_t Index = 0; Index < ACount; ++Index) { UnicodeString Name = ::IntToStr(Index); std::unique_ptr<TCopyParamRule> Rule(nullptr); std::unique_ptr<TCopyParamType> CopyParam(new TCopyParamType()); if (Storage->OpenSubKey(Name, false)) { SCOPE_EXIT { Storage->CloseSubKey(); }; Name = Storage->ReadString("Name", Name); CopyParam->Load(Storage); if (Storage->ReadBool("HasRule", false)) { Rule.reset(new TCopyParamRule()); Rule->Load(Storage); } } FCopyParams->Add(CopyParam.release()); FRules->Add(Rule.release()); FNames->Add(Name); }
void Proxy::sync_expand() { assert(this->dataSource != NULL); for (std::list<std::list<std::string> >::iterator oepPathIter = this->__idPathList_OtherEntriesPlaceHolders.begin(); oepPathIter != this->__idPathList_OtherEntriesPlaceHolders.end(); oepPathIter++) { std::list<Entry>* dataSource = this->dataSource->getListByPath(*oepPathIter); if (dataSource) { Rule* oep = this->getPlaceholderBySourceList(*dataSource, this->rules); assert(oep != NULL); Rule* parentRule = this->getParentRule(oep); std::list<Rule>& dataTarget = parentRule ? parentRule->subRules : this->rules; std::list<Rule>::iterator dataTargetIter = dataTarget.begin(); while (dataTargetIter != dataTarget.end() && (dataTargetIter->type != Rule::OTHER_ENTRIES_PLACEHOLDER || dataTargetIter->__idpath != *oepPathIter)){ dataTargetIter++; } std::list<Rule> newRules; for (std::list<Entry>::iterator iter = dataSource->begin(); iter != dataSource->end(); iter++){ Rule* relatedRule = this->getRuleByEntry(*iter, this->rules, Rule::NORMAL); if (!relatedRule){ newRules.push_back(Rule(*iter, dataTargetIter->isVisible, *this->dataSource, this->__idPathList, this->dataSource->buildPath(*iter))); } } dataTargetIter++; dataTarget.splice(dataTargetIter, newRules); } } }
Rule::Rule(Entry& source, bool isVisible, EntryPathFollower& pathFollower, std::list<std::list<std::string> > const& pathesToIgnore, std::list<std::string> const& currentPath) : type(Rule::NORMAL), isVisible(isVisible), __idpath(currentPath), outputName(source.name), dataSource(&source) { if (source.type == Entry::SUBMENU) { Rule placeholder(Rule::OTHER_ENTRIES_PLACEHOLDER, currentPath, "*", true); placeholder.dataSource = pathFollower.getEntryByPath(currentPath); placeholder.dataSource_list = pathFollower.getListByPath(currentPath); this->subRules.push_front(placeholder); } for (std::list<Entry>::iterator iter = source.subEntries.begin(); iter != source.subEntries.end(); iter++) { std::list<std::string> currentPath_in_loop = currentPath; currentPath_in_loop.push_back(iter->name); bool currentPath_in_loop_is_blacklisted = false; for (std::list<std::list<std::string> >::const_iterator pti_iter = pathesToIgnore.begin(); pti_iter != pathesToIgnore.end(); pti_iter++) { if (*pti_iter == currentPath_in_loop) { currentPath_in_loop_is_blacklisted = true; break; } } if (!currentPath_in_loop_is_blacklisted){ this->subRules.push_back(Rule(*iter, isVisible, pathFollower, pathesToIgnore, currentPath_in_loop)); } } }
void Iteration::addRule(std::vector<std::string> data, std::string rec_id) { std::string strTemp = data[4] + data[3] + data[2]; if (data[0].at(0) == 't') { if (rul_rec_map.find(strTemp) != rul_rec_map.end()) { std::shared_ptr<Rule> rul_rec = rul_rec_map[strTemp]; rul_rec->setRuntime(std::stod(data[5]) + rul_rec->getRuntime()); } else { std::shared_ptr<Rule> rul_rec = std::make_shared<Rule>(Rule(data[4], std::stoi(data[2]), rec_id)); rul_rec->setRuntime(std::stod(data[5])); rul_rec->setLocator(data[3]); rul_rec_map[strTemp] = rul_rec; } } else if (data[0].at(0) == 'n') { std::unordered_map<std::string, std::shared_ptr<Rule>>::const_iterator got = rul_rec_map.find(strTemp); assert(got != rul_rec_map.end() && "missing t tag"); std::shared_ptr<Rule> rul_rec = rul_rec_map[strTemp]; rul_rec->setNum_tuples(std::stol(data[5]) - prev_num_tuples); this->prev_num_tuples = std::stol(data[5]); rul_rec_map[strTemp] = rul_rec; } }
Rule Rule::createDefaultRule() { Rule r = Rule(); r.setRuleId(DEFAULT_RULE_ID); r.setRuleName("Default rule"); return r; }
void Simulation::setupRules(json_spirit::Array &ruleData) { for (json_spirit::Value &val : ruleData) { rules.push_back(Rule(val.get_obj())); } }
QgsRuleBasedRendererV2::QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol ) : QgsFeatureRendererV2( "RuleRenderer" ) { mDefaultSymbol = defaultSymbol; // add the default rule mRules << Rule( defaultSymbol->clone() ); }
void Transformer::loadRule(const string raw, int mode) { stringstream ss(raw); vector<string> tokensLHS, tokensRHS; string buffer; bool isLHS = true; while (ss >> buffer) { if (buffer == "->") // assuming wellformedness (only one "->" divider in rule) { isLHS = false; } else { if (isLHS) { tokensLHS.push_back(buffer); } else { tokensRHS.push_back(buffer); } } } Tree trLHS = getTTETree(tokensLHS); Tree trRHS = getTTETree(tokensRHS); string id = getID(trLHS, trLHS.begin()); if (mode == 3) { rules3plus[id].push_back(Rule(trLHS, trRHS)); } else if (mode == 2) { rules2[id].push_back(Rule(trLHS, trRHS)); } else { printWarning("illegal rule mode specified"); } ruleCount++; }
QList<QgsRuleBasedRendererV2::Rule> QgsRuleBasedRendererV2::refineRuleScales( QgsRuleBasedRendererV2::Rule& initialRule, QList<int> scales ) { qSort( scales ); // make sure the scales are in ascending order QList<Rule> rules; int oldScale = initialRule.scaleMinDenom(); int maxDenom = initialRule.scaleMaxDenom(); foreach( int scale, scales ) { if ( initialRule.scaleMinDenom() >= scale ) continue; // jump over the first scales out of the interval if ( maxDenom != 0 && maxDenom <= scale ) break; // ignore the latter scales out of the interval rules.append( Rule( initialRule.symbol()->clone(), oldScale, scale, initialRule.filterExpression(), initialRule.label(), initialRule.description() ) ); oldScale = scale; } // last rule rules.append( Rule( initialRule.symbol()->clone(), oldScale, maxDenom, initialRule.filterExpression(), initialRule.label(), initialRule.description() ) ); return rules; }
Grammar read_grammar(std::istream& in) { Grammar ret; std::string line; while(std::getline(in, line)) { std::vector<std::string> entry = split(line); if(!entry.empty()) ret[entry[0]].push_back(Rule(entry.begin() + 1, entry.end())); } return ret; }
void Configuration::parseRules(INI& ini) { Section* rules = ini.getSection(L"rules"); std::vector<std::wstring>& keys = rules->getKeys(); std::vector<std::wstring>& values = rules->getValues(); for (unsigned int i = 0 ; i < keys.size() ; i++) { File f(values[i]); f.expand(); this->rules.push_back(Rule(keys[i], f.path())); } }
Parser::Parser(const vector<Production>& productions, const string& parserTablePath) : BasicParser(productions), parserTablePath(parserTablePath) { #ifdef _DEBUG stream.open("ParserResult.txt", fstream::out | fstream::binary); #endif // String Begin Rule quotationMarks = Rule('\"', &context); Rule ruleString = quotationMarks + *!quotationMarks + quotationMarks; ruleString.buildDFA(); ruleString.setShowName("\"{String}\""); Production::Item itemString(ruleString); // String End // Digit Start Rule _0('0', &context); Rule _9('9', &context); Rule _0_9 = _0 - _9; Rule ruleDigit = +_0_9; ruleDigit.buildDFA(); ruleDigit.setShowName("\"{Digit}\""); Production::Item itemDigit(ruleDigit); // Digit End // Real Start Rule _point('.', &context); Rule ruleReal = *_0_9 + _point + +_0_9; ruleReal.buildDFA(); ruleReal.setShowName("\"{Real}\""); Production::Item itemReal(ruleReal); // Real End // Letter Start Rule _('_', &context); Rule _a('a', &context); Rule _z('z', &context); Rule _A('A', &context); Rule _Z('Z', &context); Rule _a_z = _a - _z; Rule _A_Z = _A - _Z; Rule ruleLetter = ((+_ + ruleDigit) | (+(_ | _a_z | _A_Z))) + *(_ | ruleDigit | _a_z | _A_Z); ruleLetter.buildDFA(); ruleLetter.setShowName("\"{Letter}\""); Production::Item itemLetter(ruleLetter); // Letter End vts.push_back(pair<string, Production::Item>("{String}", itemString)); vts.push_back(pair<string, Production::Item>("{Digit}", itemDigit)); vts.push_back(pair<string, Production::Item>("{Real}", itemReal)); vts.push_back(pair<string, Production::Item>("{Letter}", itemLetter)); }
void QmlRulesModel::setNewEditRule() { // qDebug("QmlRulesModel::setNewEditRule"); _editRule = Rule(); // According to user input, this might be confusing, so do not set all days. Empty selection. // // When creating new rule, automatically select all days // QSet<int> days; // for (int i = 0; i < 7; i++) { // days << i; // } // _editRule.setDays(days); }
void QmlRulesModel::setEditRule(int index) { // qDebug("QmlRulesModel::setEditRule(%d)", index); if (index < 0 || index >= _rules.count()) { qDebug("QmlRulesModel::setEditRule: Invalid index %d", index); _editRule = Rule(); return; } _editRule = _rules[index]; // qDebug("QmlRulesModel::setEditRule client->saveEditRule id %s, name %s", qPrintable(_editRule.getRuleId()), qPrintable(_editRule.getRuleName())); }
void Resource::readRule(Common::File *file, RuleList &rules) { rules.clear(); while (file->readByte() == 1) { rules.push_back(Rule()); Rule &rule = rules.back(); rule._ruleType = (RuleType)file->readSint16LE(); rule._param1 = file->readSint16LE(); rule._param2 = file->readSint16LE(); rule._condition = readConditions(file); readAction(file, rule._actionList); } }
void datalogProgram ::ruleList(){ if (tokens.at(vecIndex).getTokenType() == ID && tokens.at(vecIndex + 2).getTokenType() == ID){ Rule(); ruleList(); } else if (tokens.at(vecIndex).getTokenType() == QUERIES){} else{ if (currentStatus == true){ currentStatus = false; falseTok = tokens.at(vecIndex); } } }
void LogViewer::createRule() { QList<QTreeWidgetItem *> items=list->selectedItems(); QTreeWidgetItem *item=items.count() ? items.first() : 0L; if(item) { QString l(item->text(COL_RAW)); l=l.replace("[UFW ", "[UFW_"); QStringList parts=l.split(' ', QString::SkipEmptyParts); QStringList::ConstIterator it(parts.constBegin()), end(parts.constEnd()); QString destAddress, sourceAddress, destPort, sourcePort, interfaceIn, interfaceOut, action; Types::Protocol protocol=Types::PROTO_BOTH; Types::Policy pol=Types::POLICY_DENY; for(; it!=end; ++it) { if((*it).startsWith(QLatin1String("IN="))) interfaceIn=(*it).mid(3); else if((*it).startsWith(QLatin1String("OUT="))) interfaceOut=(*it).mid(4); else if((*it).startsWith(QLatin1String("SRC="))) sourceAddress=(*it).mid(4); else if((*it).startsWith(QLatin1String("DST="))) destAddress=(*it).mid(4); else if((*it).startsWith(QLatin1String("PROTO="))) protocol=Types::toProtocol((*it).mid(6).toLower()); else if((*it).startsWith(QLatin1String("SPT="))) sourcePort=(*it).mid(4); else if((*it).startsWith(QLatin1String("DPT="))) destPort=(*it).mid(4); else if((*it).startsWith(QLatin1String("[UFW_"))) { // Invert rule type - as we are creating the inverse of what the log says! pol=QLatin1String("[UFW_BLOCK]")==(*it) ? Types::POLICY_ALLOW : Types::POLICY_DENY; } } kcm->createRule(Rule(pol, interfaceOut.isEmpty(), Types::LOGGING_OFF, protocol, QString(), QString(), sourceAddress, sourcePort, destAddress, destPort, interfaceIn, interfaceOut)); } }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ vector<Rule> myRules; bIsTreeMode = false; switch (key) { case '1': myRules.push_back( Rule('F',"FF+[+F-F-F]-[-F+F+F]") ); system.setup("F", myRules); turtle.setup( 15, 25 ); bIsTreeMode = true; mode = "Tree"; break; case '2': myRules.push_back( Rule('F',"F[F]-F+F[--F]+F-F") ); system.setup( "F-F-F-F", myRules ); turtle.setup( 10, 90 ); mode = "Boxes"; break; case '3': myRules.push_back( Rule('F',"F--F--F--G") ); myRules.push_back( Rule('G',"GG") ); system.setup("F--F--F", myRules); turtle.setup( 10, 60 ); mode = "Sierpinski"; break; default: break; } turtle.setInstructions( system.sentence ); }
QList<QgsRuleBasedRendererV2::Rule> QgsRuleBasedRendererV2::refineRuleCategories( QgsRuleBasedRendererV2::Rule& initialRule, QgsCategorizedSymbolRendererV2* r ) { QList<Rule> rules; foreach( const QgsRendererCategoryV2& cat, r->categories() ) { QString newfilter = QString( "%1 = '%2'" ).arg( r->classAttribute() ).arg( cat.value().toString() ); QString filter = initialRule.filterExpression(); QString label = initialRule.label(); QString description = initialRule.description(); if ( filter.isEmpty() ) filter = newfilter; else filter = QString( "(%1) AND (%2)" ).arg( filter ).arg( newfilter ); rules.append( Rule( cat.symbol()->clone(), initialRule.scaleMinDenom(), initialRule.scaleMaxDenom(), filter, initialRule.label(), initialRule.description() ) ); } return rules; }
QList<QgsRuleBasedRendererV2::Rule> QgsRuleBasedRendererV2::refineRuleRanges( QgsRuleBasedRendererV2::Rule& initialRule, QgsGraduatedSymbolRendererV2* r ) { QList<Rule> rules; foreach( const QgsRendererRangeV2& rng, r->ranges() ) { QString newfilter = QString( "%1 >= '%2' AND %1 <= '%3'" ).arg( r->classAttribute() ).arg( rng.lowerValue() ).arg( rng.upperValue() ); QString filter = initialRule.filterExpression(); QString label = initialRule.label(); QString description = initialRule.description(); if ( filter.isEmpty() ) filter = newfilter; else filter = QString( "(%1) AND (%2)" ).arg( filter ).arg( newfilter ); rules.append( Rule( rng.symbol()->clone(), initialRule.scaleMinDenom(), initialRule.scaleMaxDenom(), filter, initialRule.label(), initialRule.description() ) ); } return rules; }
void DNSEnumService::parse_naptr_reply(const struct ares_naptr_reply* naptr_reply, std::vector<DNSEnumService::Rule>& rules) { for (const struct ares_naptr_reply* record = naptr_reply; record != NULL; record = record->next) { TRC_DEBUG("Got NAPTR record: %u %u \"%s\" \"%s\" \"%s\" %s", record->order, record->preference, record->service, record->flags, record->regexp, record->replacement); if ((strcasecmp((char*)record->service, "e2u+sip") == 0) || (strcasecmp((char*)record->service, "e2u+pstn:sip") == 0) || (strcasecmp((char*)record->service, "e2u+pstn:tel") == 0)) { boost::regex regex; std::string replace; bool terminal = false; if (!EnumService::parse_regex_replace(std::string((char*)record->regexp), regex, replace)) { TRC_WARNING("DNS ENUM record contains unparseable regular expression: %s", record->regexp); // As above, we don't give up totally here. continue; } // The only valid flag is u. If we see any other flags, we must ignore // the whole record (according to RFC 3761, 2.4.1). if (strcasecmp((char*)record->flags, "u") == 0) { terminal = true; } else if (strcmp((char*)record->flags, "") != 0) { TRC_WARNING("DNS ENUM record contains unknown flags: %s", record->flags); // Note that we don't give up totally here. If we end up with an empty // list, we'll break out then. Otherwise, we'll just try and push on. continue; } rules.push_back(Rule(regex, replace, terminal, record->order, record->preference)); } } std::sort(rules.begin(), rules.end(), DNSEnumService::Rule::compare_order_preference); }
QgsFeatureRendererV2* QgsRuleBasedRendererV2::create( QDomElement& element ) { // load symbols QDomElement symbolsElem = element.firstChildElement( "symbols" ); if ( symbolsElem.isNull() ) return NULL; QgsSymbolV2Map symbolMap = QgsSymbolLayerV2Utils::loadSymbols( symbolsElem ); if ( !symbolMap.contains( "default" ) ) { QgsDebugMsg( "default symbol not found!" ); return NULL; } QgsRuleBasedRendererV2* r = new QgsRuleBasedRendererV2( symbolMap.take( "default" ) ); r->mRules.clear(); QDomElement rulesElem = element.firstChildElement( "rules" ); QDomElement ruleElem = rulesElem.firstChildElement( "rule" ); while ( !ruleElem.isNull() ) { QString symbolIdx = ruleElem.attribute( "symbol" ); if ( symbolMap.contains( symbolIdx ) ) { QString filterExp = ruleElem.attribute( "filter" ); QString label = ruleElem.attribute( "label" ); QString description = ruleElem.attribute( "description" ); int scaleMinDenom = ruleElem.attribute( "scalemindenom", "0" ).toInt(); int scaleMaxDenom = ruleElem.attribute( "scalemaxdenom", "0" ).toInt(); r->mRules.append( Rule( symbolMap.take( symbolIdx ), scaleMinDenom, scaleMaxDenom, filterExp, label, description ) ); } else { QgsDebugMsg( "symbol for rule " + symbolIdx + " not found! (skipping)" ); } ruleElem = ruleElem.nextSiblingElement( "rule" ); } // delete symbols if there are any more QgsSymbolLayerV2Utils::clearSymbolMap( symbolMap ); return r; }
Rule Rule::operator-(const Rule& x) { if (epsilonNFA_Edges.size() == 1 && x.epsilonNFA_Edges.size() == 1 && epsilonNFA_Edges.begin()->second.size() == 1 && x.epsilonNFA_Edges.begin()->second.size() == 1 && epsilonNFA_Edges.begin()->second.begin()->value.type == Variant::TChar && x.epsilonNFA_Edges.begin()->second.begin()->value.type == Variant::TChar) { Rule a(pContext); a.pEpsilonStart = EpsilonNFA_State_Alloc::allocate(); construct(a.pEpsilonStart); a.pEpsilonEnd = EpsilonNFA_State_Alloc::allocate(); construct(a.pEpsilonEnd); pContext->epsilonNFA_States.insert(a.pEpsilonStart); pContext->epsilonNFA_States.insert(a.pEpsilonEnd); a.epsilonNFA_Edges[a.pEpsilonStart].push_back(EpsilonNFA_Edge(pair<char, char>(epsilonNFA_Edges.begin()->second.begin()->value.data.Char.value1, x.epsilonNFA_Edges.begin()->second.begin()->value.data.Char.value1), a.pEpsilonStart, a.pEpsilonEnd)); return a; } else { throw error<const char*>("doesn't support", __FILE__, __LINE__); } return Rule(); }
void DTrunkWork(INTERFACE_STRUCT* pOneTrunk, Acs_Evt_t* pAcsEvt) { DJ_S8 pCallerNum[64] = {0}; DJ_S8 pCalledNum[64] = {0}; DJ_S8 pTempcalledNum[64] = {0}; char TmpDtmf[1] = {0}; Acs_CallControl_Data *pCallControl = NULL; VOIP_STRUCT *pOneVOIP = NULL; int i = -1; RetCode_t ret; try { if (pAcsEvt->m_s32EventType == XMS_EVT_CLEARCALL) { TRACE("Recv ss7 clearCall evt\n"); long mDspID=pOneTrunk->pVoipDeviceID.m_s8ModuleID; long mChannelID=pOneTrunk->pVoipDeviceID.m_s16ChannelID; pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if(pOneTrunk->mExchangeType == SS7_VOIP) { pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if (pOneVOIP->iLineState != DCS_FREE) { pubIpSendClearCallCount++; XMS_ctsClearCall(g_acsHandle, &pOneVOIP->deviceID, 0, NULL); if(pOneVOIP->pVoiceDeviceID.m_s8ModuleID>0 ) My_DualUnlink(&pOneTrunk->deviceID, &pOneVOIP->pVoiceDeviceID); DrawVOIP_LinkDev (pOneVOIP); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s Direct SS7 call in: ss7 receive clearCall so clear voip.Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } } } if(AllDeviceRes[mDspID].pVOIP[mChannelID].mExchangeType == VOIP_SS7 && AllDeviceRes[mDspID].pVOIP[mChannelID].iLineState !=DCS_FREE && AllDeviceRes[mDspID].pVOIP[mChannelID].iLineState !=DCS_CALLIN ) { pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); ret = XMS_ctsClearCall(g_acsHandle, &pOneVOIP->deviceID, 0, NULL); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s Direct VOIP call in: ss7 receive clearCall so clear voip.Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } } ResetTrunk(pOneTrunk,pAcsEvt); return; } //状态处理 switch(pOneTrunk->DTrkState) { case TRK_FREE: /*call in from Digit Signal */ if (pAcsEvt->m_s32EventType == XMS_EVT_CALLIN) { pCallControl = (Acs_CallControl_Data *)((DJ_S8 *)pAcsEvt + sizeof(Acs_Evt_t)); strncpy(pCallerNum, pCallControl->m_s8CallingNum, sizeof(pCallerNum)); strncpy(pTempcalledNum, pCallControl->m_s8CalledNum, sizeof(pTempcalledNum)); //hao ma gui ze memset(pCalledNum, 0, sizeof(pCalledNum)); if (Rule(pTempcalledNum, pDailRuleHead, pCalledNum) == 0) strcpy(pCalledNum, pTempcalledNum); pOneTrunk->mExchangeType = SS7_VOIP; pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s SS7 RECEVICE CallIn:Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pCallerNum, pCalledNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } if(pOneVOIP->iLineState==DCS_FREE && pOneVOIP->State == VOIP_FREE) { pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if(PSTNToVOIPCallout(pCallerNum, pCalledNum, &pOneVOIP->deviceID, pOneTrunk) < 0) { XMS_ctsClearCall(g_acsHandle, &pOneTrunk->deviceID, 0, NULL); TRACE("3 ClearCall SS7\n"); Change_DTrunkState(pOneTrunk, TRK_HANGUP); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s First Direct SS7 callin: voip function error, so clear ss7 :Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } break; } DrawVOIP_LinkDev(pOneVOIP); DrawVOIP_CallInfo(pOneVOIP); Change_VOIPState(pOneVOIP, VOIP_CALLOUT); strncpy(pOneVOIP->CalleeNum,pCalledNum,20); strncpy(pOneVOIP->CallerNum,pCallerNum,20); strncpy(pOneTrunk->CalleeCode, pCalledNum, 20); strncpy(pOneTrunk->CallerCode, pCallerNum, 20); DrawDTrunk_CallInfo(pOneTrunk); DrawDTrunk_LinkDev(pOneTrunk); Change_DTrunkState(pOneTrunk, TRK_WAIT_ANSERCALL); } else { XMS_ctsSetDevTimer(g_acsHandle,&pOneTrunk->deviceID,400); pOneTrunk->TimeOut = 0; DrawDTrunk_DTMF(pOneTrunk); Change_DTrunkState(pOneTrunk,TRK_WAIT_CALL_VOIP); } } break; case TRK_WAIT_CALL_VOIP: { if(pOneTrunk->iLineState == DCS_FREE ) { if (pOneTrunk->mExchangeType == SS7_VOIP) { pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if (pOneVOIP->iLineState != DCS_FREE) { XMS_ctsClearCall(g_acsHandle, &pOneVOIP->deviceID, 0, NULL); if(pOneVOIP->pVoiceDeviceID.m_s8ModuleID>0 ) My_DualUnlink(&pOneTrunk->deviceID, &pOneVOIP->pVoiceDeviceID); DrawVOIP_LinkDev (pOneVOIP); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s Direct SS7 call in: wait call IP,then SS7 Linestate is free so clear voip:Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } } } ResetTrunk(pOneTrunk,pAcsEvt); } if(pAcsEvt->m_s32EventType == XMS_EVT_DEV_TIMER && pOneTrunk->iLineState != DCS_FREE) { pOneTrunk->TimeOut++; DrawDTrunk_DTMF(pOneTrunk); if(pOneTrunk->TimeOut >4 ) { pOneTrunk->TimeOut = 0; pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); XMS_ctsClearCall(g_acsHandle, &pOneTrunk->deviceID, 0, NULL); TRACE("4 ClearCall SS7\n"); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s Direct SS7 call in: voip wait time is timeover,so clear ss7 :Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%d\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } break; } pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if(pOneVOIP->iLineState==DCS_FREE && pOneVOIP->State == VOIP_FREE) { if(PSTNToVOIPCallout(pCallerNum, pCalledNum, &pOneVOIP->deviceID, pOneTrunk) < 0) { XMS_ctsClearCall(g_acsHandle, &pOneTrunk->deviceID, 0, NULL); TRACE("5 ClearCall SS7\n");; Change_DTrunkState(pOneTrunk, TRK_HANGUP); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s Second Direct SS7 call in: Voip call function error, so clear ss7:Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } break; } DrawVOIP_LinkDev(pOneVOIP); DrawVOIP_CallInfo(pOneVOIP); Change_VOIPState(pOneVOIP, VOIP_CALLOUT); strncpy(pOneTrunk->CalleeCode, pCalledNum, 20); strncpy(pOneTrunk->CallerCode, pCallerNum, 20); DrawDTrunk_CallInfo(pOneTrunk); DrawDTrunk_LinkDev(pOneTrunk); Change_DTrunkState(pOneTrunk, TRK_WAIT_ANSERCALL); } else { XMS_ctsSetDevTimer(g_acsHandle,&pOneTrunk->deviceID,400); Change_DTrunkState(pOneTrunk,TRK_WAIT_CALL_VOIP); } } } break; case TRK_WAIT_ANSERCALL: if(pOneTrunk->iLineState == DCS_FREE) { if (pOneTrunk->mExchangeType == SS7_VOIP) { pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if (pOneVOIP->iLineState != DCS_FREE) { XMS_ctsClearCall(g_acsHandle, &pOneVOIP->deviceID, 0, NULL); if(pOneVOIP->pVoiceDeviceID.m_s8ModuleID>0 ) My_DualUnlink(&pOneTrunk->deviceID, &pOneVOIP->pVoiceDeviceID); DrawVOIP_LinkDev (pOneVOIP); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s SS7 wait ansercall but SS7 Linestate is free so clear VOIP: Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } } } ResetTrunk(pOneTrunk,pAcsEvt); } if(pAcsEvt->m_s32EventType == XMS_EVT_ANSWERCALL) { Change_DTrunkState(pOneTrunk, TRK_CONNECT); } break; case TRK_CALLOUT: if ( pAcsEvt->m_s32EventType == XMS_EVT_CALLOUT ) { INTERFACE_STRUCT *pOneInterface = NULL; pOneVOIP = &M_OneVOIP(pOneTrunk->pVoipDeviceID); pCallControl = (Acs_CallControl_Data *)((DJ_S8 *)pAcsEvt + sizeof(Acs_Evt_t)); if ( pCallControl->m_s32AcsEvtState == 1 ) // 呼出成功,对方摘机 { // pOneTrunk->bcallFailFalg = false; if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s SS7 CallOut Success:Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } pubIpSS7ConnectCount++; Change_DTrunkState(pOneTrunk, TRK_CONNECT); Change_VOIPState(pOneVOIP, VOIP_WAIT_ANSWERCALL); XMS_ctsAnswerCallIn(g_acsHandle, &pOneVOIP->deviceID, NULL); } else // 呼出失败 { pOneTrunk->bcallFailFalg = true; DrawDTrunk_Reason(pOneTrunk, pCallControl->m_s32AcsEvtErrCode, pCallControl->m_s32CallClearCause); Change_DTrunkState(pOneTrunk, TRK_FREE); pubIpSS7ErrorCount++; pubErrorClearCallCount++; //带原因值的拆线--ADD by WWK int mCallErrorCode = 0; if(pCallControl->m_s32AcsEvtErrCode == 17 ) mCallErrorCode = 486; //被叫忙 if(pCallControl->m_s32AcsEvtErrCode == 28 ) mCallErrorCode = 404; //号码不存在 if(pCallControl->m_s32AcsEvtErrCode == 19 ) mCallErrorCode = 408; //被叫关机或者无应答 XMS_ctsClearCall(g_acsHandle, &pOneVOIP->deviceID, mCallErrorCode, NULL); Change_VOIPState(pOneVOIP, VOIP_HANGUP); if (g_logfp != NULL) { char mTemp[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mTemp,"%s SS7 call out failed, so clear voip!! DSP:%d Ch:%d ErrorCode:%d Reason:%d, bcallFailFalg:%d\n\r", mCurrTime, pOneTrunk->deviceID.m_s8ModuleID, pOneTrunk->deviceID.m_s16ChannelID, pCallControl->m_s32AcsEvtErrCode, pCallControl->m_s32CallClearCause, pOneTrunk->bcallFailFalg); fwrite(mTemp,strlen(mTemp),1,g_logfp); fflush(g_logfp); } } } break; case TRK_CONNECT: if(pOneTrunk->iLineState == DCS_FREE ) { if (pOneTrunk->mExchangeType == SS7_VOIP) { pOneVOIP=&M_OneVOIP(pOneTrunk->pVoipDeviceID); if (pOneVOIP->iLineState != DCS_FREE) { XMS_ctsClearCall(g_acsHandle, &pOneVOIP->deviceID, 0, NULL); if(pOneVOIP->pVoiceDeviceID.m_s8ModuleID>0 ) My_DualUnlink(&pOneTrunk->deviceID, &pOneVOIP->pVoiceDeviceID); DrawVOIP_LinkDev (pOneVOIP); if (g_logfp != NULL) { char mLog[512]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mLog,"%s SS7 Connected and Line State Is Free So Clear VOIP CALL :Dsp:%d Ch:%d GlobalID:%d CallerNum:%s CalledNum:%s\n\r", mCurrTime, pOneVOIP->deviceID.m_s8ModuleID, pOneVOIP->deviceID.m_s16ChannelID, pOneVOIP->iGlobeID, pOneVOIP->CallerNum, pOneVOIP->CalleeNum); fwrite(mLog,strlen(mLog),1,g_logfp); fflush(g_logfp); } } } ResetTrunk(pOneTrunk, pAcsEvt); return; } TmpDtmf[0] = My_GetIntfDtmfCode(pAcsEvt); if ( TmpDtmf[0] != -1 ) //DTMF按键 { My_AddIntfDtmfBuf(pOneTrunk, TmpDtmf[0]); DrawDTrunk_DTMF(pOneTrunk); if(pOneTrunk->DtmfCount > 0 ) { DeviceID_t *pOneVOIP = &AllDeviceRes[pOneTrunk->deviceID.m_s8ModuleID].pInterf[pOneTrunk->deviceID.m_s16ChannelID].pVoipDeviceID; switch(pubSendRTPDTMFType) { case 1: { Acs_VoIP_H245UII h245Uii = {0}; h245Uii.m_s8Signal = pOneTrunk->DtmfBuf[0]; // dtmf char in "0123456789#*ABCD!" h245Uii.m_u32Duration = 200; // milliseconds XMS_ctsSendIOData(g_acsHandle,pOneVOIP,XMS_IO_TYPE_VOIP_H245UII,sizeof(h245Uii),&h245Uii); } break; case 2: { Acs_VoIP_SIPINFO sipInfo = {0}; strcpy(sipInfo.m_s8ContentType, "application/dtmf"); sprintf(sipInfo.m_s8Body, "dtmf=%c\nduration=%d", pOneTrunk->DtmfBuf[0], 200); XMS_ctsSendIOData(g_acsHandle,pOneVOIP,XMS_IO_TYPE_VOIP_SIPINFO,sizeof(sipInfo),&sipInfo); } break; case 3: { Acs_VoIP_RTPDTMF rtpDtmf = {0}; rtpDtmf.m_s8EventChar = pOneTrunk->DtmfBuf[0]; // rtp dtmf event char rtpDtmf.m_s8Volume = -32; // volume (in dbm0 from -63 to 0) rtpDtmf.m_u16Duration = 200; // duration (in timestamp units XMS_ctsSendIOData(g_acsHandle,pOneVOIP,XMS_IO_TYPE_VOIP_RTPDTMF,sizeof(rtpDtmf),&rtpDtmf); } break; default: { Acs_VoIP_H245UII h245Uii = {0}; h245Uii.m_s8Signal = pOneTrunk->DtmfBuf[0]; // dtmf char in "0123456789#*ABCD!" h245Uii.m_u32Duration = 200; // milliseconds XMS_ctsSendIOData(g_acsHandle,pOneVOIP,XMS_IO_TYPE_VOIP_H245UII,sizeof(h245Uii),&h245Uii); } break; } My_InitIntfDtmfBuf(pOneTrunk); } } break; } }catch(...) { if (g_logfp != NULL) { char mTemp[255]={0}; char mCurrTime[50]={0}; getCurrTime(mCurrTime); sprintf(mTemp,"%s DT Trunk Run Error\n\r",mCurrTime); fwrite(mTemp,strlen(mTemp),1,g_logfp); fflush(g_logfp); } } return; }
void Parser::add_token(std::string tag, std::string pattern) { this->lexer.add_rule(Rule(tag, pattern)); this->terminals.insert(tag); }
QList<Token> LexicalAnalyzer::analyze(QString s, const QString &fileName, QTextCodec *codec, bool *ok, QString *err, int *pos, QString *fn) { typedef QList<Rule> RuleList; init_once(RuleList, rules, RuleList()) { //String literal, priority=0 rules << Rule(&matchString, &parceString); //Function name, priority=1 rules << Rule(&matchFuncName2Args, &parceFuncName); //Special function name, priority=2 rules << Rule(&matchSpecFuncName, &parceSpecFuncName); //Special symbols, priority=3 rules << Rule(&matchSharp, &parceSpecialSymbol); rules << Rule(&matchBackslash, &parceSpecialSymbol); rules << Rule(&matchLeftBrace, &parceSpecialSymbol); rules << Rule(&matchRightBrace, &parceSpecialSymbol); rules << Rule(&matchLeftBracket, &parceSpecialSymbol); rules << Rule(&matchRightBracket, &parceSpecialSymbol); //Real literal, priority=4 rules << Rule(&matchReal, &parceReal); //String literal, priority=5 rules << Rule(&matchInteger, &parceInteger); }
//! //! Zwraca wartosc calki z funkcji $f$ na prostopadloscianie $[x0, x1] \times [y0, y1] \times [z0, z1]$. //! double Adapt3D::Calc(const Fun3D& f, double x0, double x1, double y0, double y1, double z0, double z1) { Brick *br1, *br2; Clear(); // Pierwsze wywolanie kwadratury br1 = NewBrick(); br1->m_x0 = x0; br1->m_x1 = x1; br1->m_y0 = y0; br1->m_y1 = y1; br1->m_z0 = z0; br1->m_z1 = z1; Rule(f, br1); m_set.Add(br1); // Dodaje brick do kolejki priorytetowej size_t ii = 0; while(1) { if(ii > 10) // Musi byc wykonanych co najniej 10 podzialow { if(m_set.ErrAbs() < m_epsAbs) break; } ii++; br1 = m_set.Top(); // Pobieram brick z kolejki o najwiekszym bledzie br2 = NewBrick(); if(br2 == NULL) { fprintf(stderr, "ARAPT WARNING. Max size = %lu of priority queue exceeded!\n\n", static_cast<unsigned long>(m_set.MaxSize())); break; } *br2 = *br1; // Kopiuje obeikty // Podzial na dwa prostopadlosciany if(br1->m_divAx == 0) // podzial wzdluz osi X { br1->HalfXup(); br2->HalfXdown(); } else if(br1->m_divAx == 1) // podzial wzdluz osi Y { br1->HalfYup(); br2->HalfYdown(); } else if(br1->m_divAx == 2) // podzial wzdluz osi Z { br1->HalfZup(); br2->HalfZdown(); } else assert(0); // Policzenie kwadratur Rule(f, br1); Rule(f, br2); // Dodanie do kolejki dwoch brikow m_set.Add(br1); m_set.Add(br2); // printf("Adapt3D::Quad = %18.8E\n", m_set.Quad()); } return m_set.Quad(); }