Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/diag/xml.h

Go to the documentation of this file.
00001 
00002 //  Copyright (C) 2000--2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00003 
00004 //  This file is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 
00009 //  This file is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 //  As a special exception, you may use this file as part of a free
00019 //  software library without restriction.  Specifically, if other files
00020 //  instantiate templates or use macros or inline functions from this
00021 //  file, or you compile this file and link it with other files to
00022 //  produce an executable, this file does not by itself cause the
00023 //  resulting executable to be covered by the GNU General Public
00024 //  License.  This exception does not however invalidate any other
00025 //  reasons why the executable file might be covered by the GNU General
00026 //  Public License.
00027 
00028 //  $Id: xml.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00029 //  STATUS. Experimental. This interface may be changed or removed!
00030 
00031 
00032 #include <more/gen/nary_tree.h>
00033 #include <more/gen/utility.h>
00034 #include <string>
00035 #include <map>
00036 
00037 
00038 namespace more
00039 {
00040 
00041   typedef char xml_char_type;
00042   typedef std::basic_string<xml_char_type> xml_string_type;
00043 
00044   struct _xml_node_base : handle_data
00045   {
00046       virtual ~_xml_node_base() {}
00047   };
00048 
00049   struct xml_namespace_node
00050   {
00051       xml_string_type const& url() const { return m_url; }
00052     private:
00053       xml_string_type m_url;
00054   };
00055 
00056   struct xml_text_node : _xml_node_base
00057   {
00058       xml_text_node() {}
00059       xml_text_node(xml_string_type s) : m_contents(s) {}
00060       virtual ~xml_text_node() {}
00061 
00062       xml_string_type const& contents() const { return m_contents; }
00063 
00064     private:
00065       xml_string_type m_contents;
00066   };
00067 
00068   struct xml_element_node : _xml_node_base
00069   {
00070       typedef std::map<xml_string_type, xml_string_type>
00071               attribute_container;
00072       typedef attribute_container::iterator attribute_iterator;
00073       typedef attribute_container::const_iterator const_attribute_iterator;
00074 
00075       xml_element_node() {}
00076 
00077       explicit xml_element_node(xml_string_type name)
00078           : m_ns(0), m_name(name) {}
00079 
00080       virtual ~xml_element_node() {}
00081 
00082       xml_string_type const& name() const { return m_name; }
00083 
00084       attribute_iterator insert_attribute(xml_string_type k, xml_string_type v)
00085         { m_attr.insert(std::make_pair(k, v)); }
00086 
00087     private:
00088       xml_namespace_node* m_ns;
00089       xml_string_type m_name;
00090       attribute_container m_attr;
00091   };
00092 
00093   struct _xml_node_handle : handle<_xml_node_base>
00094   {
00095       _xml_node_handle() {}
00096       _xml_node_handle(_xml_node_handle const& x) : handle<_xml_node_base>(x) {}
00097       _xml_node_handle(_xml_node_base* x) : handle<_xml_node_base>(x) {}
00098 
00099       xml_text_node* as_text()
00100         { return dynamic_cast<xml_text_node*>(data()); }
00101       xml_text_node const* as_text() const
00102         { return dynamic_cast<xml_text_node*>(data()); }
00103       xml_element_node* as_element()
00104         { return dynamic_cast<xml_element_node*>(data()); }
00105       xml_element_node const* as_element() const
00106         { return dynamic_cast<xml_element_node*>(data()); }
00107   };
00108 
00109   struct xml_document : nary_tree<_xml_node_handle>
00110   {
00111       typedef nary_tree<_xml_node_handle> container;
00112       typedef container::const_iterator const_iterator;
00113       typedef container::iterator iterator;
00114 
00115       xml_document(std::string file_name);
00116   };
00117 
00118 }

Generated on Sat Sep 7 19:11:10 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.