libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/base/conf_backend_xml.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 2007, 2008, 2009 Juan Pedro BolĂ­var Puente
00013  *
00014  *  This file is part of Psychosynth.
00015  *   
00016  *  Psychosynth is free software: you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation, either version 3 of the License, or
00019  *  (at your option) any later version.
00020  *
00021  *  Psychosynth is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  You should have received a copy of the GNU General Public License
00027  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028  *
00029  */
00030 
00031 #ifndef PSYNTH_CONFBACKENDXML_H
00032 #define PSYNTH_CONFBACKENDXML_H
00033 
00034 #include <string>
00035 
00036 #include <libxml/xmlreader.h>
00037 #include <libxml/xmlwriter.h>
00038 
00039 #include <psynth/base/type_value.hpp>
00040 #include <psynth/base/config.hpp>
00041 #include <psynth/base/conf_backend_xml_fwd.hpp>
00042 
00043 namespace psynth
00044 {
00045 namespace base
00046 {
00047 
00048 PSYNTH_DECLARE_ERROR (config_error, config_xml_error)
00049 PSYNTH_DECLARE_ERROR (config_xml_error, config_xml_type_error)
00050 PSYNTH_DECLARE_ERROR (config_xml_error, config_xml_io_error)
00051 
00057 class conf_backend_xml : public conf_backend
00058 {
00059 public:
00065     conf_backend_xml (const std::string& file)
00066         : m_file(file)
00067     {}
00068 
00070     ~conf_backend_xml () {}
00071 
00076     void set_file (const std::string& file)
00077     {
00078         m_file = file;
00079     }
00080 
00084     const std::string& get_file ()
00085     {
00086         return m_file;
00087     }
00088 
00090     void attach (conf_node& node) {};
00091 
00093     void datach (conf_node& node) {};
00094 
00099     void save (conf_node& node);
00100 
00105     void load (conf_node& node)
00106     {
00107         m_overwrite = true;
00108         do_load (node);
00109     }
00110 
00115     void def_load (conf_node& node)
00116     {
00117         m_overwrite = false;
00118         do_load (node);
00119     }
00120 
00125     void handle_conf_change (conf_node& c) {};
00126 
00131     void handle_conf_nudge (conf_node& c) {};
00132 
00137     void handle_conf_add_child (conf_node& c) {};
00138 
00143     void handle_conf_del_child (conf_node& c) {};
00144 
00145 private:
00146     type_value m_current_type;
00147     
00148     std::string m_file;
00149     bool m_overwrite;
00150     
00151     conf_node* process_new_element (xmlTextReaderPtr reader, conf_node* node);
00152     conf_node* process_text (xmlTextReaderPtr reader, conf_node* node);
00153     conf_node* process_end_element (xmlTextReaderPtr reader, conf_node* node);
00154     conf_node* process (xmlTextReaderPtr reader, conf_node* node);
00155 
00156     void do_load (conf_node& node);
00157     
00158     void expand (xmlTextWriterPtr writer, conf_node& node);
00159     void expand_childs (xmlTextWriterPtr writer, conf_node& node);
00160     void expand_value (xmlTextWriterPtr writer, conf_node& node);
00161 };
00162 
00163 } /* namespace base */
00164 } /* namespace psynth */
00165 
00166 #endif /* PSYNTH_CONFBACKENDXML_H */