Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

std_ostream.h

Go to the documentation of this file.
00001 // Output streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 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.6.2  Output streams
00032 //
00033 
00034 #ifndef _CPP_OSTREAM
00035 #define _CPP_OSTREAM    1
00036 
00037 #pragma GCC system_header
00038 
00039 #include <bits/std_ios.h>
00040 
00041 namespace std
00042 {
00043   // 27.6.2.1 Template class basic_ostream
00044   template<typename _CharT, typename _Traits>
00045     class basic_ostream : virtual public basic_ios<_CharT, _Traits>
00046     {
00047     public:
00048 
00049       // Types (inherited from basic_ios (27.4.4)):
00050       typedef _CharT                            char_type;
00051       typedef typename _Traits::int_type        int_type;
00052       typedef typename _Traits::pos_type        pos_type;
00053       typedef typename _Traits::off_type        off_type;
00054       typedef _Traits                           traits_type;
00055       
00056       // Non-standard Types:
00057       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00058       typedef basic_ios<_CharT, _Traits>        __ios_type;
00059       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00060       typedef ostreambuf_iterator<_CharT>       __ostreambuf_iter;
00061       typedef num_put<_CharT, __ostreambuf_iter>        __numput_type;
00062       typedef ctype<_CharT>                     __ctype_type;
00063 
00064       // 27.6.2.2 Constructor/destructor:
00065       explicit 
00066       basic_ostream(__streambuf_type* __sb)
00067       { this->init(__sb); }
00068 
00069       virtual 
00070       ~basic_ostream() 
00071       { _M_fnumput = NULL; }
00072 
00073       // 27.6.2.3 Prefix/suffix:
00074       class sentry;
00075       friend class sentry;
00076       
00077       // 27.6.2.5 Formatted output:
00078       // 27.6.2.5.3  basic_ostream::operator<<
00079       __ostream_type&
00080       operator<<(__ostream_type& (*__pf)(__ostream_type&));
00081       
00082       __ostream_type&
00083       operator<<(__ios_type& (*__pf)(__ios_type&));
00084       
00085       __ostream_type&
00086       operator<<(ios_base& (*__pf) (ios_base&));
00087 
00088       // 27.6.2.5.2 Arithmetic Inserters
00089       __ostream_type& 
00090       operator<<(long __n);
00091       
00092       __ostream_type& 
00093       operator<<(unsigned long __n);
00094 
00095       __ostream_type& 
00096       operator<<(bool __n);
00097 
00098       __ostream_type& 
00099       operator<<(short __n)
00100       { 
00101     ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00102     if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00103       return this->operator<<(static_cast<unsigned long>
00104                   (static_cast<unsigned short>(__n)));
00105     else
00106       return this->operator<<(static_cast<long>(__n));
00107       }
00108 
00109       __ostream_type& 
00110       operator<<(unsigned short __n)
00111       { return this->operator<<(static_cast<unsigned long>(__n)); }
00112 
00113       __ostream_type& 
00114       operator<<(int __n)
00115       { 
00116     ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00117     if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00118       return this->operator<<(static_cast<unsigned long>
00119                   (static_cast<unsigned int>(__n)));
00120     else
00121       return this->operator<<(static_cast<long>(__n));
00122       }
00123 
00124       __ostream_type& 
00125       operator<<(unsigned int __n)
00126       { return this->operator<<(static_cast<unsigned long>(__n)); }
00127 
00128 #ifdef _GLIBCPP_USE_LONG_LONG
00129       __ostream_type& 
00130       operator<<(long long __n);
00131 
00132       __ostream_type& 
00133       operator<<(unsigned long long __n);
00134 #endif
00135 
00136       __ostream_type& 
00137       operator<<(double __f);
00138 
00139       __ostream_type& 
00140       operator<<(float __f)
00141       { return this->operator<<(static_cast<double>(__f)); }
00142 
00143       __ostream_type& 
00144       operator<<(long double __f);
00145 
00146       __ostream_type& 
00147       operator<<(const void* __p);
00148 
00149       __ostream_type& 
00150       operator<<(__streambuf_type* __sb);
00151 
00152       // Unformatted output:
00153       __ostream_type& 
00154       put(char_type __c);
00155 
00156       __ostream_type& 
00157       write(const char_type* __s, streamsize __n);
00158 
00159       __ostream_type& 
00160       flush();
00161 
00162       // Seeks:
00163       pos_type 
00164       tellp();
00165 
00166       __ostream_type& 
00167       seekp(pos_type);
00168 
00169       __ostream_type& 
00170       seekp(off_type, ios_base::seekdir);
00171 
00172     private:
00173 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00174       // Not defined.
00175       __ostream_type& 
00176       operator=(const __ostream_type&);
00177 
00178       basic_ostream(const __ostream_type&);
00179 #endif
00180     };
00181 
00182   // 27.6.2.3  Class basic_ostream::sentry
00183   template <typename _CharT, typename _Traits>
00184     class basic_ostream<_CharT, _Traits>::sentry
00185     {
00186       // Data Members:
00187       bool              _M_ok;
00188       basic_ostream<_CharT,_Traits>&    _M_os;
00189       
00190     public:
00191       explicit
00192       sentry(basic_ostream<_CharT,_Traits>& __os);
00193 
00194       ~sentry()
00195       {
00196     // XXX MT
00197     if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
00198       {
00199         // Can't call flush directly or else will get into recursive lock.
00200         if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
00201           _M_os.setstate(ios_base::badbit);
00202       }
00203       }
00204 
00205       operator bool() 
00206       { return _M_ok; }
00207     };
00208 
00209   template<typename _CharT, typename _Traits>
00210     basic_ostream<_CharT, _Traits>&
00211     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c);
00212 
00213   template<typename _CharT, typename _Traits>
00214     basic_ostream<_CharT, _Traits>&
00215     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
00216     { return (__out << __out.widen(__c)); }
00217 
00218   // Specialization
00219   template <class _Traits> 
00220     basic_ostream<char, _Traits>&
00221     operator<<(basic_ostream<char, _Traits>& __out, char __c);
00222 
00223   // Signed and unsigned
00224   template<class _Traits>
00225     basic_ostream<char, _Traits>&
00226     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
00227     { return (__out << static_cast<char>(__c)); }
00228   
00229   template<class _Traits>
00230     basic_ostream<char, _Traits>&
00231     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
00232     { return (__out << static_cast<char>(__c)); }
00233   
00234   template<typename _CharT, typename _Traits>
00235     basic_ostream<_CharT, _Traits>&
00236     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s);
00237 
00238   template<typename _CharT, typename _Traits>
00239     basic_ostream<_CharT, _Traits> &
00240     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
00241 
00242   // Partial specializationss
00243   template<class _Traits>
00244     basic_ostream<char, _Traits>&
00245     operator<<(basic_ostream<char, _Traits>& __out, const char* __s);
00246  
00247   // Signed and unsigned
00248   template<class _Traits>
00249     basic_ostream<char, _Traits>&
00250     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
00251     { return (__out << reinterpret_cast<const char*>(__s)); }
00252 
00253   template<class _Traits>
00254     basic_ostream<char, _Traits> &
00255     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
00256     { return (__out << reinterpret_cast<const char*>(__s)); }
00257 
00258   // 27.6.2.7 Standard basic_ostream manipulators
00259   template<typename _CharT, typename _Traits>
00260     basic_ostream<_CharT, _Traits>& 
00261     endl(basic_ostream<_CharT, _Traits>& __os)
00262     { return flush(__os.put(__os.widen('\n'))); }
00263 
00264   template<typename _CharT, typename _Traits>
00265     basic_ostream<_CharT, _Traits>& 
00266     ends(basic_ostream<_CharT, _Traits>& __os)
00267     { return __os.put(_CharT()); }
00268   
00269   template<typename _CharT, typename _Traits>
00270     basic_ostream<_CharT, _Traits>& 
00271     flush(basic_ostream<_CharT, _Traits>& __os)
00272     { return __os.flush(); }
00273 
00274 } // namespace std
00275 
00276 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00277 # define export
00278 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
00279 # include <bits/ostream.tcc>
00280 #endif
00281 #endif
00282 
00283 #endif  /* _CPP_OSTREAM */
00284 

Generated at Tue May 1 16:28:38 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001