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.
DataPacks: Heterogeneous Container
- Archive-Poster
- Posts: 1267
- Gender:

DataPacks: Heterogeneous Container
- Attachments
-
- DataPacks.inc.zip
- (2.18 KiB) Downloaded 19 times
- Archive-Poster
- Posts: 1267
- Gender:

Re: DataPacks: Heterogeneous Container
Forgot to mention, indexes start at 0, and are ordered in first-in-first-out scheme.
E.g.:
E.g.:
Code: Select all
// 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)- Archive-Poster
- Posts: 1267
- Gender:

Re: DataPacks: Heterogeneous Container
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.hmmm, I'm not sure about the advantage of this over using the existing functions in cellarray.inc o_O
Can you clarify?
Code: Select all
Array
{
Array
{
cell,cell,cell...
}
Array
{
multicell,multicell...
}
}Edit:
doesn't the file miss the stocks for CellTries?
- Archive-Poster
- Posts: 1267
- Gender:

Re: DataPacks: Heterogeneous Container
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.
let me just leave you a tip:
You are doing
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.
Code: Select all
native TrieSetCell(Trie:handle, const key[], any:value);You are doing
Code: Select all
if(!hDataPack)
return- Archive-Poster
- Posts: 1267
- Gender:

Re: DataPacks: Heterogeneous Container
Makes sense, I'll change it so the CellArray functions will take care of validating the handles.
- Archive-Poster
- Posts: 1267
- Gender:

Re: DataPacks: Heterogeneous Container
Thanks for the explanation! I assumed that the regular arrays were already heterogeneous.
Who is online
Users browsing this forum: No registered users and 1 guest