CDataFileWriter: Make it clear that Add methods do not modify the data

This commit is contained in:
Alexander Akulich 2023-07-08 02:43:46 +03:00
parent 74789f86dc
commit 0a657225ce
5 changed files with 10 additions and 10 deletions

View file

@ -611,7 +611,7 @@ int CDataFileWriter::GetExtendedItemTypeIndex(int Type)
return Index;
}
int CDataFileWriter::AddItem(int Type, int ID, int Size, void *pData)
int CDataFileWriter::AddItem(int Type, int ID, int Size, const void *pData)
{
dbg_assert((Type >= 0 && Type < MAX_ITEM_TYPES) || Type >= OFFSET_UUID, "incorrect type");
dbg_assert(m_NumItems < 1024, "too many items");
@ -650,7 +650,7 @@ int CDataFileWriter::AddItem(int Type, int ID, int Size, void *pData)
return m_NumItems - 1;
}
int CDataFileWriter::AddData(int Size, void *pData, int CompressionLevel)
int CDataFileWriter::AddData(int Size, const void *pData, int CompressionLevel)
{
dbg_assert(m_NumDatas < 1024, "too much data");
@ -666,7 +666,7 @@ int CDataFileWriter::AddData(int Size, void *pData, int CompressionLevel)
return m_NumDatas - 1;
}
int CDataFileWriter::AddDataSwapped(int Size, void *pData)
int CDataFileWriter::AddDataSwapped(int Size, const void *pData)
{
dbg_assert(Size % sizeof(int) == 0, "incorrect boundary");

View file

@ -126,9 +126,9 @@ public:
void Init();
bool OpenFile(class IStorage *pStorage, const char *pFilename, int StorageType = IStorage::TYPE_SAVE);
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType = IStorage::TYPE_SAVE);
int AddData(int Size, void *pData, int CompressionLevel = Z_DEFAULT_COMPRESSION);
int AddDataSwapped(int Size, void *pData);
int AddItem(int Type, int ID, int Size, void *pData);
int AddData(int Size, const void *pData, int CompressionLevel = Z_DEFAULT_COMPRESSION);
int AddDataSwapped(int Size, const void *pData);
int AddItem(int Type, int ID, int Size, const void *pData);
void Finish();
};

View file

@ -192,7 +192,7 @@ bool CEditorMap::Save(const char *pFileName)
GItemEx.m_Version = CMapItemGroupEx::CURRENT_VERSION;
GItemEx.m_ParallaxZoom = pGroup->m_ParallaxZoom;
for(const auto &pLayer : pGroup->m_vpLayers)
for(CLayer *pLayer : pGroup->m_vpLayers)
{
if(pLayer->m_Type == LAYERTYPE_TILES)
{

View file

@ -3785,7 +3785,7 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
Writer.AddData(TotalLength, pSettings);
continue;
}
unsigned char *pData = (unsigned char *)Reader.GetData(i);
const void *pData = Reader.GetData(i);
int Size = Reader.GetDataSize(i);
Writer.AddData(Size, pData);
Reader.UnloadData(i);

View file

@ -24,7 +24,7 @@ int main(int argc, const char **argv)
for(int Index = 0; Index < Reader.NumItems(); Index++)
{
int Type, ID;
void *pPtr = Reader.GetItem(Index, &Type, &ID);
const void *pPtr = Reader.GetItem(Index, &Type, &ID);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
@ -37,7 +37,7 @@ int main(int argc, const char **argv)
// add all data
for(int Index = 0; Index < Reader.NumData(); Index++)
{
void *pPtr = Reader.GetData(Index);
const void *pPtr = Reader.GetData(Index);
int Size = Reader.GetDataSize(Index);
Writer.AddData(Size, pPtr);
}