DataPacks: Heterogeneous Container

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

DataPacks: Heterogeneous Container

Post by Archive-Poster »

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.
Attachments
DataPacks.inc.zip
(2.18 KiB) Downloaded 19 times
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: DataPacks: Heterogeneous Container

Post by Archive-Poster »

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

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)
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: DataPacks: Heterogeneous Container

Post by Archive-Poster »

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.

Code: Select all

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

Edit:

doesn't the file miss the stocks for CellTries?
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: DataPacks: Heterogeneous Container

Post by Archive-Poster »

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.

Code: Select all

native TrieSetCell(Trie:handle, const key[], any:value);
let me just leave you a tip:

You are doing

Code: Select all

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.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: DataPacks: Heterogeneous Container

Post by Archive-Poster »

Makes sense, I'll change it so the CellArray functions will take care of validating the handles.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: DataPacks: Heterogeneous Container

Post by Archive-Poster »

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

Who is online

Users browsing this forum: No registered users and 0 guests