ximol/fstream.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: fstream.hpp,v 1.5 2004/02/25 18:58:39 tournois Exp $
00029     $Log: fstream.hpp,v $
00030     Revision 1.5  2004/02/25 18:58:39  tournois
00031     imporve the gcc compatibility.
00032 
00033     Revision 1.4  2004/02/22 10:27:32  tournois
00034     Add some doc.
00035 
00036     Revision 1.3  2004/02/22 09:54:19  tournois
00037     Change years on the copyright.
00038 
00039     Revision 1.2  2003/10/25 13:53:39  hfp
00040     review and separation
00041 
00042     Revision 1.1  2003/10/24 15:53:13  hfp
00043     separation of each public class into one file
00044 
00045   */
00046 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00047 #ifndef XIMOL_FSTREAM_HPP_
00048 #define XIMOL_FSTREAM_HPP_
00049 
00050 #include <ximol/stream.hpp>
00051 
00052 #include <fstream>
00053 
00054 
00055 XIMOL_BEGIN_NAMESPACE
00056 
00057 
00058 //=============================================================================
00059 /// class xofstream 
00060 //=============================================================================
00061 class XIMOL_EXPORT xofstream
00062         : public xostream
00063 {
00064 public: // constructor(s) & destructor
00065         /// Default constructor - use open()-method to specify a file.
00066         xofstream();
00067 
00068         explicit xofstream(const char* name,
00069                                            const char* encoding_name = XIMOL_DEFAULT_ENCODING,
00070                        std::ios_base::openmode mode = std::ios_base::out);
00071 
00072         xofstream(const char* name, std::ios_base::openmode mode,
00073                           const char* encoding_name = XIMOL_DEFAULT_ENCODING);
00074 
00075         ~xofstream();
00076 
00077 public: // methods
00078         ::std::basic_filebuf<xchar_t>* rdbuf();
00079 
00080         bool is_open() const;
00081 
00082         void open(const char* filename, 
00083                           openmode mode = std::ios_base::out);
00084 
00085         void close();
00086 
00087         inline xostream& operator<<(xchar_t c)  { return xostream::operator<<(c); }
00088         inline xostream& operator<<(char c)             { return xostream::operator<<(c); }
00089 
00090 private: // data members
00091         ::std::basic_filebuf<xchar_t> buf_;
00092 };
00093 
00094 
00095 //=============================================================================
00096 /// class xifstream 
00097 //=============================================================================
00098 class XIMOL_EXPORT xifstream
00099         : public xistream
00100 {
00101 public: // constructor(s) & destructor
00102         xifstream();
00103 
00104         explicit xifstream(const char* name,
00105                                            const char* encoding_name = XIMOL_DEFAULT_ENCODING,
00106                                            std::ios_base::openmode mode = std::ios_base::in);
00107 
00108         xifstream(const char* name, std::ios_base::openmode mode,
00109                           const char* encoding_name = XIMOL_DEFAULT_ENCODING);
00110 
00111         ~xifstream();
00112 
00113 public: // methods
00114         ::std::basic_filebuf<xchar_t>* rdbuf();
00115 
00116         bool is_open() const;
00117 
00118         void open(const char* filename, 
00119                           openmode mode = std::ios_base::in);
00120 
00121         void close();
00122 
00123     inline xistream& operator>>(xchar_t& c)     { return xistream::operator>>(c); }
00124         inline xistream& operator>>(char& c)    { return xistream::operator>>(c); }
00125 
00126 private: // data members
00127         ::std::basic_filebuf<xchar_t> buf_;
00128 };
00129 
00130 
00131 //=============================================================================
00132 /// class xfstream 
00133 //=============================================================================
00134 class XIMOL_EXPORT xfstream
00135         : public xiostream
00136 {
00137 public: // constructor(s) & destructor
00138         xfstream();
00139 
00140         explicit xfstream(const char* name,
00141                                           const char* encoding_name = XIMOL_DEFAULT_ENCODING,
00142                                           std::ios_base::openmode mode = std::ios_base::in | out);
00143 
00144         xfstream(const char* name, std::ios_base::openmode mode,
00145                          const char* encoding_name = XIMOL_DEFAULT_ENCODING);
00146 
00147         ~xfstream();
00148 
00149 public: // methods
00150         ::std::basic_filebuf<xchar_t>* rdbuf();
00151 
00152         bool is_open() const;
00153 
00154         void open(const char* filename, 
00155                           openmode mode = std::ios_base::in | out);
00156 
00157         void close();
00158 
00159         inline xostream& operator<<(xchar_t c)  { return xostream::operator<<(c); }
00160         inline xostream& operator<<(char c)             { return xostream::operator<<(c); }
00161         inline xistream& operator>>(xchar_t& c) { return xistream::operator>>(c); }
00162         inline xistream& operator>>(char& c)    { return xistream::operator>>(c); }
00163 
00164 private: // data members
00165         ::std::basic_filebuf<xchar_t> buf_;
00166 };
00167 
00168 
00169 XIMOL_END_NAMESPACE 
00170 
00171 #endif // #ifndef XIMOL_FSTREAM_HPP_


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