KeyValues: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
 
mNo edit summary
Line 1: Line 1:
#REDIRECT [[Keyvalue]]
'''KeyValeus''' handles input and output.
 
The KeyValues class can load the input from a data buffer or a file.
 
The format of a data buffer or file is the following.
 
"SuperKey1" "Value"
"SuperKey2"
{
"Key1" "Value"
"Key2"
{
"SubKey1" "Value"
"SubKey2"
{
<font color="red">And so on...</font>
}
}
}
 
==Useful Traverses==
The following loops are contained in the following function: <code>void Traverse(KeyValues *pKV);</code>
 
for ( KeyValues *sub = pKV->GetFirstSubKey(); sub; sub = sub->GetNextKey() )
:This loop steps through all subkeys contained in pKV.
:To handle subkeys with their own subkeys in pKV, you may want use a recursive loop.  To check if a subkey has subkeys, do the following:
if(sub->GetFirstSubKey())
{
Traverse(sub);
}
 
for ( KeyValues *sub = pKV->GetFirstValue(); sub; sub = sub->GetNextValue() )
:This loop steps through all subkeys contained in a pKV that have values.
:It is also valid to use the KeyValues member function <code>GetDataType</code> in the loop to do a type specific traverse.
 
[[Category:Helpers]]

Revision as of 20:59, 10 January 2006

KeyValeus handles input and output.

The KeyValues class can load the input from a data buffer or a file.

The format of a data buffer or file is the following.

"SuperKey1"	"Value"
"SuperKey2"
{
	"Key1"	"Value"
	"Key2"
	{
		"SubKey1"	"Value"
		"SubKey2"
		{
			And so on...
		}
	}
}

Useful Traverses

The following loops are contained in the following function: void Traverse(KeyValues *pKV);

for ( KeyValues *sub = pKV->GetFirstSubKey(); sub; sub = sub->GetNextKey() )
This loop steps through all subkeys contained in pKV.
To handle subkeys with their own subkeys in pKV, you may want use a recursive loop. To check if a subkey has subkeys, do the following:
if(sub->GetFirstSubKey())
{
	Traverse(sub);
}
for ( KeyValues *sub = pKV->GetFirstValue(); sub; sub = sub->GetNextValue() )
This loop steps through all subkeys contained in a pKV that have values.
It is also valid to use the KeyValues member function GetDataType in the loop to do a type specific traverse.