S3FC project page S3FC home page

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

s3_xml_config.h

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
00022  */
00023 
00030 #ifndef S3_XML_CONFIG_H
00031 #define S3_XML_CONFIG_H
00032 
00033 #define XERCES_2 (1)
00034 
00035 #ifdef XERCES_2
00036 #include <xercesc/util/PlatformUtils.hpp>
00037 #include <xercesc/dom/deprecated/DOM.hpp>
00038 #include <xercesc/dom/deprecated/DOMParser.hpp>
00039 #include <xercesc/sax2/DefaultHandler.hpp>
00040 #else
00041 #include <util/PlatformUtils.hpp>
00042 #include <dom/DOM.hpp>
00043 #include <parsers/DOMParser.hpp>
00044 #include <sax2/DefaultHandler.hpp>
00045 #endif
00046 #include <string>
00047 #include <stdlib.h>
00048 #include <iostream>
00049 #include <list>
00050 
00051 #include <s3fc/s3_config_base.h>
00052 #include <s3fc/s3_config_node.h>
00053 #include <s3fc/s3_exception.h>
00054 
00058 class s3_xml_exception : public s3_exception
00059 {
00060   public:
00064    s3_xml_exception(const std::string& errstr);
00065 };
00066 
00070 class s3_xml_config  : s3_config_base
00071 {
00072   protected:
00076    std::string config_file;
00081    DOM_Document doc;
00085    s3_config_node* rootnode;
00086 
00087 public:
00095    s3_xml_config(const std::string& n_config_file, bool create_file = false) throw (s3_generic_exception);
00099     ~s3_xml_config();
00103    s3_config_node& get_rootnode() const;
00110    void refresh();
00115    void set_config_file(const std::string& n_config_file);
00120    static void write_node(const std::string& filename,
00121            const s3_config_node& node);
00130    static void write_node(std::ostream& os,
00131            const s3_config_node& node,
00132            unsigned int depth = 0);
00133    // write n spaces to os
00134    static void write_spaces(std::ostream& os,
00135              unsigned int n);
00136   protected:
00141    static DOM_Document parse(const std::string& filename)
00142       throw (s3_generic_exception, s3_xml_exception);
00147    static s3_config_node* build_tree(const DOM_Node& doc);
00153    static std::string get_name(const DOM_Node& node);
00161    static std::string get_value(const DOM_Node& node);
00167    static std::map<std::string,std::string> get_attributes(const DOM_Node& node);
00173    static std::vector<s3_config_node*> get_children(const DOM_Node& node);
00179    static std::string domstr_to_string(const DOMString& dstr);
00180 
00184    void dump_DOM_tree(const DOM_Node& domdoc) const;
00185    
00191    class error_handler : public ErrorHandler
00192    {
00193      public:
00197       virtual void warning(const SAXParseException& e);
00201       virtual void error(const SAXParseException& e);
00205       virtual void fatalError(const SAXParseException& e);
00209       virtual void resetErrors();
00210      protected:
00218       void assemble_and_throw(const SAXParseException& e,
00219                const std::string& type);
00220    };
00221    friend class error_handler;
00222 };
00223 
00224 
00225 
00229 std::ostream& operator<<(std::ostream& str, const DOMString& s);
00230 
00231 #endif

Send comments to: s3fc@stonethree.com SourceForge Logo