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


C++ Element::getNumChildren方法代码示例

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


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

示例1: parseCellArrayExpr

/***************************************************************
* Function: CodeParser::parseCellArrayExpr()
* Purpose : Parse the XML code of a cell array expression
* Initial : Maxime Chevalier-Boisvert on February 23, 2009
****************************************************************
Revisions and bug fixes:
*/
Expression* CodeParser::parseCellArrayExpr(const XML::Element* pElement)
{
	// Declare a vector to store the rows
	CellArrayExpr::RowVector rowVector;

	// For each child element
	for (size_t i = 0; i < pElement->getNumChildren(); ++i)
	{
		// Declare a row to store elements
		CellArrayExpr::Row row;

		// Get a reference to this child element
		XML::Element* pRowElem = pElement->getChildElement(i);

		// If this is not a row element, throw an exception
		if (pRowElem->getName() != "Row")
			throw XML::ParseError("Invalid element found in cell array expression", pRowElem->getTextPos());

		// For each expression in this row
		for (size_t j = 0; j < pRowElem->getNumChildren(); ++j)
		{
			// Parse the expression and add it to the row
			row.push_back(parseExpression(pRowElem->getChildElement(j)));
		}

		// Add the row to the vector
		rowVector.push_back(row);
	}

	// Create and return the cell array expression
	return new CellArrayExpr(rowVector);
}
开发者ID:Sable,项目名称:mcvm,代码行数:39,代码来源:parser.cpp

示例2: parseAssignStmt

/***************************************************************
* Function: CodeParser::parseAssignStmt()
* Purpose : Parse the XML code of an assignment statement
* Initial : Maxime Chevalier-Boisvert on November 5, 2008
****************************************************************
Revisions and bug fixes:
*/
Statement* CodeParser::parseAssignStmt(const XML::Element* pElement)
{
	// Get the element corresponding to the left-expression
	XML::Element* pLeftElem = pElement->getChildElement(0);

	// Create a vector to store the left expressions
	AssignStmt::ExprVector leftExprs;

	// If the left expression is a matrix expression
	if (pLeftElem->getName() == "MatrixExpr")
	{
		// If the number of rows is not 1, throw an exception
		if (pLeftElem->getNumChildren() != 1)
			throw XML::ParseError("invalid matrix expression on assignment lhs");

		// Get the row element
		XML::Element* pRowElem = pLeftElem->getChildElement(0);

		// For each left expression element
		for (size_t i = 0; i < pRowElem->getNumChildren(); ++i)
		{
			// Get the child element for this expression
			XML::Element* pExprElem = pRowElem->getChildElement(i);

			// Parse this left-expression
			leftExprs.push_back(parseExpression(pExprElem));
		}
	}
	else
	{
		// Parse the left expression directly
		leftExprs.push_back(parseExpression(pLeftElem));
	}

	// Parse the right expression
	Expression* pRightExpr = parseExpression(pElement->getChildElement(1));

	// Get the output suppression flag
	bool suppressOut = pElement->getBoolAttrib("outputSuppressed");

	// Create and return the new assignment statement object
	return new AssignStmt(leftExprs, pRightExpr, suppressOut);
}
开发者ID:Sable,项目名称:mcvm,代码行数:50,代码来源:parser.cpp

示例3: parseFunction

/***************************************************************
* Function: CodeParser::parseFunction()
* Purpose : Parse the XML code of a function
* Initial : Maxime Chevalier-Boisvert on November 3, 2008
****************************************************************
Revisions and bug fixes:
*/
ProgFunction* CodeParser::parseFunction(const XML::Element* pElement)
{
	// Get the function name
	std::string funcName = pElement->getStringAttrib("name");

	// Declare a pointer for the sequence statement
	StmtSequence* pSequenceStmt = NULL;

	// Declare vectors for the input and output parameters
	ProgFunction::ParamVector inParams;
	ProgFunction::ParamVector outParams;

	// Declare a vector for the nested function list
	ProgFunction::FuncVector nestedFuncs;

	// For each child element
	for (size_t i = 0; i < pElement->getNumChildren(); ++i)
	{
		// Get a pointer to this element
		XML::Element* pFuncElement = pElement->getChildElement(i);

		// If this is a symbol table
		if (pFuncElement->getName() == "Symboltable")
		{
			// Ignore for now
		}

		// If this is a parameter declaration list
		else if (pFuncElement->getName() == "ParamDeclList")
		{
			// Ignore for now
		}

		// If this is an input parameter list
		else if (pFuncElement->getName() == "InputParamList")
		{
			// For each child element
			for (size_t i = 0; i < pFuncElement->getNumChildren(); ++i)
			{
				// Get the parameter name
				const std::string& paramName = pFuncElement->getChildElement(i)->getStringAttrib("nameId");

				// Add the parameter to the list
				inParams.push_back(SymbolExpr::getSymbol(paramName));
			}
		}

		// If this is an output parameter list
		else if (pFuncElement->getName() == "OutputParamList")
		{
			// For each child element
			for (size_t i = 0; i < pFuncElement->getNumChildren(); ++i)
			{
				// Get the parameter name
				const std::string& paramName = pFuncElement->getChildElement(i)->getStringAttrib("nameId");

				// Add the parameter to the list
				outParams.push_back(SymbolExpr::getSymbol(paramName));
			}
		}

		// If this is a nested function list
		else if (pFuncElement->getName() == "NestedFunctionList")
		{
			// For each child element
			for (size_t i = 0; i < pFuncElement->getNumChildren(); ++i)
			{
				// Parse this function declaration
				ProgFunction* pFunction = parseFunction(pFuncElement->getChildElement(i));

				// Add the nested function to the list
				nestedFuncs.push_back(pFunction);
			}
		}

		// If this is the statement list
		else if (pFuncElement->getName() == "StmtList")
		{
			// If the statement list was already encountered, throw an exception
			if (pSequenceStmt != NULL)
				throw XML::ParseError("Duplicate statement list", pElement->getTextPos());

			// Parse the statement list
			pSequenceStmt = parseStmtList(pFuncElement);
		}

		// Otherwise
		else
		{
			// This is an invalid element type, throw an exception
			throw XML::ParseError("Invalid element type in script: \"" + pFuncElement->getName() + "\"", pFuncElement->getTextPos());
		}
	}
//.........这里部分代码省略.........
开发者ID:Sable,项目名称:mcvm,代码行数:101,代码来源:parser.cpp


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