[INC] Kvizzle - KeyValues made easy
Introduction
When working with KeyValues, it can sometimes be frustratingly complex to do seemingly simple tasks. Therefore I made something similar to CSS Selectors, just for KeyValues. I call it Kvizzle. The idea is that, instead of manually navigating up and down in the KeyValues structure, you simply describe the path with a string. In the string, a dot represents a child. Let us look at this sample KeyValues file. Code:
"Root"The path would be: Arena1.Players If you want to get the name of the author, the path is: Arena1.Author.Name The code would look like this: PHP Code:
Okay, so far it is pretty simple. Let us step it up a notch. Kvizzle supports something called "pseudo classes". We can use them to describe a path that is not simply given by a name. For example, "first child" is a pseudo class. Pseudo classes are indicated by using a colon instead of a dot. This path would get us to the Author's name: Arena1.Author:first-child To get the value of Players, we could use: Arena1:nth-child(2) Kvizzle also supports different "actions". For example, if you want to count how many children Arena1 has, you could use: Arena1:count This would return 3. Finally, you can also use "checks". Let us say you want to find the child to Arena1 that has the value 10. To do this you can use
This will return "Players". PHP Code:
Pseudo Classes
Checks
Actions (can only be used once at the end of the path)
Functions PHP Code:
Quick Guide To use Kvizzle, it is important that you only use the Kviz* functions. Using the normal Kv* functions will mess up Kvizzle's functionality. You must always begin with KvizCreate/KvizCreateFromFile, and you must always end with KvizClose. Here is a quick example that you can try out: Code:
new Handle:kv = KvizCreate("Test");Performance I made some performance measurements. I will post them here soon but until then, the conclusion is:
Changelog
-> Download Kvizzle <- If you are interested, you can also download a unit test of Kvizzle with a lot of examples. Feedback Since this is the first release, there is plenty of room for improvement. So if you have any comments, questions, or suggestion, feel free to write them here. |
Re: [INC] Kvizzle - KeyValues made easy
Examples
I have a couple of examples from real projects. Here you can see the difference between using the normal Kv-functions, and using Kvizzle. This is just to give you an idea about how much time you can save by using Kvizzle. Example 1 Without Kvizzle: PHP Code:
PHP Code:
Without Kvizzle: PHP Code:
PHP Code:
|
Re: [INC] Kvizzle - KeyValues made easy
reserved
|
Re: [INC] Kvizzle - KeyValues made easy
Wow this is really awesome. :mrgreen:
|
Re: [INC] Kvizzle - KeyValues made easy
Very clean. This will help a lot of people save a lot of time and headache.
|
Re: [INC] Kvizzle - KeyValues made easy
I'd be tempted to use this, but most of the time when I'm parsing KeyValues files I'm going to be looping over a section. Something that the default KeyValues implementation does pretty well and would incur heavier costs to do with Kvizzle.
Also, should I assume the name Kvizzle is a reference to Sizzle, one of jQuery's core parts? |
Re: [INC] Kvizzle - KeyValues made easy
This looks really awesome! Great job!
|
Re: [INC] Kvizzle - KeyValues made easy
Quote:
|
Re: [INC] Kvizzle - KeyValues made easy
Quote:
Actually, looping through a section is quite easy with Kvizzle. Let's say you have a structure like this: Code:
"Root"PHP Code:
If you are doing nested loops, you will end up with very long paths, like: "Admins:nth-child(%i):nth-child(%i):nth-child(%i)". To avoid these long strings, you can do something like this: PHP Code:
For example, imagine that you have a SteamID and you want to check if that SteamID belongs to an admin. Normally you would loop through all admins, and check their SteamID. With Kvizzle you can avoid that, and write a one-liner: PHP Code:
|
Re: [INC] Kvizzle - KeyValues made easy
Nice job, I love it. I have an idea to fix the issue of "To use Kvizzle, it is important that you only use the Kviz* functions. Using the normal Kv* functions will mess up Kvizzle's functionality.", maybe clone the handle on your side so people can't mess up the functionality of Kvizzle?
|
| All times are GMT -4. The time now is 18:35. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.