Here the xml structure used: More...
#include <xml_config.hh>
Inheritance diagram for xml::XMLConfig:

Public Member Functions | |
| XMLConfig (const std::string &def_file, const std::string &def_loc) | |
| void | switchClientSection (int client_gid) const |
| template<typename T> | |
| T | getData (const std::string §ion_name, const std::string &node_name) const |
| Get a text value. | |
| template<typename T> | |
| T | getAttr (const std::string §ion_name, const std::string &node_name, const std::string &attr_name) const |
| Get an attribute value. | |
| template<typename T> | |
| void | setData (const std::string §ion_name, const std::string &node_name, const T &value) |
Replace text of node node_name by value. | |
| template<typename T> | |
| void | setAttr (const std::string §ion_name, const std::string &node_name, const std::string &attr_name, const T &value) |
Replace an attribute of the node node_name by value. | |
| virtual void | parse (const std::string &filename) |
| Try to find config file in various place before parsing. | |
Here the xml structure used:
<config>
<section1>
<node1 attr1="..." attr2="...">value 1</node1>
<node2 attr1="..." attr2="..." />
</section1>
<section2>
[...]
</section2>
</config>
Configuration options are organized into sections (like game, client, server, ...). Inside them, there are one or more node, for a specific configuration item.
To retrieve them, first parse the config file, then use: * getData<return type wanted>(section, node) * getAttr<return type wanted>(section, node, attr)
To modify or add new, use: * setData(section, node, value) * setAttr(section, node, attr, value)
Then use save to dump configuration into a file.
The section client is a little special. There is more than one client section, identified by attribute id. Each one with id > 0 identify a particular client configuration, so it is possible to use the same configuration file to launch multiple instance of stechec with different client configuration (in a single process, only one section is used at all). You only have to choose the correct client id at the process startup. Client section can be chosen using switchClientSection.
There is also a special client section, whose id is 0. It defined configuration items for all client section, in case they were not found in there specific sections. (yes, this is some xml inheritance kind). This is used to factorize client configuration.
To get client section value and attribute, be sure to call switchClientSection once in your program, then always use "client" as section:
int val = cfg.getAttr<int>("client", "debug", "verbose");
You can refer to config.dtd to see the exact file definition, and what section and node it can accept.
| T xml::XMLConfig::getAttr | ( | const std::string & | section_name, | |
| const std::string & | node_name, | |||
| const std::string & | attr_name | |||
| ) | const [inline] |
Get an attribute value.
| section_name | Section to fetch value from (client, server, game). | |
| node_name | The node to get value from. | |
| attr_name | The attribute name to get value from. |
| T xml::XMLConfig::getData | ( | const std::string & | section_name, | |
| const std::string & | node_name | |||
| ) | const [inline] |
Get a text value.
| section_name | Section to fetch value from (client, server, game). | |
| node_name | The node to get text from. |
| void xml::XMLConfig::setAttr | ( | const std::string & | section_name, | |
| const std::string & | node_name, | |||
| const std::string & | attr_name, | |||
| const T & | value | |||
| ) | [inline] |
Replace an attribute of the node node_name by value.
It create a new attribute if node_name is not found.
| void xml::XMLConfig::setData | ( | const std::string & | section_name, | |
| const std::string & | node_name, | |||
| const T & | value | |||
| ) | [inline] |
Replace text of node node_name by value.
It creates a new node if node_name is not found.
1.4.7