<!-- Wanted to avoid copying .css to each folder, so copied default .css from doxyen in here, kicked out most stuff we don't need for examples and modified some a little bit.
Target was having a single html in each example folder which is created from the main.cpp files and needs no files besides some images below media folder.
<p>This class loads and writes the settings and manages the options.</p>
<p>The class makes use of irrMap which is a an associative arrays using a red-black tree it allows easy mapping of a key to a value, along the way there is some information on how to use it. </p><divclass="fragment"><divclass="line"><spanclass="keyword">class </span>SettingManager</div><divclass="line">{</div><divclass="line"><spanclass="keyword">public</span>:</div><divclass="line"></div><divclass="line"><spanclass="comment">// Construct setting managers and set default settings</span></div><divclass="line"> SettingManager(<spanclass="keyword">const</span> stringw& settings_file): SettingsFile(settings_file), NullDevice(0)</div><divclass="line"> {</div><divclass="line"><spanclass="comment">// Irrlicht null device, we want to load settings before we actually created our device, therefore, nulldevice</span></div><divclass="line"> NullDevice = irr::createDevice(irr::video::EDT_NULL);</div><divclass="line"></div><divclass="line"><spanclass="comment">//DriverOptions is an irrlicht map,</span></div><divclass="line"><spanclass="comment">//we can insert values in the map in two ways by calling insert(key,value) or by using the [key] operator</span></div><divclass="line"><spanclass="comment">//the [] operator overrides values if they already exist</span></div><divclass="line"> DriverOptions.insert(L<spanclass="stringliteral">"Software"</span>, EDT_SOFTWARE);</div><divclass="line"> DriverOptions.insert(L<spanclass="stringliteral">"OpenGL"</span>, EDT_OPENGL);</div><divclass="line"> DriverOptions.insert(L<spanclass="stringliteral">"Direct3D9"</span>, EDT_DIRECT3D9);</div><divclass="line"></div><divclass="line"><spanclass="comment">//some resolution options</span></div><divclass="line"> ResolutionOptions.insert(L<spanclass="stringliteral">"640x480"</span>, dimension2du(640,480));</div><divclass="line"> ResolutionOptions.insert(L<spanclass="stringliteral">"800x600"</span>, dimension2du(800,600));</div><divclass="line"> ResolutionOptions.insert(L<spanclass="stringliteral">"1024x768"</span>, dimension2du(1024,768));</div><divclass="line"></div><divclass="line"><spanclass="comment">//our preferred defaults</span></div><divclass="line"> SettingMap.insert(L<spanclass="stringliteral">"driver"</span>, L<spanclass="stringliteral">"Direct3D9"</span>);</div><divclass="line"> SettingMap.insert(L<spanclass="stringliteral">"resolution"</span>, L<spanclass="stringliteral">"640x480"</span>);</div><divclass="line"> SettingMap.insert(L<spanclass="stringliteral">"fullscreen"</span>, L<spanclass="stringliteral">"0"</span>); <spanclass="comment">//0 is false</span></div><divclass="line"> }</div><divclass="line"></div><divclass="line"><spanclass="comment">// Destructor, you could store settings automatically on exit of your</span></div><divclass="line"><spanclass="comment">// application if you wanted to in our case we simply drop the</span></div><divclass="line"><spanclass="comment">// nulldevice</span></div><divclass="line"> ~SettingManager()</div><divclass="line"> {</div><divclass="line"><spanclass="keywordflow">if</span> (NullDevice)</div><divclass="line"> {</div><divclass="line"> NullDevice->closeDevice();</div><divclass="line"> NullDevice->drop();</div><divclass="line"> }</div><divclass="line"> };</div></div><!-- fragment --><p> Load xml from disk, overwrite default settings The xml we are trying to load has the following structure settings nested in sections nested in the root node, like: </p><preclass="fragment"><pre>
</pre></pre><divclass="fragment"><divclass="line"><spanclass="keywordtype">bool</span> load()</div><divclass="line"> {</div><divclass="line"><spanclass="comment">//if not able to create device don't attempt to load</span></div><divclass="line"><spanclass="keywordflow">if</span> (!NullDevice)</div><divclass="line"><spanclass="keywordflow">return</span><spanclass="keyword">false</span>;</div><divclass="line"></div><divclass="line"> irr::io::IXMLReader* xml = NullDevice->getFileSystem()->createXMLReader(SettingsFile); <spanclass="comment">//create xml reader</span></div><divclass="line"><spanclass="keywordflow">if</span> (!xml)</div><divclass="line"><spanclass="keywordflow">return</span><spanclass="keyword">false</span>;</div><divclass="line"></div><divclass="line"><spanclass="keyword">const</span> stringw settingTag(L<spanclass="stringliteral">"setting"</span>); <spanclass="comment">//we'll be looking for this tag in the xml</span></div><divclass="line"> stringw currentSection; <spanclass="comment">//keep track of our current section</span></div><divclass="line"><spanclass="keyword">const</span> stringw videoTag(L<spanclass="stringliteral">"video"</span>); <spanclass="comment">//constant for videotag</span></div><divclass="line"></div><divclass="line"><spanclass="comment">//while there is more to read</span></div><divclass="line"><spanclass="keywordflow">while</span> (xml->read())</div><divclass="line"> {</div><divclass="line"><spanclass="comment">//check the node type</span></div><divclass="line"><spanclass="keywordflow">switch</span> (xml->getNodeType())</div><divclass="line"> {</div><divclass="line"><spanclass="comment">//we found a new element</span></div><divclass="line"><spanclass="keywordflow">case</span> irr::io::EXN_ELEMENT:</div><divclass="line"> {</div><divclass="line"><spanclass="comment">//we currently are in the empty or mygame section and find the video tag so we set our current section to video</span></div><divclass="line"><spanclass="keywordflow">if</span> (currentSection.empty() && videoTag.equals_ignore_case(xml->getNodeName()))</div><divclass="line"> {</div><divclass="line"> currentSection = videoTag;</div><divclass="line"> }</div><divclass="line"><spanclass="comment">//we are in the video section and we find a setting to parse</span></div><divclass="line"><spanclass="keywordflow">else</span><spanclass="keywordflow">if</span> (currentSection.equals_ignore_case(videoTag) && settingTag.equals_ignore_case(xml->getNodeName() ))</div><divclass="line"> {</div><divclass="line"><spanclass="comment">//read in the key</span></div><divclass="line"> stringw key = xml->getAttributeValueSafe(L<spanclass="stringliteral">"name"</span>);</div><divclass="line"><spanclass="comment">//if there actually is a key to set</span></div><divclass="line"><spanclass="keywordflow">if</span> (!key.empty())</div><divclass="line"> {</div><divclass="line"><spanclass="comment">//set the setting in the map to the value,</span></div><divclass="line"><spanclass="comment">//the [] operator overrides values if they already exist or inserts a new key value</span></div><divclass="line"><spanclass="comment">//pair into the settings map if it was not defined yet</span></div><divclass="line"> SettingMap[key] = xml->getAttributeValueSafe(L<spanclass="stringliteral">"value"</span>);</div><divclass="line"