📄 xmlconfiguration.cpp
字号:
// ___ ___ ___ ___ ___ // /\__\ ___ /\__\ /\ \ /\__\ /\ \. // /::| | /\ \ /::| | /::\ \ /:/ / /::\ \. // /:|:| | \:\ \ /:|:| | /:/\:\ \ /:/ / /:/\:\ \. // /:/|:|__|__ /::\__\ /:/|:| |__ /:/ \:\ \ /:/ / /::\~\:\ \. // /:/ |::::\__\ __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/ /:/\:\ \:\__\.// \/__/~~/:/ / /\/:/ / \/__|:|/:/ / \:\ /\ \/__/ \:\ \ \:\~\:\ \/__/// /:/ / \::/__/ |:/:/ / \:\ \:\__\ \:\ \ \:\ \:\__\. // /:/ / \:\__\ |::/ / \:\/:/ / \:\ \ \:\ \/__/ // /:/ / \/__/ /:/ / \::/ / \:\__\ \:\__\. // \/__/ \/__/ \/__/ \/__/ \/__/ // // =============================================================================// Minimalist OpenGL Environment// =============================================================================//// This file is part of Minimalist OpenGL Environment (MinGLE)//// Version: 0.2.0// Author: Balazs Domonkos// Filename: src/configuration/src/XMLConfiguration.cpp// Creation Date: January 27th 2008// Revision Date: January 27th 2008////// The Minimalist OpenGL Environment is free software: you can// redistribute it and/or modify it under the terms of the GNU// General Public License as published by the Free Software// Foundation, either version 3 of the License, or (at your// option) any later version.//// The Minimalist OpenGL Environment is distributed in the hope// that it will be useful, but WITHOUT ANY WARRANTY; without// even the implied warranty of MERCHANTABILITY or FITNESS FOR// A PARTICULAR PURPOSE. See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License// along with Minimalist OpenGL Environment. If not, see // <http://www.gnu.org/licenses/>. See the COPYING file included // with this distribution file for license details.///// @file XMLConfiguration.cpp/// Text configuration file support// Header that contains the declaration#include <XMLConfiguration.h>// MinGLE headers// System headersnamespace MinGLE {XMLConfiguration::XMLConfiguration(const std::string& filename, VirtualFileSystem *vfs) { // Load XML document TiXmlDocument *doc = TinyXML::loadXML(filename, vfs); // Start parsing from the root element _parseElement(doc->RootElement()); // Erase the XML document delete doc;}void XMLConfiguration::_parseElement(const TiXmlElement *xmlElement) { // Recreate root element delete mRootEntry; mRootEntry = new Entry(xmlElement->Value()); // Iterate on attributes for (TiXmlAttribute *attr = (TiXmlAttribute *) xmlElement->FirstAttribute(); attr; attr = (TiXmlAttribute *) attr->Next()) { // Add attribute as simple entry Assert(attr->Name() && attr->Value(), "XMLConfiguration::_parseElement"); (void) _addChild(mRootEntry, attr->Name(), attr->Value()); } // Iterate on children for (TiXmlNode *childNode = (TiXmlNode *) xmlElement->FirstChild(); childNode; childNode = (TiXmlNode *) xmlElement->IterateChildren(childNode)) { // Parse child node _parseElement(mRootEntry, reinterpret_cast<const TiXmlElement *>(childNode)); }}void XMLConfiguration::_parseElement(Entry *parent, const TiXmlElement *xmlElement) { // Add composite entry Entry *entry = _addChild(parent, xmlElement->Value()); // Iterate on attributes for (TiXmlAttribute *attr = (TiXmlAttribute *) xmlElement->FirstAttribute(); attr; attr = (TiXmlAttribute *) attr->Next()) { // Add attribute as simple entry Assert(attr->Name() && attr->Value(), "XMLConfiguration::_parseElement"); (void) _addChild(entry, attr->Name(), attr->Value()); } // Iterate on children for (TiXmlNode *childNode = (TiXmlNode *) xmlElement->FirstChild(); childNode; childNode = (TiXmlNode *) xmlElement->IterateChildren(childNode)) { // Parse child node _parseElement(entry, reinterpret_cast<const TiXmlElement *>(childNode)); }}// =============================================================================const std::string XMLConfigurationManager::FUNCTIONALITY_STRING = "xml";XMLConfigurationManager::~XMLConfigurationManager() { // Nothing to do}void XMLConfigurationManager::registerConfigurationManager() { ConfigurationManager::registerImplementation(XMLConfigurationManager::FUNCTIONALITY_STRING, new XMLConfigurationManager()); ConfigurationManager::registerFunctionality(FileFormatFunctionality("xml", FileFormatFunctionality::READ), XMLConfigurationManager::FUNCTIONALITY_STRING);}Configuration *XMLConfigurationManager::_createConfiguration( const std::string& filename, VirtualFileSystem *vfs) { return new XMLConfiguration(filename, vfs);}} // namespace MinGLE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -