ximol/stream.hpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002  *                                                                           *
00003  * library XiMoL                                                             *
00004  * Copyright (C) 2002, 2003, 2004 Florent Tournois                           *
00005  *                                                                           *
00006  * This library is free software; you can redistribute it and/or             *
00007  * modify it under the terms of the GNU Lesser General Public                *
00008  * License as published by the Free Software Foundation; either              *
00009  * version 2.1 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  * Lesser General Public License for more details.                           *
00015  *                                                                           *
00016  * You should have received a copy of the GNU Lesser General Public          *
00017  * License along with this library; if not, write to the Free Software       *
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   *
00019  *                                                                           *
00020 \*****************************************************************************/
00021 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00022 /** \file 
00023         \brief XML streams declarations.
00024         
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: stream.hpp,v 1.8 2004/02/22 10:27:33 tournois Exp $
00029     $Log: stream.hpp,v $
00030     Revision 1.8  2004/02/22 10:27:33  tournois
00031     Add some doc.
00032 
00033     Revision 1.7  2004/02/22 09:54:19  tournois
00034     Change years on the copyright.
00035 
00036     Revision 1.6  2003/11/02 19:23:01  tournois
00037     Go to the boost coding standard.
00038     Change all name to lower case.
00039 
00040     Revision 1.5  2003/10/25 13:53:39  hfp
00041     review and separation
00042 
00043     Revision 1.4  2003/10/09 16:59:45  tournois
00044     add the stringstream initialisation.
00045     add some prolog test.
00046     Correct code for VC6.0.
00047 
00048   */
00049 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00050 #ifndef XIMOL_STREAM_HPP_
00051 #define XIMOL_STREAM_HPP_
00052 
00053 #include <ximol/xml/context.hpp>
00054 #include <ximol/macros.hpp>
00055 
00056 #include <iostream>
00057 
00058 
00059 XIMOL_BEGIN_NAMESPACE
00060 
00061 
00062 //=============================================================================
00063 /// class ostream with context.
00064 //=============================================================================
00065 class XIMOL_EXPORT xostream
00066         : public ::std::basic_ostream<xchar_t>
00067 {
00068 public: // constructor(s) & destructor
00069         /// Contruct and set the encoding.
00070         /** @see XIMOL_DEFAULT_ENCODING */
00071         xostream(const char* encoding_name = XIMOL_DEFAULT_ENCODING);
00072 
00073 private: // restrict copy & assignment
00074         xostream(const xostream& x);
00075         xostream& operator=(const xostream&);
00076 
00077 public: // methods
00078         ::std::string encoding() const;
00079         void encoding(const char* encoding_name);
00080 
00081         xostream& operator<<(xchar_t c);
00082         xostream& operator<<(char c);
00083 
00084 public: // data members
00085         XIMOL_XML_NAMESPACE_PATH::context context;
00086 };
00087 
00088 
00089 //=============================================================================
00090 /// class istream with context.
00091 //=============================================================================
00092 class XIMOL_EXPORT xistream
00093         : public ::std::basic_istream<xchar_t>
00094 {
00095 public: // constructor(s) & destructor
00096         xistream(const char* encoding_name = XIMOL_DEFAULT_ENCODING);
00097 
00098 private: // restrict copy & assignment
00099         xistream(const xistream& x);
00100         xistream& operator=(const xistream&);
00101 
00102 public: // methods
00103         ::std::string encoding() const;
00104         void encoding(const char* encoding_name);
00105 
00106         bool get(xchar_t& xc);
00107         void putback(xchar_t xc);
00108         void putback(const xstring& xstr);
00109         xchar_t front() const;
00110         void pop_front();
00111 
00112         xistream& operator>>(xchar_t& c);
00113         xistream& operator>>(char& c);
00114 
00115 public: // data members
00116         XIMOL_XML_NAMESPACE_PATH::context context;
00117 
00118 private: // data members
00119         typedef class XIMOL_EXPORT ::std::list<xchar_t> buffer_type;
00120         buffer_type buffer_;
00121 };
00122 
00123 
00124 //=============================================================================
00125 /// class derived bfrom xistream and xostream.
00126 //=============================================================================
00127 class XIMOL_EXPORT xiostream
00128         : public xostream
00129         , public xistream
00130 {
00131 public: // constructor(s) & destructor
00132         xiostream(const char* encoding_name = XIMOL_DEFAULT_ENCODING);
00133 
00134 public: // methods
00135         inline xostream& operator<<(xchar_t c)  { return xostream::operator<<(c); }
00136         inline xostream& operator<<(char c)             { return xostream::operator<<(c); }
00137         inline xistream& operator>>(xchar_t& c) { return xistream::operator>>(c); }
00138         inline xistream& operator>>(char& c)    { return xistream::operator>>(c); }
00139 };
00140 
00141 
00142 //-----------------------------------------------------------------------------
00143 /// Change encoding.
00144 //-----------------------------------------------------------------------------
00145 XIMOL_EXPORT xostream& use_XML(xostream& xos,
00146                                                            const ::std::string& encoding_name = XIMOL_DEFAULT_ENCODING);
00147 
00148 
00149 //-----------------------------------------------------------------------------
00150 /// Change encoding.
00151 //-----------------------------------------------------------------------------
00152 XIMOL_EXPORT xistream& use_XML(xistream& xis,
00153                                                            const ::std::string& encoding_name = XIMOL_DEFAULT_ENCODING);
00154 
00155 
00156 XIMOL_END_NAMESPACE 
00157 
00158 #endif // #ifndef XIMOL_STREAM_HPP_


Donate to the XiMoL project SourceForge.net Logo If you have any questions about XiMoL, you could write to tournois@users.sourceforge.net.