PDA

View Full Version : DataPacks: Heterogeneous Container


danielkza
03-22-2009, 20:57
These stocks are meant to mimic Sourcemod's data packs functionality, and complement CellTrie/CellArray, allowing heterogeneous data in the same container to be accessed by index.

Storage is done in nested CellArrays, and there are no size limits other than those imposed by them, if any.

They'll be specially useful to pass data to/from callbacks and forwards.

Changelog:

22/03/2009
Initial Release
23/03/2009
Fixed DataPack_GetString not returning the proper string length
Fixed accidental removal of stock modifier from functions
PS: I'll be posting an example script soon.

Arkshine
03-22-2009, 21:48
Nice. Good job, danielkza.

danielkza
03-22-2009, 22:34
Nice. Good job, danielkza.
Thanks :mrgreen:

Forgot to mention, indexes start at 0, and are ordered in first-in-first-out scheme.

E.g.:

// Create
new Array:hPack = DataPack_Create()

// Insert
DataPack_PushCell(hPack, 1)
DataPack_PushString(hPack, "hello world")

// Test
DataPack_GetItemType(hPack, 0) // DPACK_CELL
DataPack_GetItemType(hPack, 1) // DPACK_STRING

// Retrieve
new any:cCell, szString[32]
DataPack_GetCell(hPack, 0, cCell)
DataPack_GetString(hPack, 1, szString, charsmax(szString))
// cCell == 1, szString == "hello world"

// Free
DataPack_Free(hPack)

stupok
03-23-2009, 00:07
hmmm, I'm not sure about the advantage of this over using the existing functions in cellarray.inc o_O

Can you clarify?

joaquimandrade
03-23-2009, 06:15
hmmm, I'm not sure about the advantage of this over using the existing functions in cellarray.inc o_O

Can you clarify?

Arrays are homogenous containers. Each array can only contain data of one kind (cell or multicell). This is an abstraction layer for an array of "cells which values refer to arrays", being each one of the pointed to arrays a container of a different kind of data.

Array
{
Array
{
cell,cell,cell...
}
Array
{
multicell,multicell...
}
}If i understood it right. Anyway, good job daniel.

Edit:

Daniel, doesn't the file miss the stocks for CellTries?

danielkza
03-23-2009, 11:04
Arrays are homogenous containers. Each array can only contain data of one kind (cell or multicell). This is an abstraction layer for an array of "cells which values refer to arrays", being each one of the pointed to arrays a container of a different kind of data.

Array
{
Array
{
cell,cell,cell...
}
Array
{
multicell,multicell...
}
}If i understood it right. Anyway, good job daniel.

Edit:

Daniel, doesn't the file miss the stocks for CellTries?
You got it right, couldn't have explained it better myself.

And what stocks are you talking about? I never actually used CellTrie so I don't know it very well.

joaquimandrade
03-23-2009, 11:14
You got it right, couldn't have explained it better myself.

And what stocks are you talking about? I never actually used CellTrie so I don't know it very well.

The same as for Arrays the difference is that with Arrays you associate data to a cell, with Tries you associated data to a group of cells.

native TrieSetCell(Trie:handle, const key[], any:value);

joaquimandrade
03-23-2009, 11:20
Daniel, let me just leave you a tip:

You are doing

if(!hDataPack)
return

I wouldn't recommend that because you should let errors happen or handle them in your code so, the user can see what's the problem.

danielkza
03-23-2009, 11:23
Daniel, let me just leave you a tip:

You are doing

if(!hDataPack)
returnI wouldn't recommend that because you should let errors happen or handle them in your code so, the user can see what's the problem.
Makes sense, I'll change it so the CellArray functions will take care of validating the handles.

AntiBots
03-23-2009, 12:00
Good Job. /* Sorry */ I explain wrong.

OffTopic... I can use ArrayCreate in plugin_natives() ?

stupok
03-23-2009, 17:54
@joaquimandrade

Thanks for the explanation! I assumed that the regular arrays were already heterogeneous.