Raised This Month: $51 Target: $400
 12% 

DataPacks: Heterogeneous Container


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 03-22-2009 , 20:57   DataPacks: Heterogeneous Container
Reply With Quote #1

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:
Code:
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.
Attached Files
File Type: inc DataPacks.inc (6.5 KB, 368 views)
__________________

Community / No support through PM

Last edited by danielkza; 03-22-2009 at 23:23.
danielkza is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-22-2009 , 21:48   Re: DataPacks: Heterogeneous Container
Reply With Quote #2

Nice. Good job, danielkza.
Arkshine is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 03-22-2009 , 22:34   Re: DataPacks: Heterogeneous Container
Reply With Quote #3

Quote:
Originally Posted by arkshine View Post
Nice. Good job, danielkza.
Thanks

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

E.g.:
Code:
// 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)
__________________

Community / No support through PM

Last edited by danielkza; 03-22-2009 at 22:40.
danielkza is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 03-23-2009 , 00:07   Re: DataPacks: Heterogeneous Container
Reply With Quote #4

hmmm, I'm not sure about the advantage of this over using the existing functions in cellarray.inc o_O

Can you clarify?
__________________
stupok is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-23-2009 , 06:15   Re: DataPacks: Heterogeneous Container
Reply With Quote #5

Quote:
Originally Posted by stupok View Post
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:
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?
__________________

Last edited by joaquimandrade; 03-23-2009 at 06:24.
joaquimandrade is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 03-23-2009 , 11:04   Re: DataPacks: Heterogeneous Container
Reply With Quote #6

Quote:
Originally Posted by joaquimandrade View Post
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:
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.
__________________

Community / No support through PM
danielkza is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-23-2009 , 11:14   Re: DataPacks: Heterogeneous Container
Reply With Quote #7

Quote:
Originally Posted by danielkza View Post
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.

Code:
native TrieSetCell(Trie:handle, const key[], any:value);
__________________
joaquimandrade is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-23-2009 , 11:20   Re: DataPacks: Heterogeneous Container
Reply With Quote #8

Daniel, let me just leave you a tip:

You are doing

PHP Code:
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.
__________________
joaquimandrade is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 03-23-2009 , 11:23   Re: DataPacks: Heterogeneous Container
Reply With Quote #9

Quote:
Originally Posted by joaquimandrade View Post
Daniel, let me just leave you a tip:

You are doing

PHP Code:
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.
Makes sense, I'll change it so the CellArray functions will take care of validating the handles.
__________________

Community / No support through PM
danielkza is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 03-23-2009 , 12:00   Re: DataPacks: Heterogeneous Container
Reply With Quote #10

Good Job. /* Sorry */ I explain wrong.

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

Last edited by AntiBots; 03-23-2009 at 12:18. Reason: Fix
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Old 03-23-2009, 12:03
joaquimandrade
This message has been deleted by joaquimandrade.
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode