@ -61,7 +61,6 @@ namespace STORAGE {
# define PMBS_APP_DATA_HEADER_CHUNK_ID 0x0100
# define PMBS_APP_DATA_HEADER_CHUNK_ID 0x0100
# define PMBS_APP_DATA_ENTRY_CHUNK_ID 0x0110
# define PMBS_APP_DATA_ENTRY_CHUNK_ID 0x0110
# define PMBS_APP_DATA_ENTRY_KEY_CHUNK_ID 0x0120
# define PMBS_APP_DATA_ENTRY_KEY_CHUNK_ID 0x0120
# define PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID 0x0130
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
@ -122,7 +121,12 @@ CAppData::CAppData()
CAppData : : ~ CAppData ( )
CAppData : : ~ CAppData ( )
{
{
if ( ! m_ChunksOwnsPointers )
{
for ( TMap : : const_iterator subit = m_Entries . begin ( ) , subend = m_Entries . end ( ) ; subit ! = subend ; + + subit )
delete subit - > second ;
m_Entries . clear ( ) ;
}
}
}
std : : string CAppData : : className ( ) const
std : : string CAppData : : className ( ) const
@ -197,6 +201,11 @@ void CAppData::clean()
if ( m_Chunks . begin ( ) - > first ! = PMBS_APP_DATA_HEADER_CHUNK_ID ) { nlerror ( " Bad id %x, expected %x " , ( uint32 ) m_Chunks . begin ( ) - > first , PMBS_APP_DATA_HEADER_CHUNK_ID ) ; return ; } // Cannot happen, because we won't have local ownership if parsing failed
if ( m_Chunks . begin ( ) - > first ! = PMBS_APP_DATA_HEADER_CHUNK_ID ) { nlerror ( " Bad id %x, expected %x " , ( uint32 ) m_Chunks . begin ( ) - > first , PMBS_APP_DATA_HEADER_CHUNK_ID ) ; return ; } // Cannot happen, because we won't have local ownership if parsing failed
delete m_Chunks . begin ( ) - > second ; // Delete the header chunk, since we own it
delete m_Chunks . begin ( ) - > second ; // Delete the header chunk, since we own it
m_Chunks . clear ( ) ; // Clear the remaining chunks
m_Chunks . clear ( ) ; // Clear the remaining chunks
// Clean raw storage
for ( TMap : : const_iterator subit = m_Entries . begin ( ) , subend = m_Entries . end ( ) ; subit ! = subend ; + + subit )
subit - > second - > clean ( ) ;
# else
# else
CStorageContainer : : clean ( ) ;
CStorageContainer : : clean ( ) ;
# endif
# endif
@ -217,6 +226,9 @@ void CAppData::build(uint16 version, uint filter)
// 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 )
m_Chunks . push_back ( TStorageObjectWithId ( PMBS_APP_DATA_ENTRY_CHUNK_ID , it - > second ) ) ;
m_Chunks . push_back ( TStorageObjectWithId ( PMBS_APP_DATA_ENTRY_CHUNK_ID , it - > second ) ) ;
// Rebuild raw storage
CStorageContainer : : build ( version ) ;
# else
# else
CStorageContainer : : build ( version ) ;
CStorageContainer : : build ( version ) ;
# endif
# endif
@ -251,7 +263,7 @@ void CAppData::init()
// We own this
// We own this
m_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 ( m_ChunksOwnsPointers ) { nlwarning ( " Not parsed " ) ; return NULL ; }
if ( m_ChunksOwnsPointers ) { nlwarning ( " Not parsed " ) ; return NULL ; }
@ -305,7 +317,7 @@ void CAppData::fill(NLMISC::CClassId classId, TSClassId superClassId, uint32 sub
// Outside classes should unlock in case the implementation changes.
// Outside classes should unlock in case the implementation changes.
// unlock(classId, superClassId, subId, size);
// unlock(classId, superClassId, subId, size);
}
}
*/
void CAppData : : erase ( NLMISC : : CClassId classId , TSClassId superClassId , uint32 subId )
void CAppData : : erase ( NLMISC : : CClassId classId , TSClassId superClassId , uint32 subId )
{
{
if ( m_ChunksOwnsPointers ) { nlwarning ( " Not parsed " ) ; return ; }
if ( m_ChunksOwnsPointers ) { nlwarning ( " Not parsed " ) ; return ; }
@ -372,14 +384,15 @@ void CAppDataEntryKey::toString(std::ostream &ostream, const std::string &pad) c
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CAppDataEntry : : CAppDataEntry ( ) : m_Key ( NULL ) , m_ Value( NULL )
CAppDataEntry : : CAppDataEntry ( ) : m_Key ( NULL ) , m_ Raw( NULL ) , m_ Value( NULL )
{
{
}
}
CAppDataEntry : : ~ CAppDataEntry ( )
CAppDataEntry : : ~ CAppDataEntry ( )
{
{
delete m_Value ;
m_Value = NULL ;
}
}
std : : string CAppDataEntry : : className ( ) const
std : : string CAppDataEntry : : className ( ) const
@ -417,7 +430,7 @@ void CAppDataEntry::parse(uint16 version, uint filter)
+ + it ;
+ + it ;
if ( it - > first ! = PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID ) { nlwarning ( " Bad id %x, expected %x " , ( uint32 ) it - > first , PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID ) ; disown ( ) ; return ; }
if ( it - > first ! = PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID ) { nlwarning ( " Bad id %x, expected %x " , ( uint32 ) it - > first , PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID ) ; disown ( ) ; return ; }
m_ Value = static_cast < CStorageRaw * > ( it - > second ) ;
m_ Raw = static_cast < CStorageRaw * > ( it - > second ) ;
// m_ChunksOwnsPointers = false;
// m_ChunksOwnsPointers = false;
nlassert ( m_ChunksOwnsPointers ) ; // Never set false here
nlassert ( m_ChunksOwnsPointers ) ; // Never set false here
@ -425,18 +438,28 @@ void CAppDataEntry::parse(uint16 version, uint filter)
void CAppDataEntry : : clean ( )
void CAppDataEntry : : clean ( )
{
{
nlassert ( false ) ;
// CStorageContainer::clean();
// CStorageContainer::clean();
// if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return; }
if ( m_Value )
// Nothing to do here!
{
nlassert ( m_Raw ) ;
m_Raw - > Value . resize ( 0 ) ;
m_Key - > Size = 0xFFFFFFFF ;
}
}
}
void CAppDataEntry : : build ( uint16 version , uint filter )
void CAppDataEntry : : build ( uint16 version , uint filter )
{
{
nlassert ( false ) ;
// if (m_ChunksOwnsPointers) { nlwarning("Not parsed"); return; }
// Nothing to do here!
// CStorageContainer::build(version);
// CStorageContainer::build(version);
if ( m_Value )
{
nlassert ( m_Raw ) ;
NLMISC : : CMemStream mem ;
m_Value - > serial ( mem ) ;
m_Raw - > setSize ( mem . getPos ( ) ) ;
mem . invert ( ) ;
m_Raw - > serial ( mem ) ;
m_Key - > Size = m_Raw - > Value . size ( ) ;
}
}
}
void CAppDataEntry : : disown ( )
void CAppDataEntry : : disown ( )
@ -444,6 +467,8 @@ void CAppDataEntry::disown()
// CStorageContainer::disown();
// CStorageContainer::disown();
if ( m_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_Raw = NULL ;
delete m_Value ;
m_Value = NULL ;
m_Value = NULL ;
}
}
@ -452,18 +477,8 @@ void CAppDataEntry::init()
nlassert ( m_Chunks . size ( ) = = 0 ) ;
nlassert ( m_Chunks . size ( ) = = 0 ) ;
m_Key = new CAppDataEntryKey ( ) ;
m_Key = new CAppDataEntryKey ( ) ;
m_Chunks . push_back ( TStorageObjectWithId ( PMBS_APP_DATA_ENTRY_KEY_CHUNK_ID , m_Key ) ) ;
m_Chunks . push_back ( TStorageObjectWithId ( PMBS_APP_DATA_ENTRY_KEY_CHUNK_ID , m_Key ) ) ;
m_Value = new CStorageRaw ( ) ;
m_Raw = new CStorageRaw ( ) ;
m_Chunks . push_back ( TStorageObjectWithId ( PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID , m_Value ) ) ;
m_Chunks . push_back ( TStorageObjectWithId ( PMBS_APP_DATA_ENTRY_VALUE_CHUNK_ID , m_Raw ) ) ;
}
CAppDataEntryKey * CAppDataEntry : : key ( )
{
return m_Key ;
}
CStorageRaw * CAppDataEntry : : value ( )
{
return m_Value ;
}
}
IStorageObject * CAppDataEntry : : createChunkById ( uint16 id , bool container )
IStorageObject * CAppDataEntry : : createChunkById ( uint16 id , bool container )