AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: Vdf (key/value trees) - 1.07 (https://forums.alliedmods.net/showthread.php?t=51662)

commonbullet 02-22-2007 00:19

Module: Vdf (key/value trees) - 1.07
 
6 Attachment(s)
This is a simple module to handle vdf (valve data files) trees. It makes very easy to read, create and write node structures.

A vdf tree is composed by nodes of key/value string pairs in quotation marks hierarchically disposed in braces.

Example:
Code:


"UserConfigData"
{
        "Steam"
        {
                "Cached"
                {
                        "SteamGamesDialog.res"
                        {
                                "xpos"                "700"
                                "ypos"                "112"
                                "wide"                "204"
                                "tall"                "332"
                        }
                }
        }
}

Big thanks to sawce for helping with linux.

Zenith77 02-22-2007 09:58

Re: Module: Vdf trees
 
So basically now instead of creating are own file formats, we can just use this for plugins that require loading things? In other words, we could create are own .vdf files then read from them (I'm guessing 90% yes)? If so, you've saved my life.

Twilight Suzuka 02-22-2007 15:24

Re: Module: Vdf trees
 
That is actually reasonably cool.

A little ineffecient though, as you could use casts to hand the user a direct pointer, thus improving speed by a large margin (due to cache misses).

But cool none the less.

commonbullet 02-22-2007 16:18

Re: Module: Vdf trees
 
Yep, Zenith that's what it's supposed to be ;).

Thanks Rukia.

EDIT: I am working on that.

sawce 02-23-2007 00:49

Re: Module: Vdf trees
 
1 Attachment(s)
Here's a Linux build (if you update and don't have a way to build Linux on your own PM me and I'll rebuild). I haven't tested this build's functionality beyond it loading properly.

I'd suggest 2 things:

1. Look at other module include files (.inc and the moduleconfig.h) (like fakemeta, engine) and see how they do module auto loading.

2. Update your amxxmodule.cpp/amxxmodule.h to whatever is in SVN, it doesn't export the amxx query functions properly in GCC4 with the version you have.

BAILOPAN 02-23-2007 01:07

Re: Module: Vdf trees
 
Shameless plug: If you're interested, I wrote an article on this file format using a different parsing technique: http://www.sourcemod.net/devlog/?p=96 (source code included)

Tree-based parsers are better for coders who like simplicity and don't like maintaining state, so I can certainly see this module being useful ;) good job.

commonbullet 02-23-2007 11:51

Re: Module: Vdf trees
 
Thank you sawce for that linux build, I'll check how to do the auto load thing and update my source files (I was using sdk from amxx 1.75).

Very cool reading - thanks Bail, maybe in future it could support both parsing methods (in separate modules or not), just like i.e. xml's sax & dom libraries.

I'm trying to work out Rukia's point (if I understand what she meant).
The way it works right now, nodes are exposed in pawn as indexes of a pointer 'list'. When a function is called it checks if node is in pointer array index bounds before picking up the pointer.

If these 'nodes' in script were directly nodes objects addresses, how could I safely cast them? (it could happen that a coder would pass a wrong argument or accidentally change the variable and hl would crash; I guess this would be hard to debug)

BAILOPAN 02-23-2007 13:29

Re: Module: Vdf trees
 
Using pointers directly is possible if you explicitly tell users not to pass wrong ones. For example, pcvars in AMX Mod X use direct pointers. Just tell users to be careful and not to assume that the return values are mutable or consistent in any way.

Zenith77 02-24-2007 12:46

Re: Module: Vdf trees
 
Already have some requests, as I plan on using this module in two of my major projects.
I would like these two natives:

Code:
vdf_is_first_node(); vdf_is_last_node();

or perhaps collapse them into one native:

Code:
vdf_is_node_number(myNode, 1); vdf_is_node_number(myNode, vdf_num_nodes(myParentNode));

The latter one would require an additional native though, 'vdf_num_nodes()', which as you can tell returns the number of nodes in the current node.

Also, you should put everything in one big .zip file ^^..

commonbullet 02-24-2007 15:17

Re: Module: Vdf trees
 
Cool ideas.

You could check if it's the last or first node with "vdf_get_first_node" or vdf_get_last_node", but I see the advantages of using your model in a loop.

The new version is going to change functions arguments a bit, since nodes and trees will be pointers, functions like vdf_get_next_node won't need to pass the tree i.e.

And although this means performance enhancement you'll have to be very careful - I crashed hl a couple of times when I was writing the new example script carelessly... :)

For the same reason it's better to detach nodes concept from numbers. I'll include a function to count nodes in a branch though.

Finally I'm including important stuff I had forgotten like destroying trees and setting keys/values functions.


All times are GMT -4. The time now is 01:04.

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