ximol/fstream.cpp

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 implementations.
00024         
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: fstream.cpp,v 1.5 2004/02/25 18:58:39 tournois Exp $
00029     $Log: fstream.cpp,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 #include <ximol/fstream.hpp>
00048 #include <ximol/encoders/encoders.hpp>
00049 
00050 
00051 XIMOL_BEGIN_NAMESPACE
00052 
00053 
00054 //-----------------------------------------------------------------------------
00055 //
00056 //-----------------------------------------------------------------------------
00057 xofstream::xofstream()
00058   :buf_()
00059 {
00060         XIMOL_ENCODERS_USING_NAMESPACE;
00061 
00062         this->init(&buf_);
00063         prepare_ios(*this);
00064         encoding(XIMOL_DEFAULT_ENCODING);
00065 }
00066 
00067 //-----------------------------------------------------------------------------
00068 //
00069 //-----------------------------------------------------------------------------
00070 xofstream::xofstream(const char* name, const char* encoding_name, std::ios_base::openmode mode)
00071   :buf_()
00072 {
00073         XIMOL_ENCODERS_USING_NAMESPACE;
00074 
00075         this->init(&buf_);
00076         prepare_ios(*this);
00077         encoding(encoding_name);
00078         open(name, mode | binary);
00079 }
00080 
00081 //-----------------------------------------------------------------------------
00082 //
00083 //-----------------------------------------------------------------------------
00084 xofstream::xofstream(const char* name, std::ios_base::openmode mode, const char* encoding_name)
00085   :buf_()
00086 {
00087         XIMOL_ENCODERS_USING_NAMESPACE;
00088 
00089         this->init(&buf_);
00090         prepare_ios(*this);
00091         encoding(encoding_name);
00092         open(name, mode | binary);
00093 }
00094 
00095 //-----------------------------------------------------------------------------
00096 //
00097 //-----------------------------------------------------------------------------
00098 xofstream::~xofstream()
00099 {
00100 }
00101 
00102 //-----------------------------------------------------------------------------
00103 //
00104 //-----------------------------------------------------------------------------
00105 ::std::basic_filebuf<xchar_t>* xofstream::rdbuf()
00106 {
00107         return &buf_;
00108 }
00109 
00110 //-----------------------------------------------------------------------------
00111 //
00112 //-----------------------------------------------------------------------------
00113 bool xofstream::is_open() const
00114 {
00115         return buf_.is_open();
00116 }
00117 
00118 //-----------------------------------------------------------------------------
00119 //
00120 //-----------------------------------------------------------------------------
00121 void xofstream::open(const char* filename, openmode mode )
00122 {
00123         if (!buf_.open(filename, mode | out | binary))
00124       this->setstate(failbit);
00125 }
00126 
00127 //-----------------------------------------------------------------------------
00128 //
00129 //-----------------------------------------------------------------------------
00130 void xofstream::close()
00131 {
00132     if (!buf_.close())
00133       this->setstate(failbit);
00134 }
00135 
00136 //-----------------------------------------------------------------------------
00137 //
00138 //-----------------------------------------------------------------------------
00139 xifstream::xifstream()
00140   :buf_()
00141 {
00142         XIMOL_ENCODERS_USING_NAMESPACE;
00143 
00144         this->init(&buf_);
00145         prepare_ios(*this);
00146         encoding(XIMOL_DEFAULT_ENCODING);
00147 }
00148 
00149 //-----------------------------------------------------------------------------
00150 //
00151 //-----------------------------------------------------------------------------
00152 xifstream::xifstream(const char* name, const char* encoding_name, std::ios_base::openmode mode)
00153   :buf_()
00154 {
00155         XIMOL_ENCODERS_USING_NAMESPACE;
00156 
00157         this->init(&buf_);
00158         prepare_ios(*this);
00159         encoding(encoding_name);
00160         open(name, mode | binary);
00161 }
00162 
00163 //-----------------------------------------------------------------------------
00164 //
00165 //-----------------------------------------------------------------------------
00166 xifstream::xifstream(const char* name, std::ios_base::openmode mode, const char* encoding_name)
00167   :buf_()
00168 {
00169         XIMOL_ENCODERS_USING_NAMESPACE;
00170 
00171         this->init(&buf_);
00172         prepare_ios(*this);
00173         encoding(encoding_name);
00174         open(name, mode | binary);
00175 }
00176 
00177 //-----------------------------------------------------------------------------
00178 //
00179 //-----------------------------------------------------------------------------
00180 xifstream::~xifstream()
00181 {
00182 }
00183 
00184 //-----------------------------------------------------------------------------
00185 //
00186 //-----------------------------------------------------------------------------
00187 ::std::basic_filebuf<xchar_t>* xifstream::rdbuf()
00188 {
00189         return &buf_;
00190 }
00191 
00192 //-----------------------------------------------------------------------------
00193 //
00194 //-----------------------------------------------------------------------------
00195 bool xifstream::is_open() const
00196 {
00197         return buf_.is_open();
00198 }
00199 
00200 //-----------------------------------------------------------------------------
00201 //
00202 //-----------------------------------------------------------------------------
00203 void xifstream::open(const char* filename, openmode mode )
00204 {
00205         if (!buf_.open(filename, mode | in | binary))
00206       this->setstate(failbit);
00207 }
00208 
00209 //-----------------------------------------------------------------------------
00210 //
00211 //-----------------------------------------------------------------------------
00212 void xifstream::close()
00213 {
00214     if (!buf_.close())
00215       this->setstate(failbit);
00216 }
00217 
00218 //-----------------------------------------------------------------------------
00219 //
00220 //-----------------------------------------------------------------------------
00221 xfstream::xfstream()
00222   :xiostream()
00223   ,buf_()
00224 {
00225         this->init(&buf_);
00226 }
00227 
00228 //-----------------------------------------------------------------------------
00229 //
00230 //-----------------------------------------------------------------------------
00231 xfstream::xfstream(const char* name, const char* encoding_name, std::ios_base::openmode mode)
00232   :buf_()
00233 {
00234         XIMOL_ENCODERS_USING_NAMESPACE;
00235 
00236         this->init(&buf_);
00237         prepare_ios(*this);
00238         xostream::encoding(encoding_name);
00239         xistream::encoding(encoding_name);
00240         open(name, mode | binary);
00241 }
00242 
00243 //-----------------------------------------------------------------------------
00244 //
00245 //-----------------------------------------------------------------------------
00246 xfstream::xfstream(const char* name, std::ios_base::openmode mode, const char* encoding_name)
00247   :buf_()
00248 {
00249         XIMOL_ENCODERS_USING_NAMESPACE;
00250 
00251         this->init(&buf_);
00252         prepare_ios(*this);
00253         xostream::encoding(encoding_name);
00254         xistream::encoding(encoding_name);
00255         open(name, mode | binary);
00256 }
00257 
00258 //-----------------------------------------------------------------------------
00259 //
00260 //-----------------------------------------------------------------------------
00261 xfstream::~xfstream()
00262 {
00263 }
00264 
00265 //-----------------------------------------------------------------------------
00266 //
00267 //-----------------------------------------------------------------------------
00268 ::std::basic_filebuf<xchar_t>* xfstream::rdbuf()
00269 {
00270         return &buf_;
00271 }
00272 
00273 //-----------------------------------------------------------------------------
00274 //
00275 //-----------------------------------------------------------------------------
00276 bool xfstream::is_open() const
00277 {
00278         return buf_.is_open();
00279 }
00280 
00281 //-----------------------------------------------------------------------------
00282 //
00283 //-----------------------------------------------------------------------------
00284 void xfstream::open(const char* filename, openmode mode )
00285 {
00286         if (!buf_.open(filename, mode | binary))
00287                 this->setstate(failbit);
00288 }
00289 
00290 //-----------------------------------------------------------------------------
00291 //
00292 //-----------------------------------------------------------------------------
00293 void xfstream::close()
00294 {
00295     if (!buf_.close())
00296       this->setstate(failbit);
00297 }
00298 
00299 
00300 XIMOL_END_NAMESPACE


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