Ejemplo n.º 1
0
Archivo: proxy.cpp Proyecto: Sebi55/GPC
void Proxy::sync_add_placeholders(Rule* parent) {
	assert(parent == NULL || parent->dataSource != NULL);

	std::list<std::string> path = parent ? this->dataSource->buildPath(*parent->dataSource) : std::list<std::string>();
	bool eop_is_blacklisted = false;

	for (std::list<std::list<std::string> >::const_iterator pti_iter = this->__idPathList_OtherEntriesPlaceHolders.begin(); pti_iter != this->__idPathList_OtherEntriesPlaceHolders.end(); pti_iter++) {
		if (*pti_iter == path) {
			eop_is_blacklisted = true;
			break;
		}
	}

	std::list<Rule>& list = parent ? parent->subRules : this->rules;
	if (!eop_is_blacklisted) {
		Rule newRule(Rule::OTHER_ENTRIES_PLACEHOLDER, parent ? this->dataSource->buildPath(*parent->dataSource) : std::list<std::string>(), "*", true);
		newRule.dataSource = this->dataSource->getEntryByPath(path);
		newRule.dataSource_list = this->dataSource->getListByPath(path);
		list.push_front(newRule);
		this->__idPathList_OtherEntriesPlaceHolders.push_back(path);
	}

	for (std::list<Rule>::iterator iter = list.begin(); iter != list.end(); iter++) {
		if (iter->dataSource && iter->type == Rule::NORMAL && iter->dataSource->type == Entry::SUBMENU) {
			this->sync_add_placeholders(&*iter);
		}
	}
}
Quadrature<Real>::Quadrature(const int dimension,
                             const std::vector<int> &numPoints1D,
                             const std::vector<EQuadrature> &rule1D, 
                             const std::vector<EGrowth> &growth1D,
                             const bool isNormalized) 
  : dimension_(dimension) {
  TEUCHOS_TEST_FOR_EXCEPTION((dimension!=(int)numPoints1D.size()||
		      dimension!=(int)rule1D.size()||
		      dimension!=(int)growth1D.size()),std::out_of_range,
           ">>> ERROR (Quadrature): Dimension mismatch for inputs.");
  accuracy_.clear();
  accuracy_.resize(dimension);
  std::vector<int> degree(1);
  Quadrature<Real> newRule(0,1);
  for (int i=0; i<dimension; i++) {
    // Compute 1D rules
    int numPoints = growthRule1D(numPoints1D[i],growth1D[i],rule1D[i]);
    Quadrature<Real> rule1(rule1D[i],numPoints,isNormalized);
    rule1.getAccuracy(degree);
    accuracy_.push_back(degree[0]);
    // Build Tensor Rule
    newRule = kron_prod<Real>(newRule,rule1);
  }
  typename std::map<std::vector<Real>,int>::iterator it;
  int loc = 0;
  std::vector<Real> node;
  for (it=newRule.begin(); it!=newRule.end(); it++) {
    node = it->first;
    addPointAndWeight(node,newRule.getWeight(node),loc);
    loc++;
  }
  if (isNormalized) {
    normalize();
  }
}
Ejemplo n.º 3
0
std::shared_ptr<OsmAnd::MapStyleRule> OsmAnd::MapStyle_P::createTagValueRootWrapperRule( uint64_t id, const std::shared_ptr<MapStyleRule>& rule )
{
    if(rule->_d->_values.size() <= 2)
        return rule;

    QHash< QString, QString > attributes;
    attributes.insert(QLatin1String("tag"), getTagString(id));
    attributes.insert(QLatin1String("value"), getValueString(id));
    std::shared_ptr<MapStyleRule> newRule(new MapStyleRule(owner, attributes));
    newRule->_d->_ifElseChildren.push_back(rule);
    return newRule;
}
Ejemplo n.º 4
0
void RuleControl::OnText(wxCommandEvent &evt)
{
	Rule newRule(GetValue(), this);


	if (newRule.IsValid() || GetValue().Trim().IsEmpty())
	{
		m_rule = newRule;
		
		m_canvas->Redraw();
		SetToolTip(wxT("expression ok"));
	}
	else
	{
		SetToolTip(newRule.GetErrorLog());
	}
}
Ejemplo n.º 5
0
void RandomCollatorTest::Test(){
    // See ticket 5747 about reenabling this test.
    errln("This test needs to be fixed.\n");

    LanguageGenerator test_rule;
    if (test_rule.parseBNF(collationBNF, "$root", TRUE) != LanguageGenerator::OK){
        errln("The test code itself is wrong.");
        return;
    };

    //TestColltorCompare coll_test;

    static const int CONSTRUCT_RANDOM_COUNT = 1000;
    int i;
    for (i=0; i < CONSTRUCT_RANDOM_COUNT; i++){
        const char * rule = test_rule.next();
        logln("\n-----------------------------------%d\n",i);
        logln(UnicodeString(rule, strlen(rule)));

        UnicodeString newRule(rule);    // potential bug
        UErrorCode status = U_ZERO_ERROR;
        logln(   "===========================================\n");
        fwrite(rule, strlen(rule),1,stdout);
        logln("\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");

        Collator * c = new RuleBasedCollator(newRule,status);

        if (U_FAILURE(status)) {
            errln( "Could not create Collator for the %d(th) generated rule.\n"
                   "Error Name: %s\n"
                   "The rule is ",
                   i, u_errorName(status));
            return;
        }

        delete c;
    }
}
Ejemplo n.º 6
0
  DataPriorityController::DataPriorityController(FileQueue& queue, FileQueueParameters const* params)
    : m_rules(params->rules.size()),
      m_defaultRule(DataPriorityController::Rule("*", 0, 0, false)),
      m_queue(queue),
      m_queueParams(params)
  {

    for (unsigned int i = 0; i < m_queueParams->rules.size(); ++i) {
      // look for a channel with a matching name
      int channelIdx = -1;
      for (unsigned int j = 0; j < m_queueParams->channels.size(); ++j) {
        if (params->channels[j].name == params->rules[i].channelName) {
          channelIdx = j;
          break;
        }
      }

      if (channelIdx == -1) {
        MIRO_LOG_OSTR(LL_ERROR, "DPC: channel name: "
                      << m_queueParams->rules[i].channelName
                      << " does not exist. skipping rule.");
      }
      else {
        Rule newRule(m_queueParams->rules[i].extension,
                     channelIdx,
                     m_queueParams->rules[i].priority,
                     m_queueParams->rules[i].autoAdd);
        if (m_queueParams->rules[i].extension == "*") {
          m_defaultRule = newRule;
        }
        else {
          m_rules.push_back(newRule);
        }
      }
    }

  }
Ejemplo n.º 7
0
void CSV::createMainPage ()
{
  setCaption(tr("CSV Quotes"));

  QString s = "new";
  QString s2 = tr("New Rule");
  toolbar->addButton(s, newchart, s2);
  QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(newRule()));

  s = "edit";
  s2 = tr("Edit Rule");
  toolbar->addButton(s, edit, s2);
  QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(editRule()));

  s = "delete";
  s2 = tr("Delete Rule");
  toolbar->addButton(s, deleteitem, s2);
  QObject::connect(toolbar->getButton(s), SIGNAL(clicked()), this, SLOT(deleteRule()));

  QLabel *label = new QLabel(tr("Rule"), baseWidget);
  grid->addWidget(label, 0, 0);

  ruleCombo = new QComboBox(baseWidget);
  updateRules();
  grid->addWidget(ruleCombo, 0, 1);

  label = new QLabel(tr("Input"), baseWidget);
  grid->addWidget(label, 1, 0);

  QStringList l;
  file = new FileButton(baseWidget, l, lastPath);
  grid->addWidget(file, 1, 1);

  label = new QLabel(tr("Symbol"), baseWidget);
  grid->addWidget(label, 2, 0);

  symbol = new QLineEdit(baseWidget);
  grid->addWidget(symbol, 2, 1);

  label = new QLabel(tr("Auto Reload"), baseWidget);
  grid->addWidget(label, 3, 0);

  minutes = new QSpinBox(baseWidget);
  minutes->setMinValue(0);
  minutes->setMaxValue(99);
  minutes->setLineStep(1);
  QObject::connect(minutes, SIGNAL(valueChanged(int)), this, SLOT(reloadTimerChanged(int)));
  grid->addWidget(minutes, 3, 1);

  dateRange = new QCheckBox(tr("Select Date Range"), baseWidget);
  QObject::connect(dateRange, SIGNAL(toggled(bool)), this, SLOT(dateRangeChanged(bool)));
  grid->addWidget(dateRange, 5, 0);

  label = new QLabel(tr("Date Start"), baseWidget);
  grid->addWidget(label, 6, 0);

  sdate = new Q3DateEdit(QDate::currentDate(), baseWidget);
  sdate->setAutoAdvance(TRUE);
  sdate->setOrder(Q3DateEdit::YMD);
  grid->addWidget(sdate, 6, 1);

  label = new QLabel(tr("Date End"), baseWidget);
  grid->addWidget(label, 7, 0);

  edate = new Q3DateEdit(QDate::currentDate(), baseWidget);
  edate->setAutoAdvance(TRUE);
  edate->setOrder(Q3DateEdit::YMD);
  grid->addWidget(edate, 7, 1);

  // set the default end date
  QDate dt = QDate::currentDate();
  if (dt.dayOfWeek() == 6)
    dt = dt.addDays(-1);
  else
  {
    if (dt.dayOfWeek() == 7)
      dt = dt.addDays(-2);
  }
  edate->setDate(dt);
  sdate->setDate(dt);
}
Ejemplo n.º 8
0
void FilterEditor::onAddRule(GtkWidget* widget, FilterEditor* self) {
	FilterRule newRule("texture", "textures/", false);
	self->_filter.rules.push_back(newRule);

	self->update();
}
STDMETHODIMP
CContentBasedClassifier::UseRulesAndDefinitions(
		IFsrmCollection * Rules, 
		IFsrmCollection * propertyDefinitions
		)
{
	HRESULT hr = S_OK;
	_variant_t vRule;
	CComPtr<IFsrmRule> pFsrmRule;
	CComPtr<IFsrmClassificationRule> pFsrmClassificationRule;
	CComBSTR		strRuleName;
	wstring			strRuleNameLower;
	CComBSTR		strPropertyName;
	CComBSTR		strPropertyValue;
	LONG			cRuleCount;
	SAFEARRAY *psaParams = NULL;
	SAFEARRAY *psaParsedParams = NULL;
	SAFEARRAYBOUND rgsaBound[1];
	LONG paramIndex;
	LONG lBoundParams;
	LONG uBoundParams;
	GUID idRule;

	m_mapFsrmClassificationRules.clear();

	hr = Rules->get_Count( &cRuleCount );

	if (hr != S_OK) {
		goto exit;
	}

	//iterate over the rules collection and build a map to store 
	//this map will be used while processing records for matching rules
	for (LONG iRule = 1; iRule <= cRuleCount; iRule++) {

		vRule.Clear( );

		// Get the next rule
		hr = Rules->get_Item( iRule, &vRule );
		if (hr != S_OK) {
			goto exit;
		}
	
		// Query for the IFsrmRule interface
		pFsrmRule.Release( );
		hr = vRule.pdispVal->QueryInterface( _uuidof( IFsrmRule ), (void **)&pFsrmRule );
		if (hr != S_OK) {
			goto exit;
		}

		// Query for the IFsrmClassificationRule interface
		pFsrmClassificationRule.Release( );
		hr = pFsrmRule->QueryInterface( _uuidof( IFsrmClassificationRule ), (void **)&pFsrmClassificationRule );
		if (hr != S_OK) {
			goto exit;
		}

		// Get the rule's name
		strRuleName.Empty( );
		hr = pFsrmRule->get_Name( &strRuleName );
		if (hr != S_OK) {
			goto exit;
		}		

		// Get the property name for this rule
		strPropertyName.Empty( );
		hr = pFsrmClassificationRule->get_PropertyAffected( &strPropertyName );
		if (hr != S_OK) {
			goto exit;
		}

		// Get the property value that will be applied by this rule
		strPropertyValue.Empty( );
		hr = pFsrmClassificationRule->get_Value( &strPropertyValue );
		if (hr != S_OK) {
			goto exit;
		}

		// Get the additional classification parameters for this rule
		psaParams = NULL;
		hr = pFsrmRule->get_Parameters(&psaParams);
		if (FAILED(hr))
		{
			goto exit;
		}

		// Get the rule id guid
		::memset(&idRule, 0, sizeof(GUID));
		hr = pFsrmRule->get_Id(&idRule);
		if (FAILED(hr))
		{
			goto exit;
		}

		psaParsedParams = NULL;

		if (psaParams)
		{
			// The additional parameters array contains parameters in the following format
			// key=value
			// This classifier treats the key as a value as well since it needs to search for words
			// in the contents of files. 
			lBoundParams = 0;
			uBoundParams = 0;
			
			hr = SafeArrayGetLBound(psaParams, 1, &lBoundParams);
			if (FAILED(hr))
			{
				goto exit;
			}

			hr = SafeArrayGetUBound(psaParams, 1, &uBoundParams);
			if (FAILED(hr))
			{
				goto exit;
			}

			rgsaBound[0].cElements = ((uBoundParams - lBoundParams + 1) * 2);
			rgsaBound[0].lLbound = 0;
			
			paramIndex = 0;

			psaParsedParams = SafeArrayCreate(VT_VARIANT, 1, rgsaBound);
			if (psaParsedParams == NULL)
			{
				hr = E_OUTOFMEMORY;
				goto exit;
			}

			for (LONG iParam = lBoundParams; iParam <= uBoundParams; iParam++)
			{
				_variant_t vParam;				

				hr = SafeArrayGetElement(psaParams, &iParam, &vParam);
				if (FAILED(hr))
				{
					goto exit;
				}

				CComBSTR strParam = vParam.bstrVal;
				LPWSTR pwszParamKey = (LPWSTR)strParam;
				LPWSTR pwszParamVal = ::wcschr(pwszParamKey, L'=');
				*pwszParamVal = 0;
				pwszParamVal++;

				BSTR bstrKey = SysAllocString(pwszParamKey);
				BSTR bstrVal = SysAllocString(pwszParamVal);

				_variant_t vKey = bstrKey;
				_variant_t vVal = bstrVal;

				hr = SafeArrayPutElement(psaParsedParams, &paramIndex, &vKey);
				if (FAILED(hr))
				{
					goto exit;
				}

				paramIndex++;

				hr = SafeArrayPutElement(psaParsedParams, &paramIndex, &vVal);
				if (FAILED(hr))
				{
					goto exit;
				}

			}

			//create a new property/value pair to store
			CFsrmClassificationRule newRule( strPropertyName, strPropertyValue, &psaParsedParams );

			//make sure rule name is lower case for ease in matching
			strRuleNameLower = strRuleName;
			std::transform( strRuleNameLower.begin( ), strRuleNameLower.end( ), strRuleNameLower.begin( ), towlower );

			//add rule with property/value to map
			m_mapFsrmClassificationRules[idRule] = newRule;	

		}	
	}

exit:

	return hr;

}
Ejemplo n.º 10
0
void MainWindow::createActions()
{   
  
  newAction = new QAction("&New",this);
  newAction->setIcon(QIcon(":/images/new.png"));      
  newAction->setShortcut(tr("Ctrl+N"));
  newAction->setStatusTip("Create a new edit session");
  connect(newAction,SIGNAL(triggered()),
          this,SLOT(newFile()));
  
  openFileAction = new QAction("&Open file",this);
  openFileAction->setIcon(QIcon(":/images/open.png"));    
  openFileAction->setShortcut(tr("Ctrl+O"));
  openFileAction->setStatusTip("Open/load data from file");
  connect(openFileAction,SIGNAL(triggered()),
          this,SLOT(openFile()));
  
  
  
  openVideoAction= new QAction("Open video image",this);
  openVideoAction->setIcon(QIcon(":/images/video-x-generic.svg"));    
  //openVideoAction->setShortcut(tr("Ctrl+O+O"));
  //openVideoAction->setStatusTip("Open/load contexts data from file");
  connect(openVideoAction,SIGNAL(triggered()),
          this,SLOT(openVideoFile()));
  
  
  saveProjectAction= new QAction("&Save project",this);
  saveProjectAction->setIcon(QIcon(":/images/save.png"));     
  saveProjectAction->setShortcut(tr("Ctrl+P"));
  saveProjectAction->setStatusTip("Save data to project file");
  connect(saveProjectAction,SIGNAL(triggered()),
          this,SLOT(saveProjectFile()));
  
  saveContextsAction = new QAction("Save contexts",this);
  saveContextsAction->setIcon(QIcon(":/images/insert-object.svg"));     
  saveContextsAction->setShortcut(tr("Ctrl+S+C"));
  saveContextsAction->setStatusTip("Save contexts data to file");  
  connect(saveContextsAction,SIGNAL(triggered()),
          this,SLOT(saveContextsToFile())); 
  
  saveRulesAction = new QAction("Save rules",this);
  saveRulesAction->setIcon(QIcon(":/images/insert-object.svg"));     
  saveRulesAction->setShortcut(tr("Ctrl+S+C"));
  saveRulesAction->setStatusTip("Save rule data to file");  
  connect(saveRulesAction,SIGNAL(triggered()),
          this,SLOT(saveRulesToFile()));   
  
  
  exitAction = new QAction("&Exit",this);
  exitAction->setIcon(QIcon(":/images/application-exit.svg"));     
  exitAction->setShortcut(tr("Ctrl+Q"));
  exitAction->setStatusTip("Close application");
  connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));   
  
  aboutAction = new QAction("&About",this);
  aboutAction->setIcon(QIcon(":/images/find.png"));     
  aboutAction->setShortcut(tr("Ctrl+A"));
  aboutAction->setStatusTip("About");
  connect(aboutAction,SIGNAL(triggered()),
          this,SLOT(about()));
  
  newRuleAction = new QAction("&New rule",this);
  newRuleAction->setIcon(QIcon(":/images/rule.svg"));
  connect(newRuleAction,SIGNAL(triggered()),
          this,SLOT(newRule()));
  
  runVirtualFencingAction = new QAction("&Video",this);
  runVirtualFencingAction->setIcon(QIcon(":/images/arrow.png"));      
  connect(runVirtualFencingAction,SIGNAL(triggered()),
          this,SLOT(runVirtualFencing()));
  
  addLineAction = new QAction("Add &Line",this);
  addLineAction->setIcon(QIcon(":/images/linepointer.png"));     
  addLineAction->setShortcut(tr("Ctrl+L"));
  addLineAction->setStatusTip("Add line");
  connect(addLineAction,SIGNAL(triggered()),
          this,SLOT(about()));                  
  
  
}
Ejemplo n.º 11
0
Archivo: PreLL1.c Proyecto: HsuJv/Note
void DLR() {
	pSymbolNode symbol_start = ll[0];
	pRule rule_start = gRules;
	ll[2] = ll[0];

	for (pSymbolNode i = symbol_start; i; i = i->next) {
		// Delete the indirect left recursion
		for (pSymbolNode j = symbol_start; j != i; j = j->next) {
			for (pRule ri = rule_start; ri; ri = ri->next) {
				// Rules that in the form of i ::= j...
				if (ri->addr->serial == i->serial) {
					if (ri->addr->next->serial == j->serial) {
						int changed = 0;

						// j is going to be substituted
						for (pRule rj = rule_start; rj; rj = rj->next) {
							// Rules that in the form of j ::= ...
							if (rj->addr->serial == j->serial) {
								char* buf;
								pRuleNode origanal = ri->addr->next;

								changed = 1;

								buf = Rule2String(rj->addr->next);
								ri->addr->next = (pRuleNode)getLinkedList(buf, origanal->next, newRuleNode);
								free(buf);
								buf = Rule2String(ri->addr);
								gRules = newRule((pRuleNode)getLinkedList(buf, 0, newRuleNode), gRules);
								free(buf);
								buf = NULL;

								for (pRuleNode prn = ri->addr->next; prn != origanal->next;) {
									pRuleNode temp = prn;
									prn = prn->next;
									free(temp);
								}

								ri->addr->next = origanal;
							}
						}

						// Delete the rule rj
						if (changed) {
							pRule preRi = gRules;

							while (preRi->next != ri && preRi != ri) preRi = preRi->next;
							for (pRuleNode pr = ri->addr; pr;) {
								pRuleNode prn = pr;
								pr = pr->next;
								free(prn->symbol);
								free(prn);
							}
							preRi->next = ri->next;
							free(ri);
							ri = preRi;
						}
					}
				}
			}
		}

		rule_start = gRules;

		// Delete the direct left recursion
		for (pRule r = rule_start; r; r = r->next) {
			// Rules that in the form of i ::= i...
			if (r->addr->serial == i->serial && r->addr->serial == r->addr->next->serial) {
				char newSymbol[BUFSIZ], *buf;
				size_t sLen, rLen;
				pRule preRi;
				int deleted = 0;

				// Fine all rules that indicate a direct left recursion rule of i
				for (pRule ri = r; ri; ri = ri->next) {
					if (ri->addr->serial == i->serial && ri->addr->serial == ri->addr->next->serial) {
						// Add symbol i'
						strcpy(newSymbol, i->symbol);
						sLen = strlen(i->symbol);
						newSymbol[sLen++] = '\'';
						newSymbol[sLen] = 0;
						if (strcmp(ll[0]->symbol, newSymbol)) {
							ll[0] = newSymbolNode(gNonTerSerial, newSymbol, 0, 0, ll[0]);
							gNonTerSerial += 2;
						}					

						// Add rule i ::= 0
						if (!deleted) {
							newSymbol[sLen] = 0x20;
							newSymbol[sLen + 1] = '0';
							newSymbol[sLen + 2] = 0;
							gRules = newRule((pRuleNode)getLinkedList(newSymbol, 0, newRuleNode), gRules);
						}

						// Add rule i' ::= ...i'
						buf = Rule2String(ri->addr->next->next);
						newSymbol[sLen++] = 0x20;
						memcpy(newSymbol + sLen, buf, strlen(buf));
						sLen += strlen(buf);
						free(buf);
						newSymbol[sLen++] = 0x20;
						rLen = sLen;
						sLen = 0;
						while (*(newSymbol + sLen) != 0x20) sLen++;
						newSymbol[sLen] = 0;
						strcpy(newSymbol + rLen, newSymbol);
						rLen += sLen;
						newSymbol[sLen] = 0x20;
						newSymbol[rLen] = 0;
						gRules = newRule((pRuleNode)getLinkedList(newSymbol, 0, newRuleNode), gRules);

						newSymbol[sLen] = 0;

						// Add rules i ::= a i' for all a in rules i ::= a starting without i
						for (pRule rr = rule_start; rr; rr = rr->next) {
							// If rules i ::= a i' for all a in rules i ::= a starting without i has been deleted
							if (deleted) break;

							// Rule in the form of i ::= a starting without i
							if (rr->addr->serial == i->serial && rr->addr->serial != rr->addr->next->serial) {
								char newR[BUFSIZ];

								buf = Rule2String(rr->addr);
								rLen = strlen(buf);
								strcpy(newR, buf);
								free(buf);
								newR[rLen++] = 0x20;
								strcpy(newR + rLen, newSymbol);
								gRules = newRule((pRuleNode)getLinkedList(newR, 0, newRuleNode), gRules);

								// Delete the rule rr
								preRi = gRules;
								while (preRi->next != rr) preRi = preRi->next;
								for (pRuleNode pr = rr->addr; pr;) {
									pRuleNode prn = pr;
									pr = pr->next;
									free(prn->symbol);
									free(prn);
								}
								preRi->next = rr->next;
								if (rr == ri) ri = preRi;
								free(rr);
								rr = preRi;
							}
						}

						deleted = 1;
					}
				}

				// Delete all rules that indicates a direct left recursion of i
				for (pRule ri = r; ri; ri = ri->next) {
					if (ri->addr->serial == i->serial) {
						preRi = gRules;
						while (preRi->next != ri) preRi = preRi->next;
						for (pRuleNode pr = ri->addr; pr;) {
							pRuleNode prn = pr;
							pr = pr->next;
							free(prn->symbol);
							free(prn);
						}
						preRi->next = ri->next;
						if (ri == r) r = preRi;
						free(ri);
						ri = preRi;
					}
				}

				rule_start = gRules;
			}
		}
	}
}