DarkRadiant XMLRegistry

From The DarkMod Wiki
Revision as of 14:05, 13 January 2007 by Greebo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The XMLRegistry is the central storage for all kinds of variables, settings, preferences, game defaults, etc. As the name states, all the content is stored in XML format, which has some conveniences when accessing, changing and saving the content.

Accessing the Registry

The XMLRegistry plugin (interface defined in iregistry.h) implements some convenient methods to retrieve and save values into the keys. Use the GlobalRegistry() method to retrieve a reference to the XMLRegistry instance.

GlobalRegistry().get(<key>)        // returns a string
GlobalRegistry().getFloat(<key>)   // returns a float
GlobalRegistry().getInt(<key>)     // returns an int

The above methods try to retrieve the value from the registry and convert them via boost::lexical_cast, if required. If the key is not found in the specified place, an empty value is returned as default ("" or 0.0 or 0).

To save values into the registry, the set methods form the counterparts to the above functions:

GlobalRegistry().set(<key>, <value>)       // save the string into <key>
GlobalRegistry().setFloat(<key>, <value>)  // save the floating point value to <key>
GlobalRegistry().setInt(<key>, <value>)    // save the integer value to <key>

Keys

XPath Syntax

The libxml2 library is capable of interpreting the XPath syntax (see reference). Use the findXPath() and deleteXPath() methods to retrieve (or delete) certain paths. The findXPath() method returns an xml::Node structure which in turn provides some methods for adding children, getting attribute values and so on.