MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / addNewElement

Method addNewElement

Engine/source/console/SimXMLDocument.cpp:982–1026  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Create a new element and set to child of current stack element. New element is placed on top of element stack. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

980// New element is placed on top of element stack.
981// -----------------------------------------------------------------------------
982void SimXMLDocument::addNewElement(const char* rName)
983{
984 tinyxml2::XMLElement* cElement = m_qDocument->NewElement(rName);
985 tinyxml2::XMLNode* pStackTop = 0;
986 if(m_paNode.empty())
987 {
988 pStackTop = m_qDocument->InsertEndChild( cElement );
989 if(!pStackTop)
990 {
991 return;
992 }
993 m_paNode.push_back(pStackTop);
994 return;
995 }
996
997 const S32 iParentElement = m_paNode.size() - 2;
998 if(iParentElement < 0)
999 {
1000 pStackTop = m_qDocument->InsertEndChild( cElement );
1001 if(!pStackTop)
1002 {
1003 return;
1004 }
1005 m_paNode.push_back(pStackTop);
1006 return;
1007 }
1008 else
1009 {
1010 tinyxml2::XMLNode* pNode = m_paNode[iParentElement];
1011 if(!pNode)
1012 {
1013 return;
1014 }
1015 pStackTop = pNode->InsertEndChild( cElement );
1016 if(!pStackTop)
1017 {
1018 return;
1019 }
1020
1021 // Overwrite top stack position.
1022 const S32 iFinalElement = m_paNode.size() - 1;
1023 m_paNode[iFinalElement] = pStackTop;
1024 //pNode = pStackTop;
1025 }
1026}
1027
1028DefineEngineMethod( SimXMLDocument, addNewElement, void, ( const char* name ),,
1029 "@brief Create a new element with the given name as child of current Element's "

Callers 1

SimXMLDocument.cppFile · 0.80

Calls 5

NewElementMethod · 0.80
InsertEndChildMethod · 0.80
emptyMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected