本文整理汇总了C++中xml::Element类的典型用法代码示例。如果您正苦于以下问题:C++ Element类的具体用法?C++ Element怎么用?C++ Element使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _analyzeXML
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
void LNFXManager::_analyzeXML( const char* xml, size_t size )
{
XML::Document xmlDoc;
xmlDoc.Parse( xml, size );
// まずは Technique → Pass と作成して、コンパイルする。この中で Variable も作る
XML::Element* xmlElement = xmlDoc.FirstChildElement();
while ( xmlElement != NULL )
{
// <Technique>
if ( strcmp( xmlElement->Name(), TechniqueElementName ) == 0 ) {
_analyzeXMLTechniqueElement( xmlElement );
}
xmlElement = xmlElement->NextSiblingElement();
}
// 次に、作成済みの Variable にアノテーションを割り振る
xmlElement = xmlDoc.FirstChildElement();
while ( xmlElement != NULL )
{
// <Variable>
if ( strcmp( xmlElement->Name(), VariableElementName ) == 0 ) {
_analyzeXMLVariableElement( xmlElement );
}
xmlElement = xmlElement->NextSiblingElement();
}
}
示例2: 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);
}
示例3: ExceptionInvalidArgument
/*!
* Unsafe load
*
* \throws ExceptionProtocol the content of the vector is not serializable
* \throws ExceptionInvalidArgument not a Vector
* \throws ExceptionRuntime impossible to read an XML element
* \throws ExceptionNotFound unknown type
*
* \param[in] el the element to load
*/
void Vector::Deserialize(xml::Element &el)
{
if (el.GetValue() != getClassName())
{
throw ExceptionInvalidArgument(StringUTF8("void Vector::Deserialize(xml::Element &el): ") +
_("Wrong XML element."));
}
std::multimap<int, SObject> xmllist;
for (xml::Element te = el.BeginElement(); te != el.EndElement(); ++te)
{
SObject d(nullptr);
try
{
d = DataFactory::CreateData(te);
}
catch (crn::Exception &)
{ // XXX throw?
CRNWarning(String(U"void Vector::Deserialize"
U"(xml::Element &el): ") + String(_("Unknown XML element: ")) +
te.GetValue());
}
if (!d)
continue;
int index;
try { index = te.GetAttribute<int>("vector_index", false); } catch (...) { index = int(xmllist.size()); }
xmllist.insert(std::make_pair(index, d));
}
Clear();
for (auto & elem : xmllist)
data.push_back(elem.second);
ShrinkToFit();
}
示例4: parseStmtList
/***************************************************************
* Function: CodeParser::parseStmtList()
* Purpose : Parse the XML code of a statement list
* Initial : Maxime Chevalier-Boisvert on November 7, 2008
****************************************************************
Revisions and bug fixes:
*/
StmtSequence* CodeParser::parseStmtList(const XML::Element* pElement)
{
// Create a statement vector to store the statements
StmtSequence::StmtVector stmtVector;
// For each child element
for (size_t i = 0; i < pElement->getNumChildren(); ++i)
{
// Get this child element
XML::Element* pChildElement = pElement->getChildElement(i);
// If this is a variable declaration
if (pChildElement->getName() == "VariableDecl")
{
// Ignore for now
continue;
}
// Parse this statement
Statement* pStmt = parseStatement(pChildElement);
// Add the statement to the vector
stmtVector.push_back(pStmt);
}
// Return a new sequence statement
return new StmtSequence(stmtVector);
}
示例5: _analyzeXMLVariableElement
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
void LNFXManager::_analyzeXMLVariableElement( XML::Element* xmlElement )
{
// 属性
const char* attrName = xmlElement->Attribute( NameAttributeName );
const char* attrSemantic = xmlElement->Attribute( SemanticAttributeName );
const bool attrShared = xmlElement->BoolAttribute( SharedAttributeName );
const char* attrTexture = xmlElement->Attribute(TextureAttributeName);
LN_THROW_InvalidFormat(attrName);
// 適用試行
IAnnotatedObject* var = mBuilder->OnTrySetVariableParam( attrName, attrSemantic, attrShared, attrTexture );
if ( var != NULL )
{
// 子要素
XML::Element* xmlChild = xmlElement->FirstChildElement();
while ( xmlChild != NULL )
{
// <Annotation>
if ( strcmp( xmlChild->Name(), AnnotationElementName ) == 0 ) {
_analyzeXMLAnnotationElement( xmlChild, var );
}
xmlChild = xmlChild->NextSiblingElement();
}
}
}
示例6: ExceptionInvalidArgument
/*!
* Initializes the object from an XML element. Unsafe.
*
* \throws ExceptionInvalidArgument not a StringUTF8
* \throws ExceptionDomain no CDATA found
*
* \param[in] el the XML element to read
*/
void StringUTF8::Deserialize(xml::Element &el)
{
if (el.GetValue() != "StringUTF8")
{
throw ExceptionInvalidArgument(StringUTF8("void StringUTF8::deserialize(xml::Element &el): ") +
_("Wrong XML element."));
}
xml::Node c(el.GetFirstChild());
if (!c)
return; // no content
xml::Text t(c.AsText()); // may throw
*this = t.GetValue();
ShrinkToFit();
}
示例7: parseScript
/***************************************************************
* Function: CodeParser::parseScript()
* Purpose : Parse the XML code of a script
* Initial : Maxime Chevalier-Boisvert on November 4, 2008
****************************************************************
Revisions and bug fixes:
*/
IIRNode* CodeParser::parseScript(const XML::Element* pElement)
{
// Declare a pointer for the sequence statement
StmtSequence* pSequenceStmt = NULL;
// 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 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());
}
}
// If the statement list is missing, throw an exception
if (pSequenceStmt == NULL)
throw XML::ParseError("Missing statement list", pElement->getTextPos());
// Create and return a new program function object
return new ProgFunction(
"",
ProgFunction::ParamVector(),
ProgFunction::ParamVector(),
ProgFunction::FuncVector(),
pSequenceStmt,
true
);
}
示例8: parseLambdaExpr
/***************************************************************
* Function: CodeParser::parseLambdaExpr()
* Purpose : Parse the XML code of a lambda expression
* Initial : Maxime Chevalier-Boisvert on February 25, 2009
****************************************************************
Revisions and bug fixes:
*/
Expression* CodeParser::parseLambdaExpr(const XML::Element* pElement)
{
// Create a vector for the input parameters
LambdaExpr::ParamVector inParams;
// Declare a pointer for the body expression
Expression* pBodyExpr = NULL;
// For each child element
for (size_t i = 0; i < pElement->getNumChildren(); ++i)
{
// Get a pointer to this child element
XML::Element* pChildElem = pElement->getChildElement(i);
// If this is a symbol
if (pChildElem->getName() == "Name")
{
// Parse the symbol and add it to the input parameters
inParams.push_back(SymbolExpr::getSymbol(pChildElem->getStringAttrib("nameId")));
}
// Otherwise, it must be the body expression
else
{
// If the body expression was already parsed
if (pBodyExpr != NULL)
{
// Throw an exception
throw XML::ParseError("Duplicate body expression", pChildElem->getTextPos());
}
// Parse the body expression
pBodyExpr = parseExpression(pChildElem);
}
}
// If no body expression was found
if (pBodyExpr == NULL)
{
// Throw an exception
throw XML::ParseError("No body expression found", pElement->getTextPos());
}
// Create and return the new lambda expression
return new LambdaExpr(
inParams,
pBodyExpr
);
}
示例9: udel
/*!
* Internal. Initializes some internal data from an XML element.
*
* \param[in] el the element that contains the serialized object
*/
void Savable::deserialize_internal_data(xml::Element &el)
{
// read name if any
const StringUTF8 nam = el.GetAttribute<StringUTF8>("name");
xml::Element udel(el.GetFirstChildElement("Map"));
while (udel)
{ // look for a map containing user data
const StringUTF8 role = udel.GetAttribute<StringUTF8>("role");
// check role
if (role == USERDATA_NAME)
{ // found the user data
if (!user_data)
{ // create the object if needed
user_data.reset(new Map());
}
else
{ // clear the current user data if needed
user_data->Clear();
}
// read the user data and quit the method
user_data->Deserialize(udel);
return;
}
udel = udel.GetNextSiblingElement("Map");
}
}
示例10: Init
void PostgresProvider::Init(const xml::Element& rConfig)
{
// initialize connection
const xml::Element& rConnection = rConfig.GetChildElementByName("connection");
m_pImpl->m_sHost = rConnection.GetChildElementByName("host").GetTextValue();
m_pImpl->m_sPort = rConnection.GetChildElementByName("port").GetTextValue();
m_pImpl->m_sDataBase = rConnection.GetChildElementByName("db").GetTextValue();
m_pImpl->m_sLogin = rConnection.GetChildElementByName("login").GetTextValue();
m_pImpl->m_sPassword = rConnection.GetChildElementByName("password").GetTextValue();
STAFF_ASSERT(!m_pImpl->m_pConn, "Already connected");
m_pImpl->m_pConn = PQsetdbLogin(m_pImpl->m_sHost.c_str(), m_pImpl->m_sPort.c_str(), "", "",
m_pImpl->m_sDataBase.c_str(), m_pImpl->m_sLogin.c_str(),
m_pImpl->m_sPassword.c_str());
STAFF_ASSERT(m_pImpl->m_pConn, "Failed to set db login");
if (PQstatus(m_pImpl->m_pConn) != CONNECTION_OK)
{
std::string sError = std::string("Failed to login: ") + PQerrorMessage(m_pImpl->m_pConn);
PQfinish(m_pImpl->m_pConn);
m_pImpl->m_pConn = NULL;
STAFF_THROW_ASSERT(sError);
}
int nResult = PQsetClientEncoding(m_pImpl->m_pConn, "UTF8");
STAFF_ASSERT(nResult == 0, std::string("error setting encoding: ") + PQerrorMessage(m_pImpl->m_pConn));
}
示例11: el
/*!
* Dumps the object to an XML element. Unsafe.
*/
xml::Element FeatureExtractorProjection::serialize(xml::Element &parent) const
{
xml::Element el(parent.PushBackElement(GetClassName()));
el.SetAttribute("directions", int(dirs));
el.SetAttribute("size", size);
el.SetAttribute("maxval", maxval);
return el;
}
示例12: serialize_internal_data
/*!
* Internal. Dumps some internal data to an XML element.
*
* \param[in] el the element that contains the serialized object
*/
void Savable::serialize_internal_data(xml::Element &el) const
{
el.SetAttribute("name", name.CStr());
if (user_data)
{
xml::Element udel = user_data->Serialize(el);
udel.SetAttribute("role", USERDATA_NAME);
}
}
示例13: showElement
static void showElement(Xml::Element elt, const String& indent="") {
cout << indent << "ELEMENT WITH TAG '" << elt.getElementTag() << "':\n";
// Show attributes
Xml::attribute_iterator ap = elt.attribute_begin();
for (; ap != elt.attribute_end(); ++ap)
cout << indent << " ATTR '" << ap->getName() << "'='"
<< ap->getValue() << "'\n";
// Show all contents
Xml::node_iterator p = elt.node_begin();
for (; p != elt.node_end(); ++p) {
cout << indent << p->getNodeTypeAsString() << endl;
if (p->getNodeType() == Xml::ElementNode)
showElement(Xml::Element::getAs(*p), indent + " ");
}
cout << indent << "END OF ELEMENT.\n";
}
示例14: writeCppNs
void writeCppNs(xml::Element& node, const std::string& ns)
{
const std::string& realNs = (ns.substr(0, 2) == "::") ? ns.substr(2) : ns;
std::string startNs;
std::string endNs;
std::string::size_type pos = 0;
std::string::size_type prevPos = 0;
while((pos = realNs.find("::", pos)) != std::string::npos) {
startNs += "namespace " + realNs.substr(prevPos, pos - prevPos) + " {\n";
endNs += "}\n";
pos += 2;
prevPos = pos;
}
node.createElement("startCppNs", startNs);
node.createElement("endCppNs", endNs);
}
示例15: _analyzeXMLPassElement
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
void LNFXManager::_analyzeXMLPassElement( XML::Element* xmlElement, IAnnotatedObject* parentTech )
{
// 属性
const char* attrName = xmlElement->Attribute(NameAttributeName);
LN_THROW_InvalidFormat(attrName);
IAnnotatedObject* pass = mBuilder->OnCreatePass( parentTech, attrName );
// 子要素
XML::Element* xmlChild = xmlElement->FirstChildElement();
while ( xmlChild != NULL )
{
// <VertexShader>
if ( strcmp( xmlChild->Name(), VertexShaderElementName ) == 0 ) {
attrName = xmlChild->Attribute( EntryPointAttributeName );
GLSLCode* code = _findShaderCode(attrName);
LN_THROW_InvalidFormat(code);
mBuilder->OnCreateVertexShader( pass, code->Code.c_str(), code->Code.size() );
}
// <PixelShader>
else if ( strcmp( xmlChild->Name(), PixelShaderElementName ) == 0 ) {
attrName = xmlChild->Attribute( EntryPointAttributeName );
GLSLCode* code = _findShaderCode(attrName);
LN_THROW_InvalidFormat(code);
mBuilder->OnCreatePixelShader( pass, code->Code.c_str(), code->Code.size() );
}
// <RenderState>
else if ( strcmp( xmlChild->Name(), RenderStateElementName ) == 0 ) {
attrName = xmlChild->Attribute(NameAttributeName);
LN_THROW_InvalidFormat(attrName);
const char* value = xmlChild->Attribute( ValueAttributeName );
mBuilder->OnSetRenderState( pass, attrName, value );
}
// <Annotation>
else if ( strcmp( xmlChild->Name(), AnnotationElementName ) == 0 ) {
_analyzeXMLAnnotationElement( xmlChild, pass );
}
xmlChild = xmlChild->NextSiblingElement();
}
// link
mBuilder->OnEndPass( pass );
}