当前位置: 首页>>代码示例>>C++>>正文


C++ AttributeSet::Contains方法代码示例

本文整理汇总了C++中AttributeSet::Contains方法的典型用法代码示例。如果您正苦于以下问题:C++ AttributeSet::Contains方法的具体用法?C++ AttributeSet::Contains怎么用?C++ AttributeSet::Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AttributeSet的用法示例。


在下文中一共展示了AttributeSet::Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Execute

void LeafSubsetCallback::Execute(ExprVectorPositions selection, bool &continueGenerating)
{
	MatchLeafCallback leafCallback;
	leafCallback.Initialize(expression, pattern, calculator, parentCallback);
	leafCallback.InitializeLeaf(subsetGenerator, curPatternLeaf);
	if(selection.size() != 1)
	{
		Definition *functionDef = pattern->FunctionDefinition(calculator);
		AttributeSet attributes;
		if(functionDef)
			attributes = functionDef->Attributes();
		auto_ptr<Expression> sequence(new Expression);
		sequence->Leaves().reserve(selection.size());
		for(ExprVectorPositions::const_iterator leaf = selection.begin(); leaf != selection.end(); ++leaf)
			sequence->AppendLeaf(**leaf);
		if(attributes.Contains(atFlat) && selection.size() > 1)
		{
			sequence->Head(pattern->Head()->Clone());
			continueGenerating = sequence->Matches(*curPatternLeaf, calculator, subs, true, leafCallback);
			delete sequence->Head();
			sequence->Head(0);
			if(!continueGenerating)
			{
				sequence->Leaves().clear();
				return;
			}
		}
		sequence->Head(new Expression("Sequence"));
		continueGenerating = sequence->Matches(*curPatternLeaf, calculator, subs, true, leafCallback);
		sequence->Leaves().clear();
	}
	else
	{
		Expression *leaf = **selection.begin();
		continueGenerating = leaf->Matches(*curPatternLeaf, calculator, subs, true, leafCallback);
	}
}
开发者ID:dubrousky,项目名称:Mathador,代码行数:37,代码来源:LeafSubsetCallback.cpp

示例2: Evaluate

// Evaluates an expression. Considers all rules etc. In some cases there are simply
// no changes possible and the expression remains unchanged (e.g. a+b).
void Expression::Evaluate(Calculator *calculator, int32 recursions)
{
	// Since the expression is expected to be already structured, it must have a head.
	if(!head)
		throw DefinitionException("Expression::Evaluate: Expression has no head.");
	if(recursions > Max_Evaluate_Recursions)
		throw LimitationException("Maximum number of recursive definitions reached.");
	head->Evaluate(calculator, recursions);
	// If Expression is a symbol
	Definition *symbolDef = SymbolDefinition(calculator);
	if(symbolDef)
	{
		// Look if value is defined
		if(symbolDef->Value())
		{
			bool changed = !SameExpression(symbolDef->Value());
			AssignCloned(symbolDef->Value());
			if(changed)
				Evaluate(calculator, recursions + 1);
		}
	}
	// If head is a pure function
	if(head->FunctionName() == "Function" && head->LeafCount() == 1)
	{
		ExprPtr body(head->leaves.at(0));
		body->SubstituteSlots(leaves);
		body->Evaluate(calculator, recursions);
		head->leaves.clear();
		MoveNotCloned(body);
	}
	// If Expression is Function call
	Definition *def = FunctionDefinition(calculator);
	if(def)
	{
		AttributeSet attributes = def->Attributes();
		// Evaluate child leaves if no Hold attribute
		if(!attributes.Contains(atHoldAll) && !attributes.Contains(atHoldAllComplete))
		{
			if(!attributes.Contains(atHoldFirst))
				if(!leaves.empty())
					leaves.at(0)->Evaluate(calculator, recursions);
			if(!attributes.Contains(atHoldRest))
				if(leaves.size() > 1)
					for(ExprVector::const_iterator leaf = leaves.begin()+1; leaf != leaves.end(); ++leaf)
						(*leaf)->Evaluate(calculator, recursions);
		}
		// Flatten out sequences
		if(!attributes.Contains(atSequenceHold))
		{
			Flatten("Sequence");
		}
		// Apply down values
		for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
		{
			Definition *def(0);
			if((*leaf)->SymbolHead())
				def = (*leaf)->SymbolDefinition(calculator);
			else if((*leaf)->IsFunctionCall())
				def = (*leaf)->FrontFunctionDefinition(calculator);
			if(def)
			{
				bool changed(false);
				if(def->ApplyUpValues(this, calculator, &changed) && changed)
				{
					Evaluate(calculator, recursions + 1);
					return;
				}
			}
		}
		// Apply Flat attribute
		if(attributes.Contains(atFlat))
		{
			Flatten(FunctionName());
		}
		// Apply OneIdentity attribute
		if(attributes.Contains(atOneIdentity))
		{
			if(ApplyOneIdentity())
				return;
		}
		// Apply Listable attribute
		if(attributes.Contains(atListable))
		{
			// Determine resulting list length, check if there are lists with different lengths
			bool listFound(false);
			ExprVector::size_type listSize(0);
			for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
				if((*leaf)->FunctionName() == "List")
					if(!listFound)
					{
						listSize = (*leaf)->LeafCount();
						listFound = true;
					}
					else
						if(listSize != (*leaf)->LeafCount())
							throw EvaluateException("Listable operation requires lists of the same length.");
			// Construct resulting list
			if(listFound)
//.........这里部分代码省略.........
开发者ID:dubrousky,项目名称:Mathador,代码行数:101,代码来源:Expression.cpp


注:本文中的AttributeSet::Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。