if(m_ChunksOwnsPointers){nldebug("Not parsed, or disowned");return;}// Must have local ownership
if(m_Chunks.size()==0){nlwarning("Already cleaned (or did not build due to coding error)");return;}// Already cleaned
if(m_Chunks.begin()->first!=NLMAXFILE_APP_DATA_HEADER_CHUNK_ID){nlerror("Bad id %x, expected %x",(uint32)m_Chunks.begin()->first,NLMAXFILE_APP_DATA_HEADER_CHUNK_ID);return;}// Cannot happen, because we won't have local ownership if parsing failed
deletem_Chunks.begin()->second;// Delete the header chunk, since we own it
if(m_Chunks.size()!=0){nldebug("Not parsed, or disowned");return;}
// Set up the header in the chunks container
CStorageValue<uint32>*headerSize=newCStorageValue<uint32>();// Owned locally, not by m_Chunks
@ -211,12 +214,15 @@ void CAppData::disown()
if(m_ChunksOwnsPointers){nldebug("Not parsed");}
if(!m_ChunksOwnsPointers&&(m_Chunks.size()!=(m_Entries.size()+1))){nlerror("Not built");return;}// If chunks is not the owner, built chunks must match the parsed data
// Inheriting classes take control from here on, they should check
// m_ChunksOwnsPointers to be false before taking action, in case
// a subclass called disown due to failure.
}
voidCSceneClass::clean()
{
CStorageContainer::clean();
if(m_ChunksOwnsPointers){nldebug("Not parsed, or disowned");return;}// Must have local ownership, parsing may have failed
if(m_Chunks.size()==0&&m_OrphanedChunks.size()!=0){nlwarning("Already cleaned");return;}// Already cleaned, should not call twice, not reliable because not all chunks have child chunks
if(m_Chunks.size()!=0){nldebug("Not parsed, or disowned");return;}// Don't have local ownership, parsing may have failed, the built version is implicitly up to date
// Build the orphan chunks (this is a little trick to do it this
// way here, don't do this from subclasses)
CStorageContainer::build(version);
// Set the insertion pointer before the orphans
m_PutChunkInsert=m_Chunks.begin();
// Inheriting classes take control from here on, so the build is
// called to owned subclasses from the putChunk function.
}
voidCSceneClass::disown()
{
if(m_ChunksOwnsPointers){nldebug("Not parsed");}
if(!m_ChunksOwnsPointers&&(m_Chunks.size()<m_OrphanedChunks.size())){nlerror("Not built");return;}// If chunks is not the owner, built chunks must match the parsed data. This check is not fully reliable
/// Use during parsing. Gets the chunk with specified id. Warnings when chunks are skipped may be elevated to errors. Remaining orphaned chunks will be appended after chunks that are written by the classes. Returns NULL when the chunk does not exist. Empty chunks are often not written by classes. You have ownership over the chunk until it is disowned. In case that the chunk cannot be parsed, call disown and abort parsing. If this function returns NULL it is also possible that the parsing has been aborted when m_ChunksOwnsPointers is true
IStorageObject*getChunk(uint16id);
/// Use during file build. Adds a chunk to the chunks that will be written to the file. Build is called when a chunk is passed through