CNodeLiveWriterRef CNodeLiveWriter::AddChildNode( const char* pChildName ) { assert( !m_done && m_valid ); m_totalAmountChildren++; // only 1 child can be not done at any time if (!m_children.empty()) { CNodeLiveWriter* pPreviousChild = m_Writer.GetNodeLive( m_children.back()); if (!pPreviousChild->IsDone()) pPreviousChild->Done(); } assert( m_children.size() <= CHILDREN_PER_BLOCK ); if (m_children.size() == CHILDREN_PER_BLOCK) CompactPendingChildren(); // CNodeLiveWriter* pChild = m_Writer.CreateAndAddLiveNode( pChildName ); m_children.push_back( pChild->GetID()); pChild->SetParent( GetID()); return CNodeLiveWriterRef( m_Writer, pChild->GetID()); }
void CWriter::Init( const char* pNameRootNode, const char* pFileName ) { m_isSavingIntoFile = pFileName!=NULL; bool useStreaming = m_isSavingIntoFile; m_mainBuffer.Init( this, useStreaming ); m_tableTags.Init( this ); m_tableAttrNames.Init( this ); m_tableStrData.Init( this ); m_tableStrDataConstants.Init( this ); m_tableAttrSets.Init( this ); if (m_isSavingIntoFile) { #ifdef XMLCPB_DEBUGUTILS CDebugUtils::SetLastFileNameSaved( pFileName ); #endif #ifdef XMLCPB_COLLECT_STATS CNodeLiveWriter::m_stats.Reset(); CAttrWriter::m_statistics.Reset(); #endif m_tableStrDataConstants.CreateStringsFromConstants(); { ScopedSwitchToGlobalHeap switchToGlobalHeap; // This object may live beyond the end of level shutdown. Use global heap for allocations m_compressor = new CZLibCompressor(pFileName); // Don't delete this when finished, it is held by the compressor thread until finished with and destroyed by it. } } CNodeLiveWriter* pRoot = CreateAndAddLiveNode( pNameRootNode ); assert( pRoot->GetID()==XMLCPB_ROOTNODE_ID ); }