OW_XMLNode.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00038 #ifndef OW_XMLNODE_HPP_INCLUDE_GUARD_
00039 #define OW_XMLNODE_HPP_INCLUDE_GUARD_
00040 
00041 #include "OW_config.h"
00042 #include "OW_IntrusiveReference.hpp"
00043 #include "OW_IntrusiveCountableBase.hpp"
00044 #include "OW_XMLAttribute.hpp"
00045 #include "OW_XMLFwd.hpp"
00046 
00047 #include <iosfwd>
00048 
00049 namespace OW_NAMESPACE
00050 {
00051 
00052 class XMLNodeImpl;
00053 
00054 typedef IntrusiveReference<XMLNodeImpl> XMLNodeImplRef;
00055 
00065 class OW_XML_API XMLNode
00066 {
00067 public:
00068    
00078    XMLNode(const String& name, const XMLAttributeArray& attrArray);
00079    
00087    XMLNode(const String& name);
00088 
00092    XMLNode();
00093 
00097    XMLNode(const XMLNode& arg);
00098 
00105    XMLNode& operator= (const XMLNode & arg);
00106 
00107 
00108    ~XMLNode();
00109 
00114    void setToNULL();
00115 
00122    String getName() const;
00123    
00129    void assignText(const String& text) const;
00130 
00134    void appendText(const String& text) const;
00135    
00143    String getAttribute(const String& name) const;
00144    
00150    void addAttribute(const XMLAttribute& attr) const;
00151    
00161    String mustGetAttribute(const String& name) const;
00162    
00169    XMLAttributeArray getAttrs() const;
00170    
00179    String getText() const;
00180    
00190    XMLNode findElement(const char* elementName) const;
00191    
00205    XMLNode mustFindElement(const char* elementName) const;
00206    
00216    XMLNode nextElement(const char* elementName);
00217    
00230    XMLNode mustNextElement(const char* elementName) const;
00231    
00240    void mustElement(const char* elementName) const;
00241    
00254    XMLNode mustElementChild(const char* elementName) const;
00255    
00269    XMLNode mustChildElement(const char* elementName) const;
00270    
00285    XMLNode mustChildElementChild(const char* elementName) const;
00286    
00301    XMLNode mustChildFindElement(const char* elementName) const;
00302    
00311    XMLNode findElementChild(const char* elementName) const;
00312    
00324    XMLNode mustFindElementChild(const char* elementName) const;
00325    
00337    XMLNode mustChildFindElementChild(const char* elementName) const;
00338    
00346    void setNext(const XMLNode& node) const;
00347    
00353    XMLNode getNext() const;
00354    
00362    void addChild(const XMLNode& node) const;
00363    
00369    XMLNode getChild() const;
00370 
00379    XMLNode mustGetChild() const;
00380 
00386    XMLNodeArray getChildren() const;
00387 
00394    void printNode( std::ostream& ostr ) const;
00395 
00403    String toString() const;
00404 
00405    typedef XMLNodeImplRef XMLNode::*safe_bool;
00406    operator safe_bool () const
00407       {  return (m_impl) ? &XMLNode::m_impl : 0; }
00408    bool operator!() const
00409       {  return !m_impl; }
00410 
00411 
00412 private:
00413 
00414    XMLNode(const XMLNodeImplRef& ref);
00415 
00416 #ifdef OW_WIN32
00417 #pragma warning (push)
00418 #pragma warning (disable: 4251)
00419 #endif
00420 
00421    XMLNodeImplRef m_impl;
00422 
00423 #ifdef OW_WIN32
00424 #pragma warning (pop)
00425 #endif
00426 
00427    friend class XMLNodeImpl;
00428 };
00429 
00430 OW_XML_API std::ostream& operator<<(std::ostream& ostr, const XMLNode& node);
00431 
00432 #ifdef OW_WIN32
00433 #pragma warning (push)
00434 #pragma warning (disable: 4251)
00435 #endif
00436 
00437 class OW_XML_API XMLNodeImpl : public IntrusiveCountableBase
00438 {
00439 public:
00440    XMLNodeImpl(const String& name, const XMLAttributeArray& attrArray);
00441    XMLNodeImpl(const String& name);
00442    XMLNodeImpl();
00443    String getNodeName() const;
00444    void assignText(const String& text);
00445    void appendText(const String& text);
00446    String getAttribute(const String& name, bool throwException = false) const;
00447    void addAttribute(const XMLAttribute& attr);
00448    XMLAttributeArray getAttrs() const;
00449    String getText() const;
00450    String getName() const;
00451    
00452    void mustElement(const char* elementName) const;
00453    XMLNodeImplRef findElement(const char* elementName, bool throwException = false) const;
00454    XMLNodeImplRef nextElement(const char* elementName, bool throwException = false) const;
00455    XMLNodeImplRef findElementChild(const char* elementName, bool throwException = false) const;
00456    XMLNodeImplRef mustNextElement(const char* elementName) const;
00457    XMLNodeImplRef mustElementChild(const char* elementName) const;
00458    XMLNodeImplRef mustChildElement(const char* elementName) const;
00459    XMLNodeImplRef mustChildElementChild(const char* elementName) const;
00460    XMLNodeImplRef mustChildFindElement(const char* elementName) const;
00461    XMLNodeImplRef mustChildFindElementChild(const char* elementName) const;
00462    
00463    void setNext(const XMLNodeImplRef& node);
00464 
00465    XMLNodeImplRef getNext() const;
00466    void addChild(const XMLNodeImplRef& node);
00467 
00468    XMLNodeImplRef mustGetChild() const;
00469    XMLNodeImplRef getChild() const;
00470    XMLNodeArray getChildren() const;
00471    void printNode( std::ostream& ostr ) const;
00472    String toString() const;
00473 
00474 protected:
00475    XMLNodeImplRef m_nextNode;
00476    XMLNodeImplRef m_childNode;
00477    XMLNodeImplRef m_lastChildNode;
00478 
00479    XMLAttributeArray m_XMLAttributeArray;
00480    String m_strName;
00481    String m_strText;
00482 };
00483 
00484 #ifdef OW_WIN32
00485 #pragma warning (pop)
00486 #endif
00487 
00488 } // end namespace OW_NAMESPACE
00489 
00490 #endif
00491 

Generated on Thu Feb 9 08:48:19 2006 for openwbem by  doxygen 1.4.6