XmlDoc.h

Go to the documentation of this file.
00001 /* 
00002  * wsdlpull - A C++ parser  for WSDL  (Web services description language)
00003  * XmlNode_t and XmlDoc_t for the WsdlParser
00004  * Copyright (C) 2009 Daniel Rodriguez
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __XMLDOC_HPP__
00022 #define __XMLDOC_HPP__
00023 
00024 #include <ostream>
00025 #include <vector>
00026 #include <map>
00027 #include <string>
00028 
00029 
00030 
00031 
00032   class XmlNode_t {
00033   public:
00034     enum {
00035       WS_AMOUNT = 2,
00036       EMPTY_NODE = 1,
00037       NON_EMPTY_NODE = 0
00038     };
00039 
00040   protected:
00041 
00042     size_t m_depth;
00043 
00044     bool m_empty;
00045 
00046     std::string m_name;
00047     std::string m_text;
00048 
00049     typedef std::vector< std::pair< std::string, std::string> > VectorAttributes_t;
00050     typedef std::map< std::string, size_t> MapAttributes_t;
00051 
00052     VectorAttributes_t m_attributes;
00053     MapAttributes_t m_mapAttributes;
00054 
00055     typedef std::vector< XmlNode_t *> VectorNodePtrs_t;
00056     typedef std::multimap< std::string, size_t> MultiMapNodes_t;
00057 
00058     XmlNode_t *mp_parent;
00059     XmlNode_t *mp_prev;
00060     XmlNode_t *mp_next;
00061 
00062     VectorNodePtrs_t m_nodes;
00063     MultiMapNodes_t m_mapNodes;
00064 
00065 
00066   public:
00067     XmlNode_t( const std::string &p_name = "", size_t p_depth = 0);
00068     XmlNode_t( const XmlNode_t &p_xmlNode);
00069 
00070     XmlNode_t &operator =( const XmlNode_t &p_xmlNode);
00071 
00072     virtual ~XmlNode_t();
00073 
00074   private:
00075     void deallocateNodes( void);
00076 
00077   public:
00078     void clear( void);
00079 
00080     XmlNode_t &getParent( void) const;
00081     void setParent( XmlNode_t &p_parent);
00082     void setParent( XmlNode_t *p_parent);
00083 
00084 
00085     XmlNode_t &getPrev( void) const;
00086     void setPrev( XmlNode_t &p_prev);
00087     void setPrev( XmlNode_t *p_prev);
00088 
00089     XmlNode_t &getNext( void) const;
00090     void setNext( XmlNode_t &p_next);
00091     void setNext( XmlNode_t *p_next);
00092 
00093     const std::string &getName( void) const;
00094     void setName( const std::string &p_name, bool p_empty = XmlNode_t::EMPTY_NODE);
00095 
00096     const std::string &getText( void) const;
00097     void setText( const std::string &p_text);
00098 
00099     size_t getDepth( void) const;
00100     void setDepth( size_t p_depth);
00101     
00102     bool isTextNode( void) const;
00103     bool isRootNode( void) const;
00104 
00105     XmlNode_t &addNode( XmlNode_t *p_xmlNode = NULL);
00106     XmlNode_t &addNode( const std::string &p_name, bool p_empty);
00107 
00108     void addAttribute( const std::string &p_name, const std::string &p_value);
00109     bool getAttribute( const std::string &p_name, std::string &p_result) const;
00110 
00111     void setEmpty( bool p_empty);
00112     bool empty( void) const;
00113 
00114     XmlNode_t *getNode( const std::string &p_name, size_t p_index = 0) const;
00115 
00116     void getAllChildren( XmlNode_t::VectorNodePtrs_t &p_children);
00117     void findSelfOrChildren( const std::string &p_name, XmlNode_t::VectorNodePtrs_t &p_children, bool p_lazyRelativeMatch = false);
00118     void findAny( const std::string &p_name, XmlNode_t::VectorNodePtrs_t &p_children);
00119     void findDirectChildren( const std::string &p_name, XmlNode_t::VectorNodePtrs_t &p_children);
00120 
00121     bool operator ==( const XmlNode_t &p_xmlNode) const;
00122 
00123     friend std::ostream &operator <<( std::ostream &p_ostream, const XmlNode_t &p_xmlNode);
00124 
00125   };
00126 
00127   class XmlDoc_t {
00128   protected:
00129     //std::string m_version;
00130     //std::string m_encoding;
00131 
00132     XmlNode_t m_rootNode;
00133 
00134     bool m_processEnvAndBody;
00135     bool m_lazyRelativeMatch;
00136 
00137   public:
00138     XmlDoc_t( const XmlNode_t &p_xmlNode = XmlNode_t());
00139 
00140     void clear( void);
00141 
00142     void setProcessEnvAndBody( bool p_processEnvAndBody);
00143     bool getProcessEnvAndBody( void) const;
00144 
00145     void setLazyRelativeMatch( bool p_lazyRelativeMatch);
00146     bool getLazyRelativeMatch( void) const;
00147 
00148     XmlNode_t &setRootNode( const XmlNode_t &p_xmlNode);
00149 
00150     XmlNode_t &getRootNode( void);
00151     const XmlNode_t &getRootNode( void) const;
00152 
00153     friend std::ostream &operator <<( std::ostream &p_ostream, const XmlDoc_t &p_xmlDoc);
00154 
00155     bool xpath( const std::string &p_xpath, std::vector< std::string> &p_results, size_t p_index = 0);
00156 
00157   };
00158 
00159 
00160 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by  doxygen 1.6.2