Whole document tree
    

Whole document tree

sstream.tcc Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sstream.tcc

Go to the documentation of this file.
00001 // String based streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997-1999, 2001 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // 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
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 //
00031 // ISO C++ 14882: 27.7  String-based streams
00032 //
00033 
00034 #ifndef _CPP_BITS_SSTREAM_TCC
00035 #define _CPP_BITS_SSTREAM_TCC   1
00036 
00037 #include <bits/std_sstream.h>
00038 
00039 namespace std
00040 {
00041 
00042   template <class _CharT, class _Traits, class _Alloc>
00043     typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type 
00044     basic_stringbuf<_CharT, _Traits, _Alloc>::
00045     pbackfail(int_type __c)
00046     {
00047       int_type __ret = traits_type::eof();
00048       bool __testeof = traits_type::eq_int_type(__c, traits_type::eof());
00049       bool __testpos = _M_in_cur && _M_in_beg < _M_in_cur; 
00050       
00051       // Try to put back __c into input sequence in one of three ways.
00052       // Order these tests done in is unspecified by the standard.
00053       if (__testpos)
00054     {
00055       if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])
00056           && !__testeof)
00057         {
00058           --_M_in_cur;
00059           __ret = __c;
00060         }
00061       else if (!__testeof)
00062         {
00063           --_M_in_cur;
00064           *_M_in_cur = traits_type::to_char_type(__c);
00065           __ret = __c;
00066         }
00067       else if (__testeof)
00068         {
00069           --_M_in_cur;
00070           __ret = traits_type::not_eof(__c);
00071         }
00072     }
00073       return __ret;
00074     }
00075   
00076   template <class _CharT, class _Traits, class _Alloc>
00077     typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type 
00078     basic_stringbuf<_CharT, _Traits, _Alloc>::
00079     overflow(int_type __c)
00080     {
00081       int_type __ret = traits_type::eof();
00082       bool __testeof = traits_type::eq_int_type(__c, __ret);
00083       bool __testwrite = _M_out_cur < _M_buf + _M_buf_size;
00084       bool __testout = _M_mode & ios_base::out;
00085 
00086       // Try to append __c into output sequence in one of two ways.
00087       // Order these tests done in is unspecified by the standard.
00088       if (__testout)
00089     {
00090       if (!__testeof)
00091         {
00092           __size_type __len = max(_M_buf_size, _M_buf_size_opt);
00093           __len *= 2;
00094 
00095           if (__testwrite)
00096         __ret = this->sputc(__c);
00097           else if (__len <= _M_string.max_size())
00098         {
00099           // Force-allocate, re-sync.
00100           _M_string = this->str();
00101           _M_string.reserve(__len);
00102           _M_buf_size = static_cast<int_type>(__len);
00103           _M_really_sync(_M_in_cur - _M_in_beg, 
00104                  _M_out_cur - _M_out_beg);
00105           *_M_out_cur = traits_type::to_char_type(__c);
00106           _M_out_cur_move(1);
00107           __ret = __c;
00108         }
00109         }
00110       else
00111         __ret = traits_type::not_eof(__c);
00112     }
00113       return __ret;
00114     }
00115 
00116   template <class _CharT, class _Traits, class _Alloc>
00117     typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
00118     basic_stringbuf<_CharT, _Traits, _Alloc>::
00119     seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
00120     {
00121       pos_type __ret =  pos_type(off_type(-1)); 
00122       bool __testin = __mode & ios_base::in && _M_mode & ios_base::in;
00123       bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
00124       bool __testboth = __testin && __testout && __way != ios_base::cur;
00125       
00126       if (_M_buf_size && ((__testin != __testout) || __testboth))
00127     {
00128       char_type* __beg = _M_buf;
00129       char_type* __curi = NULL;
00130       char_type* __curo = NULL;
00131       char_type* __endi = NULL;
00132       char_type* __endo = NULL;
00133 
00134       if (__testin)
00135         {
00136           __curi = this->gptr();
00137           __endi = this->egptr();
00138         }
00139       if (__testout)
00140         {
00141           __curo = this->pptr();
00142           __endo = this->epptr();
00143         }
00144 
00145       off_type __newoffi = 0;
00146       off_type __newoffo = 0;
00147       if (__way == ios_base::cur)
00148         {
00149           __newoffi = __curi - __beg;
00150           __newoffo = __curo - __beg;
00151         }
00152       else if (__way == ios_base::end)
00153         {
00154           __newoffi = __endi - __beg;
00155           __newoffo = __endo - __beg;
00156         }
00157 
00158       if (__testin
00159           && __newoffi + __off >= 0 && __endi - __beg >= __newoffi + __off)
00160         {
00161           _M_in_cur = __beg + __newoffi + __off;
00162           __ret = pos_type(__newoffi);
00163         }
00164       if (__testout
00165           && __newoffo + __off >= 0 && __endo - __beg >= __newoffo + __off)
00166         {
00167           _M_out_cur_move(__newoffo + __off - (_M_out_cur - __beg));
00168           __ret = pos_type(__newoffo);
00169         }
00170     }
00171       return __ret;
00172     }
00173 
00174   template <class _CharT, class _Traits, class _Alloc>
00175     typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
00176     basic_stringbuf<_CharT, _Traits, _Alloc>::
00177     seekpos(pos_type __sp, ios_base::openmode __mode)
00178     {
00179       pos_type __ret =  pos_type(off_type(-1)); 
00180       off_type __pos = __sp._M_position();
00181       char_type* __beg = NULL;
00182       char_type* __end = NULL;
00183       bool __testin = __mode & ios_base::in && _M_mode & ios_base::in;
00184       bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
00185       
00186       if (__testin)
00187     {
00188       __beg = this->eback();
00189       __end = this->egptr();
00190     }
00191       if (__testout)
00192     {
00193       __beg = this->pbase();
00194       __end = _M_buf + _M_buf_size;
00195     }
00196  
00197       if (0 <= __pos && __pos <= __end - __beg)
00198     {
00199       // Need to set both of these if applicable
00200       if (__testin)
00201         _M_in_cur = _M_in_beg + __pos;
00202       if (__testout)
00203         _M_out_cur_move((__pos) - (_M_out_cur - __beg));
00204       __ret = pos_type(off_type(__pos));
00205     }
00206       
00207       return __ret;
00208     }
00209 
00210 } // namespace std
00211 
00212 #endif  /* _CPP_BITS_SSTREAM_TCC */
00213 

Generated on Mon Apr 8 03:11:32 2002 for libstdc++-v3 Source by doxygen1.2.15