Changed: #1440 Stricter code

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent 49aff3b7d7
commit 5fd3d7f275

@ -128,7 +128,7 @@ std::string CAppData::getClassName()
void CAppData::toString(std::ostream &ostream, const std::string &pad) void CAppData::toString(std::ostream &ostream, const std::string &pad)
{ {
if (ChunksOwnsPointers) if (m_ChunksOwnsPointers)
{ {
CStorageContainer::toString(ostream, pad); CStorageContainer::toString(ostream, pad);
} }
@ -155,16 +155,16 @@ void CAppData::parse(uint16 version, TParseLevel level)
CStorageContainer::parse(version, level); CStorageContainer::parse(version, level);
// Verify // Verify
if (Chunks.size() < 2) { nlwarning("Bad container size %i", Chunks.size()); disown(); return; } if (m_Chunks.size() < 2) { nlwarning("Bad container size %i", m_Chunks.size()); disown(); return; }
// Header // Header
TStorageObjectContainer::iterator it = Chunks.begin(); TStorageObjectContainer::iterator it = m_Chunks.begin();
if (it->first != NLMAXFILE_APP_DATA_HEADER_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_HEADER_CHUNK_ID); disown(); return; } if (it->first != NLMAXFILE_APP_DATA_HEADER_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_HEADER_CHUNK_ID); disown(); return; }
uint32 headerSize = static_cast<CStorageValue<uint32> *>(it->second)->Value; uint32 headerSize = static_cast<CStorageValue<uint32> *>(it->second)->Value;
++it; ++it;
// Entries // Entries
for (TStorageObjectContainer::iterator end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::iterator end = m_Chunks.end(); it != end; ++it)
{ {
if (it->first != NLMAXFILE_APP_DATA_ENTRY_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_CHUNK_ID); disown(); return; } if (it->first != NLMAXFILE_APP_DATA_ENTRY_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_CHUNK_ID); disown(); return; }
CAppDataEntry *entry = static_cast<CAppDataEntry *>(it->second); CAppDataEntry *entry = static_cast<CAppDataEntry *>(it->second);
@ -177,33 +177,33 @@ void CAppData::parse(uint16 version, TParseLevel level)
if (m_Entries.size() != headerSize) { nlwarning("Entry count %i does not match header %i", m_Entries.size(), headerSize); disown(); return; } if (m_Entries.size() != headerSize) { nlwarning("Entry count %i does not match header %i", m_Entries.size(), headerSize); disown(); return; }
// Take local ownership // Take local ownership
ChunksOwnsPointers = false; m_ChunksOwnsPointers = false;
} }
} }
void CAppData::clean() void CAppData::clean()
{ {
if (ChunksOwnsPointers) { nldebug("Not parsed"); return; } // Must have local ownership if (m_ChunksOwnsPointers) { nldebug("Not parsed"); return; } // Must have local ownership
if (Chunks.size() == 0) { nlwarning("Bad container size"); return; } // Already cleaned if (m_Chunks.size() == 0) { nlwarning("Bad container size"); return; } // Already cleaned
if (Chunks.begin()->first != NLMAXFILE_APP_DATA_HEADER_CHUNK_ID) { nlerror("Bad id %x, expected %x", (uint32)Chunks.begin()->first, NLMAXFILE_APP_DATA_HEADER_CHUNK_ID); return; } // Cannot happen, because we won't have local ownership if parsing failed 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
delete Chunks.begin()->second; // Delete the header chunk, since we own it delete m_Chunks.begin()->second; // Delete the header chunk, since we own it
Chunks.clear(); // Clear the remaining chunks m_Chunks.clear(); // Clear the remaining chunks
} }
void CAppData::build(uint16 version) void CAppData::build(uint16 version)
{ {
// Must be clean first // Must be clean first
if (!ChunksOwnsPointers && Chunks.size() != 0) { nlerror("Not cleaned"); return; } if (!m_ChunksOwnsPointers && m_Chunks.size() != 0) { nlerror("Not cleaned"); return; }
if (Chunks.size() != 0) { nldebug("Not parsed"); return; } if (m_Chunks.size() != 0) { nldebug("Not parsed"); return; }
// Set up the header in the chunks container // Set up the header in the chunks container
CStorageValue<uint32> *headerSize = new CStorageValue<uint32>(); // Owned locally, not by Chunks CStorageValue<uint32> *headerSize = new CStorageValue<uint32>(); // Owned locally, not by m_Chunks
headerSize->Value = m_Entries.size(); headerSize->Value = m_Entries.size();
Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_HEADER_CHUNK_ID, headerSize)); m_Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_HEADER_CHUNK_ID, headerSize));
// Set up the entries // Set up the entries
for (TMap::iterator it = m_Entries.begin(), end = m_Entries.end(); it != end; ++it) for (TMap::iterator it = m_Entries.begin(), end = m_Entries.end(); it != end; ++it)
Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_CHUNK_ID, it->second)); m_Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_CHUNK_ID, it->second));
// Build all the child chunks // Build all the child chunks
CStorageContainer::build(version); CStorageContainer::build(version);
@ -211,30 +211,30 @@ void CAppData::build(uint16 version)
void CAppData::disown() void CAppData::disown()
{ {
if (ChunksOwnsPointers) { nldebug("Not parsed"); } if (m_ChunksOwnsPointers) { nldebug("Not parsed"); }
if (!ChunksOwnsPointers && (Chunks.size() != (m_Entries.size() + 1))) { nlerror("Not built"); return; } // If chunks is not the owner, built chunks must match the parsed data 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
// NOTE: Chunks must be valid at this point! // NOTE: m_Chunks must be valid at this point!
// Disown all the child chunks // Disown all the child chunks
CStorageContainer::disown(); CStorageContainer::disown();
// Disown locally // Disown locally
m_Entries.clear(); m_Entries.clear();
// Give ownership back // Give ownership back
ChunksOwnsPointers = true; m_ChunksOwnsPointers = true;
} }
void CAppData::init() void CAppData::init()
{ {
// Cannot be init yet // Cannot be init yet
if (!ChunksOwnsPointers) { nlerror("Already parsed"); return; } if (!m_ChunksOwnsPointers) { nlerror("Already parsed"); return; }
if (Chunks.size() != 0) { nlerror("Already built or serialized"); return; } if (m_Chunks.size() != 0) { nlerror("Already built or serialized"); return; }
// We own this // We own this
ChunksOwnsPointers = false; m_ChunksOwnsPointers = false;
} }
const uint8 *CAppData::read(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 &size) const const uint8 *CAppData::read(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 &size) const
{ {
if (ChunksOwnsPointers) { nlwarning("Not parsed"); return NULL; } if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return NULL; }
TKey key(classId, superClassId, subId); TKey key(classId, superClassId, subId);
TMap::const_iterator it = m_Entries.find(key); TMap::const_iterator it = m_Entries.find(key);
if (it == m_Entries.end()) { nldebug("Trying to read non-existant key, this is allowed, returning NULL"); return NULL; } if (it == m_Entries.end()) { nldebug("Trying to read non-existant key, this is allowed, returning NULL"); return NULL; }
@ -244,7 +244,7 @@ const uint8 *CAppData::read(NLMISC::CClassId classId, TSClassId superClassId, ui
uint8 *CAppData::lock(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 capacity) uint8 *CAppData::lock(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 capacity)
{ {
if (ChunksOwnsPointers) { nlwarning("Not parsed"); return NULL; } if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return NULL; }
TKey key(classId, superClassId, subId); TKey key(classId, superClassId, subId);
TMap::const_iterator it = m_Entries.find(key); TMap::const_iterator it = m_Entries.find(key);
CAppDataEntry *appDataEntry; CAppDataEntry *appDataEntry;
@ -267,7 +267,7 @@ uint8 *CAppData::lock(NLMISC::CClassId classId, TSClassId superClassId, uint32 s
void CAppData::unlock(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 size) void CAppData::unlock(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId, uint32 size)
{ {
if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return; }
TKey key(classId, superClassId, subId); TKey key(classId, superClassId, subId);
TMap::const_iterator it = m_Entries.find(key); TMap::const_iterator it = m_Entries.find(key);
if (it == m_Entries.end()) { nlerror("Unlocking non-existant key"); return; } if (it == m_Entries.end()) { nlerror("Unlocking non-existant key"); return; }
@ -288,7 +288,7 @@ void CAppData::fill(NLMISC::CClassId classId, TSClassId superClassId, uint32 sub
void CAppData::erase(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId) void CAppData::erase(NLMISC::CClassId classId, TSClassId superClassId, uint32 subId)
{ {
if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return; }
TKey key(classId, superClassId, subId); TKey key(classId, superClassId, subId);
TMap::const_iterator it = m_Entries.find(key); TMap::const_iterator it = m_Entries.find(key);
if (it == m_Entries.end()) { nldebug("Trying to erase non-existant key, this is allowed, doing nothing"); return; } if (it == m_Entries.end()) { nldebug("Trying to erase non-existant key, this is allowed, doing nothing"); return; }
@ -371,7 +371,7 @@ void CAppDataEntry::toString(std::ostream &ostream, const std::string &pad)
{ {
if (m_Key && m_Value) if (m_Key && m_Value)
{ {
ostream << "(" << getClassName() << ") [" << Chunks.size() << "] PARSED { "; ostream << "(" << getClassName() << ") [" << m_Chunks.size() << "] PARSED { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
ostream << "\n" << pad << "Key: "; ostream << "\n" << pad << "Key: ";
m_Key->toString(ostream, padpad); m_Key->toString(ostream, padpad);
@ -388,10 +388,10 @@ void CAppDataEntry::toString(std::ostream &ostream, const std::string &pad)
void CAppDataEntry::parse(uint16 version, TParseLevel level) void CAppDataEntry::parse(uint16 version, TParseLevel level)
{ {
// CStorageContainer::parse(version, level); // CStorageContainer::parse(version, level);
// if (!ChunksOwnsPointers) { nlwarning("Already parsed"); return; } // if (!m_ChunksOwnsPointers) { nlwarning("Already parsed"); return; }
if (Chunks.size() != 2) { nlwarning("Bad container size"); disown(); return; } if (m_Chunks.size() != 2) { nlwarning("Bad container size"); disown(); return; }
TStorageObjectContainer::iterator it = Chunks.begin(); TStorageObjectContainer::iterator it = m_Chunks.begin();
if (it->first != NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID); disown(); return; } if (it->first != NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID); disown(); return; }
m_Key = static_cast<CAppDataEntryKey *>(it->second); m_Key = static_cast<CAppDataEntryKey *>(it->second);
@ -399,22 +399,22 @@ void CAppDataEntry::parse(uint16 version, TParseLevel level)
if (it->first != NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID); disown(); return; } if (it->first != NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID) { nlwarning("Bad id %x, expected %x", (uint32)it->first, NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID); disown(); return; }
m_Value = static_cast<CStorageRaw *>(it->second); m_Value = static_cast<CStorageRaw *>(it->second);
// ChunksOwnsPointers = false; // m_ChunksOwnsPointers = false;
nlassert(ChunksOwnsPointers); // Never set false here nlassert(m_ChunksOwnsPointers); // Never set false here
} }
void CAppDataEntry::clean() void CAppDataEntry::clean()
{ {
nlassert(false); nlassert(false);
// CStorageContainer::clean(); // CStorageContainer::clean();
// if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } // if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return; }
// Nothing to do here! // Nothing to do here!
} }
void CAppDataEntry::build(uint16 version) void CAppDataEntry::build(uint16 version)
{ {
nlassert(false); nlassert(false);
// if (ChunksOwnsPointers) { nlwarning("Not parsed"); return; } // if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return; }
// Nothing to do here! // Nothing to do here!
// CStorageContainer::build(version); // CStorageContainer::build(version);
} }
@ -422,18 +422,18 @@ void CAppDataEntry::build(uint16 version)
void CAppDataEntry::disown() void CAppDataEntry::disown()
{ {
// CStorageContainer::disown(); // CStorageContainer::disown();
if (Chunks.size() != 2) { nlerror("Not built"); return; } // Built chunks must match the parsed data if (m_Chunks.size() != 2) { nlerror("Not built"); return; } // Built chunks must match the parsed data
m_Key = NULL; m_Key = NULL;
m_Value = NULL; m_Value = NULL;
} }
void CAppDataEntry::init() void CAppDataEntry::init()
{ {
nlassert(Chunks.size() == 0); nlassert(m_Chunks.size() == 0);
m_Key = new CAppDataEntryKey(); m_Key = new CAppDataEntryKey();
Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID, m_Key)); m_Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_KEY_CHUNK_ID, m_Key));
m_Value = new CStorageRaw(); m_Value = new CStorageRaw();
Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID, m_Value)); m_Chunks.push_back(TStorageObjectWithId(NLMAXFILE_APP_DATA_ENTRY_VALUE_CHUNK_ID, m_Value));
} }
CAppDataEntryKey *CAppDataEntry::key() CAppDataEntryKey *CAppDataEntry::key()

@ -55,8 +55,8 @@ CClassDirectory3::CClassDirectory3(CDllDirectory *dllDirectory) : m_DllDirectory
// Parallel to CDllDirectory // Parallel to CDllDirectory
CClassDirectory3::~CClassDirectory3() CClassDirectory3::~CClassDirectory3()
{ {
// Delete m_ChunkCache and m_Entries when !ChunksOwnsPointers // Delete m_ChunkCache and m_Entries when !m_ChunksOwnsPointers
if (!ChunksOwnsPointers) if (!m_ChunksOwnsPointers)
{ {
for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
{ {
@ -80,13 +80,13 @@ std::string CClassDirectory3::getClassName()
// Parallel to CDllDirectory // Parallel to CDllDirectory
void CClassDirectory3::toString(std::ostream &ostream, const std::string &pad) void CClassDirectory3::toString(std::ostream &ostream, const std::string &pad)
{ {
if (ChunksOwnsPointers) if (m_ChunksOwnsPointers)
{ {
CStorageContainer::toString(ostream, pad); CStorageContainer::toString(ostream, pad);
} }
else else
{ {
ostream << "(" << getClassName() << ") [" << Chunks.size() << "] PARSED { "; ostream << "(" << getClassName() << ") [" << m_Chunks.size() << "] PARSED { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
sint i = 0; sint i = 0;
for (TStorageObjectContainer::const_iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
@ -136,7 +136,7 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level)
bool parsedDllEntry = false; bool parsedDllEntry = false;
// Parse chunks // Parse chunks
for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
uint16 id = it->first; uint16 id = it->first;
switch (id) switch (id)
@ -164,7 +164,7 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level)
} }
// Now ownership of the pointers lies in m_ChunkCache and m_Entries // Now ownership of the pointers lies in m_ChunkCache and m_Entries
ChunksOwnsPointers = false; m_ChunksOwnsPointers = false;
} }
} }
@ -172,10 +172,10 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level)
void CClassDirectory3::clean() void CClassDirectory3::clean()
{ {
// Ensure parsed // Ensure parsed
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
// Clear Chunks // Clear m_Chunks
Chunks.clear(); m_Chunks.clear();
// Clean chunks // Clean chunks
for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
@ -195,12 +195,12 @@ void CClassDirectory3::clean()
void CClassDirectory3::build(uint16 version) void CClassDirectory3::build(uint16 version)
{ {
// Ensure parsed // Ensure parsed
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
// Initialize // Initialize
nlassert(Chunks.empty()); nlassert(m_Chunks.empty());
// Set up the Chunks list, when (CClassEntry::ID, NULL) is found write out all of the entries. // Set up the m_Chunks list, when (CClassEntry::ID, NULL) is found write out all of the entries.
for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
{ {
uint16 id = it->first; uint16 id = it->first;
@ -208,15 +208,15 @@ void CClassDirectory3::build(uint16 version)
{ {
case 0x2040: // ClassEntry case 0x2040: // ClassEntry
for (std::vector<CClassEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) for (std::vector<CClassEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit)
Chunks.push_back(TStorageObjectWithId(id, (*subit))); m_Chunks.push_back(TStorageObjectWithId(id, (*subit)));
break; break;
default: default:
Chunks.push_back(*it); m_Chunks.push_back(*it);
break; break;
} }
} }
// Build the entries last (after Chunks is built) // Build the entries last (after m_Chunks is built)
CStorageContainer::build(version); CStorageContainer::build(version);
// NOTE: Ownership remains with m_ChunkCache and m_Entries // NOTE: Ownership remains with m_ChunkCache and m_Entries
@ -230,14 +230,14 @@ void CClassDirectory3::disown()
m_Entries.clear(); m_Entries.clear();
m_ClassIdToIndex.clear(); m_ClassIdToIndex.clear();
// Ownership goes back to Chunks // Ownership goes back to m_Chunks
ChunksOwnsPointers = true; m_ChunksOwnsPointers = true;
} }
// Parallel to CDllDirectory // Parallel to CDllDirectory
const CClassEntry *CClassDirectory3::get(uint16 index) const const CClassEntry *CClassDirectory3::get(uint16 index) const
{ {
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
nlassert(index < m_Entries.size()); nlassert(index < m_Entries.size());
return m_Entries[index]; return m_Entries[index];
} }
@ -245,7 +245,7 @@ const CClassEntry *CClassDirectory3::get(uint16 index) const
// Parallel to CDllDirectory // Parallel to CDllDirectory
void CClassDirectory3::reset() void CClassDirectory3::reset()
{ {
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
for (std::vector<CClassEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) for (std::vector<CClassEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit)
{ {
delete (*subit); delete (*subit);
@ -257,7 +257,7 @@ void CClassDirectory3::reset()
// Parallel to CDllDirectory // Parallel to CDllDirectory
uint16 CClassDirectory3::getOrCreateIndex(const ISceneClassDesc *sceneClassDesc) uint16 CClassDirectory3::getOrCreateIndex(const ISceneClassDesc *sceneClassDesc)
{ {
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
std::map<NLMISC::CClassId, uint16>::iterator it = m_ClassIdToIndex.find(sceneClassDesc->classId()); std::map<NLMISC::CClassId, uint16>::iterator it = m_ClassIdToIndex.find(sceneClassDesc->classId());
// Return existing index // Return existing index
@ -302,8 +302,8 @@ CClassEntry::CClassEntry() : m_Header(NULL), m_Name(NULL)
CClassEntry::CClassEntry(CDllDirectory *dllDirectory, const ISceneClassDesc *sceneClassDesc) : m_Header(new CClassEntryHeader()), m_Name(new CStorageValue<ucstring>()) CClassEntry::CClassEntry(CDllDirectory *dllDirectory, const ISceneClassDesc *sceneClassDesc) : m_Header(new CClassEntryHeader()), m_Name(new CStorageValue<ucstring>())
{ {
Chunks.push_back(TStorageObjectWithId(0x2060, m_Header)); m_Chunks.push_back(TStorageObjectWithId(0x2060, m_Header));
Chunks.push_back(TStorageObjectWithId(0x2042, m_Name)); m_Chunks.push_back(TStorageObjectWithId(0x2042, m_Name));
m_Header->DllIndex = dllDirectory->getOrCreateIndex(sceneClassDesc->dllPluginDesc()); m_Header->DllIndex = dllDirectory->getOrCreateIndex(sceneClassDesc->dllPluginDesc());
m_Header->ClassId = sceneClassDesc->classId(); m_Header->ClassId = sceneClassDesc->classId();
m_Header->SuperClassId = sceneClassDesc->superClassId(); m_Header->SuperClassId = sceneClassDesc->superClassId();
@ -324,7 +324,7 @@ void CClassEntry::toString(std::ostream &ostream, const std::string &pad)
{ {
if (m_Header && m_Name) if (m_Header && m_Name)
{ {
ostream << "(" << getClassName() << ") [" << Chunks.size() << "] PARSED { "; ostream << "(" << getClassName() << ") [" << m_Chunks.size() << "] PARSED { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
ostream << "\n" << pad << "Header: "; ostream << "\n" << pad << "Header: ";
m_Header->toString(ostream, padpad); m_Header->toString(ostream, padpad);
@ -340,9 +340,9 @@ void CClassEntry::toString(std::ostream &ostream, const std::string &pad)
void CClassEntry::parse(uint16 version, TParseLevel level) void CClassEntry::parse(uint16 version, TParseLevel level)
{ {
// CStorageContainer::parse(version, level); // CStorageContainer::parse(version, level);
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
nlassert(Chunks.size() == 2); nlassert(m_Chunks.size() == 2);
TStorageObjectContainer::iterator it = Chunks.begin(); TStorageObjectContainer::iterator it = m_Chunks.begin();
nlassert(it->first == 0x2060); // ClassEntryHeader nlassert(it->first == 0x2060); // ClassEntryHeader
m_Header = static_cast<CClassEntryHeader *>(it->second); m_Header = static_cast<CClassEntryHeader *>(it->second);
++it; ++it;
@ -353,7 +353,7 @@ void CClassEntry::parse(uint16 version, TParseLevel level)
void CClassEntry::clean() void CClassEntry::clean()
{ {
// Nothing to do here! (Chunks retains ownership) // Nothing to do here! (m_Chunks retains ownership)
// CStorageContainer::clean(); // CStorageContainer::clean();
} }
@ -368,7 +368,7 @@ void CClassEntry::disown()
// CStorageContainer::disown(); // CStorageContainer::disown();
m_Header = NULL; m_Header = NULL;
m_Name = NULL; m_Name = NULL;
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
} }
IStorageObject *CClassEntry::createChunkById(uint16 id, bool container) IStorageObject *CClassEntry::createChunkById(uint16 id, bool container)

@ -54,8 +54,8 @@ CDllDirectory::CDllDirectory() : m_DllEntryBuiltin(&DllPluginDescBuiltin), m_Dll
// Parallel to CClassDirectory3 // Parallel to CClassDirectory3
CDllDirectory::~CDllDirectory() CDllDirectory::~CDllDirectory()
{ {
// Delete m_ChunkCache and m_Entries when !ChunksOwnsPointers // Delete m_ChunkCache and m_Entries when !m_ChunksOwnsPointers
if (!ChunksOwnsPointers) if (!m_ChunksOwnsPointers)
{ {
for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
{ {
@ -78,13 +78,13 @@ std::string CDllDirectory::getClassName()
// Parallel to CClassDirectory3 // Parallel to CClassDirectory3
void CDllDirectory::toString(std::ostream &ostream, const std::string &pad) void CDllDirectory::toString(std::ostream &ostream, const std::string &pad)
{ {
if (ChunksOwnsPointers) if (m_ChunksOwnsPointers)
{ {
CStorageContainer::toString(ostream, pad); CStorageContainer::toString(ostream, pad);
} }
else else
{ {
ostream << "(" << getClassName() << ") [" << Chunks.size() << "] PARSED { "; ostream << "(" << getClassName() << ") [" << m_Chunks.size() << "] PARSED { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
sint i = 0; sint i = 0;
for (TStorageObjectContainer::const_iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
@ -135,7 +135,7 @@ void CDllDirectory::parse(uint16 version, TParseLevel level)
bool parsedDllEntry = false; bool parsedDllEntry = false;
// Parse chunks // Parse chunks
for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
uint16 id = it->first; uint16 id = it->first;
switch (id) switch (id)
@ -163,7 +163,7 @@ void CDllDirectory::parse(uint16 version, TParseLevel level)
} }
// Now ownership of the pointers lies in m_ChunkCache and m_Entries // Now ownership of the pointers lies in m_ChunkCache and m_Entries
ChunksOwnsPointers = false; m_ChunksOwnsPointers = false;
} }
} }
@ -171,10 +171,10 @@ void CDllDirectory::parse(uint16 version, TParseLevel level)
void CDllDirectory::clean() void CDllDirectory::clean()
{ {
// Ensure parsed // Ensure parsed
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
// Clear Chunks // Clear m_Chunks
Chunks.clear(); m_Chunks.clear();
// Clean chunks // Clean chunks
for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
@ -194,12 +194,12 @@ void CDllDirectory::clean()
void CDllDirectory::build(uint16 version) void CDllDirectory::build(uint16 version)
{ {
// Ensure parsed // Ensure parsed
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
// Initialize // Initialize
nlassert(Chunks.empty()); nlassert(m_Chunks.empty());
// Set up the Chunks list, when (CDllEntry::ID, NULL) is found write out all of the entries. // Set up the m_Chunks list, when (CDllEntry::ID, NULL) is found write out all of the entries.
for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_ChunkCache.begin(), end = m_ChunkCache.end(); it != end; ++it)
{ {
uint16 id = it->first; uint16 id = it->first;
@ -207,15 +207,15 @@ void CDllDirectory::build(uint16 version)
{ {
case 0x2038: // DllEntry case 0x2038: // DllEntry
for (std::vector<CDllEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) for (std::vector<CDllEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit)
Chunks.push_back(TStorageObjectWithId(id, (*subit))); m_Chunks.push_back(TStorageObjectWithId(id, (*subit)));
break; break;
default: default:
Chunks.push_back(*it); m_Chunks.push_back(*it);
break; break;
} }
} }
// Build the entries last (after Chunks is built) // Build the entries last (after m_Chunks is built)
CStorageContainer::build(version); CStorageContainer::build(version);
// NOTE: Ownership remains with m_ChunkCache and m_Entries // NOTE: Ownership remains with m_ChunkCache and m_Entries
@ -229,14 +229,14 @@ void CDllDirectory::disown()
m_Entries.clear(); m_Entries.clear();
m_InternalNameToIndex.clear(); m_InternalNameToIndex.clear();
// Ownership goes back to Chunks // Ownership goes back to m_Chunks
ChunksOwnsPointers = true; m_ChunksOwnsPointers = true;
} }
// Parallel to CClassDirectory3 // Parallel to CClassDirectory3
const CDllEntry *CDllDirectory::get(sint32 index) const const CDllEntry *CDllDirectory::get(sint32 index) const
{ {
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
if (index < 0) if (index < 0)
{ {
// Handle internal dummy values // Handle internal dummy values
@ -262,7 +262,7 @@ const CDllEntry *CDllDirectory::get(sint32 index) const
// Parallel to CClassDirectory3 // Parallel to CClassDirectory3
void CDllDirectory::reset() void CDllDirectory::reset()
{ {
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
for (std::vector<CDllEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit) for (std::vector<CDllEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit)
{ {
delete (*subit); delete (*subit);
@ -275,7 +275,7 @@ void CDllDirectory::reset()
// Parallel to CClassDirectory3 // Parallel to CClassDirectory3
sint32 CDllDirectory::getOrCreateIndex(const IDllPluginDescInternal *dllPluginDesc) sint32 CDllDirectory::getOrCreateIndex(const IDllPluginDescInternal *dllPluginDesc)
{ {
nlassert(!ChunksOwnsPointers); nlassert(!m_ChunksOwnsPointers);
std::map<ucstring, sint32>::iterator it = m_InternalNameToIndex.find(NLMISC::toLower(ucstring(dllPluginDesc->internalName()))); std::map<ucstring, sint32>::iterator it = m_InternalNameToIndex.find(NLMISC::toLower(ucstring(dllPluginDesc->internalName())));
// Return existing index // Return existing index
@ -331,8 +331,8 @@ CDllEntry::CDllEntry() : m_DllDescription(NULL), m_DllFilename(NULL)
CDllEntry::CDllEntry(const IDllPluginDescInternal *dllPluginDesc) : m_DllDescription(new CStorageValue<ucstring>()), m_DllFilename(new CStorageValue<ucstring>()) CDllEntry::CDllEntry(const IDllPluginDescInternal *dllPluginDesc) : m_DllDescription(new CStorageValue<ucstring>()), m_DllFilename(new CStorageValue<ucstring>())
{ {
Chunks.push_back(TStorageObjectWithId(0x2039, m_DllDescription)); m_Chunks.push_back(TStorageObjectWithId(0x2039, m_DllDescription));
Chunks.push_back(TStorageObjectWithId(0x2037, m_DllFilename)); m_Chunks.push_back(TStorageObjectWithId(0x2037, m_DllFilename));
m_DllDescription->Value = dllPluginDesc->displayName(); m_DllDescription->Value = dllPluginDesc->displayName();
m_DllFilename->Value = dllPluginDesc->internalName(); m_DllFilename->Value = dllPluginDesc->internalName();
} }
@ -351,7 +351,7 @@ void CDllEntry::toString(std::ostream &ostream, const std::string &pad)
{ {
if (m_DllDescription && m_DllFilename) if (m_DllDescription && m_DllFilename)
{ {
ostream << "(" << getClassName() << ") [" << Chunks.size() << "] PARSED { "; ostream << "(" << getClassName() << ") [" << m_Chunks.size() << "] PARSED { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
ostream << "\n" << pad << "DllDescription: " << m_DllDescription->Value.toUtf8(); ostream << "\n" << pad << "DllDescription: " << m_DllDescription->Value.toUtf8();
ostream << "\n" << pad << "DllFilename: " << m_DllFilename->Value.toUtf8(); ostream << "\n" << pad << "DllFilename: " << m_DllFilename->Value.toUtf8();
@ -366,9 +366,9 @@ void CDllEntry::toString(std::ostream &ostream, const std::string &pad)
void CDllEntry::parse(uint16 version, TParseLevel level) void CDllEntry::parse(uint16 version, TParseLevel level)
{ {
// CStorageContainer::parse(version, level); // CStorageContainer::parse(version, level);
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
nlassert(Chunks.size() == 2); nlassert(m_Chunks.size() == 2);
TStorageObjectContainer::iterator it = Chunks.begin(); TStorageObjectContainer::iterator it = m_Chunks.begin();
nlassert(it->first == 0x2039); // DllDescription nlassert(it->first == 0x2039); // DllDescription
m_DllDescription = static_cast<CStorageValue<ucstring> *>(it->second); m_DllDescription = static_cast<CStorageValue<ucstring> *>(it->second);
++it; ++it;
@ -379,7 +379,7 @@ void CDllEntry::parse(uint16 version, TParseLevel level)
void CDllEntry::clean() void CDllEntry::clean()
{ {
// Nothing to do here! (Chunks retains ownership) // Nothing to do here! (m_Chunks retains ownership)
// CStorageContainer::clean(); // CStorageContainer::clean();
} }
@ -394,7 +394,7 @@ void CDllEntry::disown()
// CStorageContainer::disown(); // CStorageContainer::disown();
m_DllDescription = NULL; m_DllDescription = NULL;
m_DllFilename = NULL; m_DllFilename = NULL;
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
} }
IStorageObject *CDllEntry::createChunkById(uint16 id, bool container) IStorageObject *CDllEntry::createChunkById(uint16 id, bool container)

@ -73,7 +73,7 @@ void CScene::toString(std::ostream &ostream, const std::string &pad)
void CScene::parse(uint16 version, TParseLevel level) void CScene::parse(uint16 version, TParseLevel level)
{ {
CStorageContainer::parse(version, level); CStorageContainer::parse(version, level);
nlassert(Chunks.size() == 1); nlassert(m_Chunks.size() == 1);
} }
void CScene::clean() void CScene::clean()
@ -83,7 +83,7 @@ void CScene::clean()
void CScene::build(uint16 version) void CScene::build(uint16 version)
{ {
nlassert(Chunks.size() == 1); nlassert(m_Chunks.size() == 1);
CStorageContainer::build(this->version()); CStorageContainer::build(this->version());
} }
@ -94,14 +94,14 @@ void CScene::disown()
uint16 CScene::version() uint16 CScene::version()
{ {
nlassert(Chunks.size() == 1); nlassert(m_Chunks.size() == 1);
return Chunks.begin()->first; return m_Chunks.begin()->first;
} }
CSceneClassContainer *CScene::container() CSceneClassContainer *CScene::container()
{ {
nlassert(Chunks.size() == 1); nlassert(m_Chunks.size() == 1);
return static_cast<CSceneClassContainer *>(Chunks.begin()->second); return static_cast<CSceneClassContainer *>(m_Chunks.begin()->second);
} }
IStorageObject *CScene::createChunkById(uint16 id, bool container) IStorageObject *CScene::createChunkById(uint16 id, bool container)

@ -121,11 +121,11 @@ CSceneClassUnknown::~CSceneClassUnknown()
void CSceneClassUnknown::toString(std::ostream &ostream, const std::string &pad) void CSceneClassUnknown::toString(std::ostream &ostream, const std::string &pad)
{ {
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
ostream << "(" << getClassName() << ": " << ucstring(getClassDesc()->displayName()).toUtf8() << ", " << getClassDesc()->classId().toString() << ", " << ucstring(getClassDesc()->dllPluginDesc()->internalName()).toUtf8() << ") [" << Chunks.size() << "] { "; ostream << "(" << getClassName() << ": " << ucstring(getClassDesc()->displayName()).toUtf8() << ", " << getClassDesc()->classId().toString() << ", " << ucstring(getClassDesc()->dllPluginDesc()->internalName()).toUtf8() << ") [" << m_Chunks.size() << "] { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
sint i = 0; sint i = 0;
for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
std::stringstream ss; std::stringstream ss;
ss << std::hex << std::setfill('0'); ss << std::hex << std::setfill('0');

@ -86,21 +86,21 @@ bool IStorageObject::isContainer() const
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
CStorageContainer::CStorageContainer() : ChunksOwnsPointers(true) CStorageContainer::CStorageContainer() : m_ChunksOwnsPointers(true)
{ {
} }
CStorageContainer::~CStorageContainer() CStorageContainer::~CStorageContainer()
{ {
if (ChunksOwnsPointers) if (m_ChunksOwnsPointers)
{ {
for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
delete it->second; delete it->second;
} }
} }
Chunks.clear(); m_Chunks.clear();
} }
std::string CStorageContainer::getClassName() // why is this not const in IClassable? std::string CStorageContainer::getClassName() // why is this not const in IClassable?
@ -112,8 +112,8 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
{ {
if (stream.isReading()) if (stream.isReading())
{ {
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
nlassert(Chunks.empty()); nlassert(m_Chunks.empty());
} }
if (stream.getPos() == 0) if (stream.getPos() == 0)
{ {
@ -178,11 +178,11 @@ void CStorageContainer::toString(std::ostream &ostream, const std::string &pad)
// Blahblah: (Container) { // Blahblah: (Container) {
// Moo: (Foo) "What" } // Moo: (Foo) "What" }
// only increase pad when multi-lining sub-items // only increase pad when multi-lining sub-items
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
ostream << "(" << getClassName() << ") [" << Chunks.size() << "] { "; ostream << "(" << getClassName() << ") [" << m_Chunks.size() << "] { ";
std::string padpad = pad + "\t"; std::string padpad = pad + "\t";
sint i = 0; sint i = 0;
for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
std::stringstream ss; std::stringstream ss;
ss << std::hex << std::setfill('0'); ss << std::hex << std::setfill('0');
@ -196,7 +196,7 @@ void CStorageContainer::toString(std::ostream &ostream, const std::string &pad)
void CStorageContainer::parse(uint16 version, TParseLevel level) void CStorageContainer::parse(uint16 version, TParseLevel level)
{ {
for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
if (it->second->isContainer()) if (it->second->isContainer())
{ {
@ -207,8 +207,8 @@ void CStorageContainer::parse(uint16 version, TParseLevel level)
void CStorageContainer::clean() void CStorageContainer::clean()
{ {
nlassert(ChunksOwnsPointers); // Can only use the default when Chunks retains ownership. nlassert(m_ChunksOwnsPointers); // Can only use the default when m_Chunks retains ownership.
for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
if (it->second->isContainer()) if (it->second->isContainer())
{ {
@ -219,7 +219,7 @@ void CStorageContainer::clean()
void CStorageContainer::build(uint16 version) void CStorageContainer::build(uint16 version)
{ {
for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
if (it->second->isContainer()) if (it->second->isContainer())
{ {
@ -230,7 +230,7 @@ void CStorageContainer::build(uint16 version)
void CStorageContainer::disown() void CStorageContainer::disown()
{ {
for (TStorageObjectContainer::const_iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::const_iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
if (it->second->isContainer()) if (it->second->isContainer())
{ {
@ -251,8 +251,8 @@ void CStorageContainer::serial(CStorageChunks &chunks)
#ifdef NL_DEBUG_STORAGE #ifdef NL_DEBUG_STORAGE
nldebug("Reading container chunk"); nldebug("Reading container chunk");
#endif #endif
nlassert(ChunksOwnsPointers); nlassert(m_ChunksOwnsPointers);
nlassert(Chunks.empty()); nlassert(m_Chunks.empty());
while (chunks.enterChunk()) while (chunks.enterChunk())
{ {
uint16 id = chunks.getChunkId(); uint16 id = chunks.getChunkId();
@ -261,10 +261,10 @@ void CStorageContainer::serial(CStorageChunks &chunks)
storageObject->setSize(chunks.getChunkSize()); storageObject->setSize(chunks.getChunkSize());
if (storageObject->isContainer()) static_cast<CStorageContainer *>(storageObject)->serial(chunks); if (storageObject->isContainer()) static_cast<CStorageContainer *>(storageObject)->serial(chunks);
else storageObject->serial(chunks.stream()); else storageObject->serial(chunks.stream());
Chunks.push_back(TStorageObjectWithId(id, storageObject)); m_Chunks.push_back(TStorageObjectWithId(id, storageObject));
if (chunks.leaveChunk()) // bytes were skipped while reading if (chunks.leaveChunk()) // bytes were skipped while reading
throw EStorage(); throw EStorage();
/*TStorageObjectContainer::iterator soit = Chunks.end(); /*TStorageObjectContainer::iterator soit = m_Chunks.end();
--soit; --soit;
serialized(soit, cont);*/ serialized(soit, cont);*/
} }
@ -274,7 +274,7 @@ void CStorageContainer::serial(CStorageChunks &chunks)
#ifdef NL_DEBUG_STORAGE #ifdef NL_DEBUG_STORAGE
nldebug("Writing container chunk"); nldebug("Writing container chunk");
#endif #endif
for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = m_Chunks.begin(), end = m_Chunks.end(); it != end; ++it)
{ {
chunks.enterChunk(it->first, it->second->isContainer()); chunks.enterChunk(it->first, it->second->isContainer());
IStorageObject *storageObject = it->second; IStorageObject *storageObject = it->second;

@ -92,11 +92,12 @@ public:
typedef std::pair<uint16, IStorageObject *> TStorageObjectWithId; typedef std::pair<uint16, IStorageObject *> TStorageObjectWithId;
typedef std::list<TStorageObjectWithId> TStorageObjectContainer; typedef std::list<TStorageObjectWithId> TStorageObjectContainer;
typedef TStorageObjectContainer::iterator TStorageObjectIterator; typedef TStorageObjectContainer::iterator TStorageObjectIterator;
TStorageObjectContainer Chunks; typedef TStorageObjectContainer::const_iterator TStorageObjectConstIt;
protected: protected:
// protected data // protected data
bool ChunksOwnsPointers; TStorageObjectContainer m_Chunks;
bool m_ChunksOwnsPointers;
public: public:
CStorageContainer(); CStorageContainer();
@ -114,9 +115,13 @@ public:
virtual void clean(); virtual void clean();
// Build the storage structure needed to store the parsed data back // Build the storage structure needed to store the parsed data back
virtual void build(uint16 version); virtual void build(uint16 version);
// Give ownership of the chunks back to the Chunks, must call build first, call instead of clean, reduces the parse level back to 0 // Give ownership of the chunks back to the m_Chunks, must call build first, call instead of clean, reduces the parse level back to 0
virtual void disown(); virtual void disown();
public:
// read access
inline const TStorageObjectContainer &chunks() const { return m_Chunks; }
public: // should be protected but that doesn't compile, nice c++! public: // should be protected but that doesn't compile, nice c++!
// inherited // inherited
virtual bool isContainer() const; virtual bool isContainer() const;
@ -126,6 +131,7 @@ protected:
virtual void serial(CStorageChunks &chunks); virtual void serial(CStorageChunks &chunks);
// Create a storage object by id, override to provide custom serialization // Create a storage object by id, override to provide custom serialization
virtual IStorageObject *createChunkById(uint16 id, bool container); virtual IStorageObject *createChunkById(uint16 id, bool container);
}; };
// CStorageRaw : serializes raw data, use for unknown data // CStorageRaw : serializes raw data, use for unknown data
@ -150,34 +156,9 @@ public: // should be protected but that doesn't compile, nice c++!
virtual void setSize(sint32 size); virtual void setSize(sint32 size);
// Gets the size when writing, return false if unknown // Gets the size when writing, return false if unknown
virtual bool getSize(sint32 &size) const; virtual bool getSize(sint32 &size) const;
};
/*
// CStorageUCString : serializes an ucstring chunk
class CStorageUCString : public ucstring, public IStorageObject
{
public:
virtual void serial(CStorageStream *stream);
virtual void dump(const std::string &pad);
};
// CStorageString : serializes a string chunk
class CStorageString : public std::string, public IStorageObject
{
public:
virtual void serial(CStorageStream *stream);
virtual void dump(const std::string &pad);
}; };
template<typename T>
class CStorageValue : public IStorageObject
{
public:
T Value;
virtual void serial(CStorageStream *stream);
virtual void dump(const std::string &pad);
};
*/
} /* namespace MAX */ } /* namespace MAX */
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -172,10 +172,10 @@ int main(int argc, char **argv)
#define NEL3D_APPDATA_ENV_FX (84682543) #define NEL3D_APPDATA_ENV_FX (84682543)
PIPELINE::MAX::CSceneClassContainer *ssc = scene.container(); PIPELINE::MAX::CSceneClassContainer *ssc = scene.container();
for (PIPELINE::MAX::CStorageContainer::TStorageObjectIterator it = ssc->Chunks.begin(), end = ssc->Chunks.end(); it != end; ++it) for (PIPELINE::MAX::CStorageContainer::TStorageObjectConstIt it = ssc->chunks().begin(), end = ssc->chunks().end(); it != end; ++it)
{ {
PIPELINE::MAX::CStorageContainer *subc = static_cast<PIPELINE::MAX::CStorageContainer *>(it->second); PIPELINE::MAX::CStorageContainer *subc = static_cast<PIPELINE::MAX::CStorageContainer *>(it->second);
for (PIPELINE::MAX::CStorageContainer::TStorageObjectIterator subit = subc->Chunks.begin(), subend = subc->Chunks.end(); subit != subend; ++subit) for (PIPELINE::MAX::CStorageContainer::TStorageObjectConstIt subit = subc->chunks().begin(), subend = subc->chunks().end(); subit != subend; ++subit)
{ {
PIPELINE::MAX::IStorageObject *storageChunk = subit->second; PIPELINE::MAX::IStorageObject *storageChunk = subit->second;
PIPELINE::MAX::CAppData *appData = dynamic_cast<PIPELINE::MAX::CAppData *>(storageChunk); PIPELINE::MAX::CAppData *appData = dynamic_cast<PIPELINE::MAX::CAppData *>(storageChunk);

Loading…
Cancel
Save