Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/xml/xmldeserializer.h

00001 /*
00002  * Copyright (C) 2008 by Marc Boris Duerner
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 #ifndef xis_cxxtools_XmlDeserializer_h
00029 #define xis_cxxtools_XmlDeserializer_h
00030 
00031 #include <cxxtools/string.h>
00032 #include <cxxtools/deserializer.h>
00033 #include "cxxtools/xml/xmlreader.h"
00034 #include <memory>
00035 
00036 namespace cxxtools
00037 {
00038 
00039 namespace xml
00040 {
00041 
00042     class XmlReader;
00043     class Node;
00044 
00050     class XmlDeserializer : public Deserializer
00051     {
00052         public:
00053             XmlDeserializer(cxxtools::xml::XmlReader& reader);
00054 
00055             XmlDeserializer(std::istream& is);
00056 
00057             cxxtools::xml::XmlReader& reader()
00058             { return *_reader; }
00059 
00060             template <typename T>
00061             static void toObject(const std::string& str, T& type)
00062             {
00063                std::istringstream in(str);
00064                XmlDeserializer d(in);
00065                d.deserialize(type);
00066             }
00067 
00068             template <typename T>
00069             static void toObject(XmlReader& in, T& type)
00070             {
00071                XmlDeserializer d(in);
00072                d.deserialize(type);
00073             }
00074 
00075             template <typename T>
00076             static void toObject(std::istream& in, T& type)
00077             {
00078                XmlDeserializer d(in);
00079                d.deserialize(type);
00080             }
00081 
00082         protected:
00083             void doDeserialize();
00084 
00086             void beginDocument(const cxxtools::xml::Node& node);
00087 
00089             void onRootElement(const cxxtools::xml::Node& node);
00090 
00092             void onStartElement(const cxxtools::xml::Node& node);
00093 
00095             void onWhitespace(const cxxtools::xml::Node& node);
00096 
00098             void onContent(const cxxtools::xml::Node& node);
00099 
00101             void onEndElement(const cxxtools::xml::Node& node);
00102 
00103         private:
00105             cxxtools::xml::XmlReader* _reader;
00106 
00108             std::auto_ptr<cxxtools::xml::XmlReader> _deleter;
00109 
00111             typedef void (XmlDeserializer::*ProcessNode)(const cxxtools::xml::Node&);
00112 
00114             ProcessNode _processNode;
00115 
00116             size_t _startDepth;
00117 
00119             cxxtools::String _nodeName;
00120 
00121             cxxtools::String _nodeId;
00122 
00123             cxxtools::String _nodeType;
00124 
00125             cxxtools::String _nodeCategory;
00126 
00127             SerializationInfo::Category nodeCategory() const;
00128 
00129     };
00130 
00131 } // namespace xml
00132 
00133 } // namespace cxxtools
00134 
00135 #endif
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6