?? xmlconfiguration.h
字號(hào):
//
// XMLConfiguration.h
//
// $Id: //poco/Main/Util/include/Util/XMLConfiguration.h#1 $
//
// Definition of the XMLConfiguration class.
//
// Copyright (c) 2004-2005, Guenter Obiltschnig/Applied Informatics.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Redistributions in any form must be accompanied by information on
// how to obtain complete source code for this software and any
// accompanying software that uses this software. The source code
// must either be included in the distribution or be available for no
// more than the cost of distribution plus a nominal fee, and must be
// freely redistributable under reasonable conditions. For an
// executable file, complete source code means the source code for all
// modules it contains. It does not include source code for modules or
// files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef Util_XMLConfiguration_INCLUDED
#define Util_XMLConfiguration_INCLUDED
#ifndef Util_Util_INCLUDED
#include "Util/Util.h"
#endif
#ifndef Util_MapConfiguration_INCLUDED
#include "Util/MapConfiguration.h"
#endif
#ifndef DOM_Document_INCLUDED
#include "DOM/Document.h"
#endif
#ifndef DOM_AutoPtr_INCLUDED
#include "DOM/AutoPtr.h"
#endif
#ifndef SAX_InputSource_INCLUDED
#include "SAX/InputSource.h"
#endif
#ifndef STD_ISTREAM_INCLUDED
#include <istream>
#define STD_ISTREAM_INCLUDED
#endif
Util_BEGIN
class Util_API XMLConfiguration: public AbstractConfiguration
/// This configuration class extracts configuration properties
/// from an XML document. An XPath-like syntax for property
/// names is supported to allow full access to the XML document.
/// XML namespaces are not supported. The name of the root element
/// of an XML document is not significant. Periods in tag names
/// are not supported.
///
/// Given the following XML document as an example:
///
/// <config>
/// <prop1>value1</prop1>
/// <prop2>value2</prop2>
/// <prop3>
/// <prop4 attr="value3"/>
/// <prop4 attr="value4"/>
/// </prop3>
/// <prop5>value5</prop5>
/// <prop5>value6</prop5>
/// </config>
///
/// The following property names would be valid and would
/// yield the shown values:
///
/// prop1 -> value1
/// prop2 -> value2
/// prop3.prop4 -> (empty string)
/// prop3.prop4[@attr] -> value3
/// prop3.prop4[1][@attr] -> value4
/// prop5[0] -> value5
/// prop5[1] -> value6
///
/// Enumerating attributes is not supported.
/// Calling keys("prop3.prop4") will return an empty range.
///
/// Setting properties is not supported. An attempt to set a property results
/// in a NotImplementedException being thrown.
{
public:
XMLConfiguration();
/// Creates an empty XMLConfiguration.
XMLConfiguration(XML::InputSource* pInputSource);
/// Creates an XMLConfiguration and loads the XML document from
/// the given InputSource.
XMLConfiguration(std::istream& istr);
/// Creates an XMLConfiguration and loads the XML document from
/// the given stream.
XMLConfiguration(const std::string& path);
/// Creates an XMLConfiguration and loads the XML document from
/// the given path.
XMLConfiguration(const XML::Document* pDocument);
/// Creates the XMLConfiguration using the given XML document.
XMLConfiguration(const XML::Node* pNode);
/// Creates the XMLConfiguration using the given XML node.
void load(XML::InputSource* pInputSource);
/// Loads the XML document containing the configuration data
/// from the given InputSource.
void load(std::istream& istr);
/// Loads the XML document containing the configuration data
/// from the given stream.
void load(const std::string& path);
/// Loads the XML document containing the configuration data
/// from the given file.
void load(const XML::Document* pDocument);
/// Loads the XML document containing the configuration data
/// from the given XML document.
void load(const XML::Node* pNode);
/// Loads the XML document containing the configuration data
/// from the given XML node.
protected:
bool getRaw(const std::string& key, std::string& value) const;
void setRaw(const std::string& key, const std::string& value);
void enumerate(const std::string& key, Keys& range) const;
~XMLConfiguration();
private:
const XML::Node* findNode(const std::string& key) const;
static const XML::Node* findNode(std::string::const_iterator& it, const std::string::const_iterator& end, const XML::Node* pNode);
static const XML::Node* findElement(const std::string& name, const XML::Node* pNode);
static const XML::Node* findElement(int index, const XML::Node* pNode);
static const XML::Node* findAttribute(const std::string& name, const XML::Node* pNode);
XML::AutoPtr<XML::Node> _pRoot;
XML::AutoPtr<XML::Document> _pDocument;
};
Util_END
#endif // Util_XMLConfiguration_INCLUDED
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -