Preserve old DataPack behavior when overwriting data (#848)
* Match old DataPack behavior when overwriting data * Make RemoveItem more flexible * Ditch implied RemoveItem behavior & asher fixes * KyleS nits - but fixed before he says them * Add back implicit behavior * Update CDataPack.cpp Committing to the spec. * Update CDataPack.h * fixup removing last item if explicitly requested * Fix logic for accepting pack pos, rather than index * Fixup IsReadable * headache is over now
This commit is contained in:
committed by
Kyle Sanderson
parent
e4862dade8
commit
32d12ea4a6
@@ -223,3 +223,24 @@ void *CDataPack::ReadMemory(size_t *size) const
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool CDataPack::RemoveItem(size_t pos)
|
||||
{
|
||||
if (!elements.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pos == static_cast<size_t>(-1))
|
||||
{
|
||||
pos = position;
|
||||
}
|
||||
if (pos >= elements.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
elements.remove(pos);
|
||||
--position;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
void Initialize();
|
||||
inline size_t GetCapacity() const { return this->elements.length(); };
|
||||
inline CDataPackType GetCurrentType(void) const { return this->elements[this->position].type; };
|
||||
bool RemoveItem(size_t pos = -1);
|
||||
private:
|
||||
|
||||
typedef union {
|
||||
|
||||
@@ -99,6 +99,12 @@ static cell_t smn_WritePackCell(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Invalid data pack handle %x (error %d).", hndl, herr);
|
||||
}
|
||||
|
||||
bool insert = (params[0] >= 3) ? params[3] : false;
|
||||
if (!insert)
|
||||
{
|
||||
pDataPack->RemoveItem();
|
||||
}
|
||||
|
||||
pDataPack->PackCell(params[2]);
|
||||
|
||||
return 1;
|
||||
@@ -120,6 +126,12 @@ static cell_t smn_WritePackFloat(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Invalid data pack handle %x (error %d).", hndl, herr);
|
||||
}
|
||||
|
||||
bool insert = (params[0] >= 3) ? params[3] : false;
|
||||
if (!insert)
|
||||
{
|
||||
pDataPack->RemoveItem();
|
||||
}
|
||||
|
||||
pDataPack->PackFloat(sp_ctof(params[2]));
|
||||
|
||||
return 1;
|
||||
@@ -141,6 +153,12 @@ static cell_t smn_WritePackString(IPluginContext *pContext, const cell_t *params
|
||||
return pContext->ThrowNativeError("Invalid data pack handle %x (error %d).", hndl, herr);
|
||||
}
|
||||
|
||||
bool insert = (params[0] >= 3) ? params[3] : false;
|
||||
if (!insert)
|
||||
{
|
||||
pDataPack->RemoveItem();
|
||||
}
|
||||
|
||||
char *str;
|
||||
pContext->LocalToString(params[2], &str);
|
||||
pDataPack->PackString(str);
|
||||
@@ -164,6 +182,12 @@ static cell_t smn_WritePackFunction(IPluginContext *pContext, const cell_t *para
|
||||
return pContext->ThrowNativeError("Invalid data pack handle %x (error %d).", hndl, herr);
|
||||
}
|
||||
|
||||
bool insert = (params[0] >= 3) ? params[3] : false;
|
||||
if (!insert)
|
||||
{
|
||||
pDataPack->RemoveItem();
|
||||
}
|
||||
|
||||
pDataPack->PackFunction(params[2]);
|
||||
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user