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

Method addNewElement

Engine/source/console/SimXMLDocument.cpp:963–1010  ·  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

961// New element is placed on top of element stack.
962// -----------------------------------------------------------------------------
963void SimXMLDocument::addNewElement(const char* rName)
964{
965 TiXmlElement cElement( rName );
966 TiXmlElement* pStackTop = 0;
967 if(m_paNode.empty())
968 {
969 pStackTop = dynamic_cast<TiXmlElement*>
970 (m_qDocument->InsertEndChild( cElement ));
971 if(!pStackTop)
972 {
973 return;
974 }
975 m_paNode.push_back(pStackTop);
976 return;
977 }
978
979 const S32 iParentElement = m_paNode.size() - 2;
980 if(iParentElement < 0)
981 {
982 pStackTop = dynamic_cast<TiXmlElement*>
983 (m_qDocument->InsertEndChild( cElement ));
984 if(!pStackTop)
985 {
986 return;
987 }
988 m_paNode.push_back(pStackTop);
989 return;
990 }
991 else
992 {
993 TiXmlElement* pNode = m_paNode[iParentElement];
994 if(!pNode)
995 {
996 return;
997 }
998 pStackTop = dynamic_cast<TiXmlElement*>
999 (pNode->InsertEndChild( cElement ));
1000 if(!pStackTop)
1001 {
1002 return;
1003 }
1004
1005 // Overwrite top stack position.
1006 const S32 iFinalElement = m_paNode.size() - 1;
1007 m_paNode[iFinalElement] = pStackTop;
1008 //pNode = pStackTop;
1009 }
1010}
1011
1012DefineEngineMethod( SimXMLDocument, addNewElement, void, ( const char* name ),,
1013 "@brief Create a new element with the given name as child of current Element's "

Callers 1

SimXMLDocument.cppFile · 0.80

Calls 4

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

Tested by

no test coverage detected