Whole document tree
    

Whole document tree

std_ostream.h Source File
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, _Traits>  __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 
00072       // 27.6.2.3 Prefix/suffix:
00073       class sentry;
00074       friend class sentry;
00075       
00076       // 27.6.2.5 Formatted output:
00077       // 27.6.2.5.3  basic_ostream::operator<<
00078       __ostream_type&
00079       operator<<(__ostream_type& (*__pf)(__ostream_type&));
00080       
00081       __ostream_type&
00082       operator<<(__ios_type& (*__pf)(__ios_type&));
00083       
00084       __ostream_type&
00085       operator<<(ios_base& (*__pf) (ios_base&));
00086 
00087       // 27.6.2.5.2 Arithmetic Inserters
00088       __ostream_type& 
00089       operator<<(long __n);
00090       
00091       __ostream_type& 
00092       operator<<(unsigned long __n);
00093 
00094       __ostream_type& 
00095       operator<<(bool __n);
00096 
00097       __ostream_type& 
00098       operator<<(short __n)
00099       { 
00100     ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00101     if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00102       return this->operator<<(static_cast<unsigned long>
00103                   (static_cast<unsigned short>(__n)));
00104     else
00105       return this->operator<<(static_cast<long>(__n));
00106       }
00107 
00108       __ostream_type& 
00109       operator<<(unsigned short __n)
00110       { return this->operator<<(static_cast<unsigned long>(__n)); }
00111 
00112       __ostream_type& 
00113       operator<<(int __n)
00114       { 
00115     ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00116     if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00117       return this->operator<<(static_cast<unsigned long>
00118                   (static_cast<unsigned int>(__n)));
00119     else
00120       return this->operator<<(static_cast<long>(__n));
00121       }
00122 
00123       __ostream_type& 
00124       operator<<(unsigned int __n)
00125       { return this->operator<<(static_cast<unsigned long>(__n)); }
00126 
00127 #ifdef _GLIBCPP_USE_LONG_LONG
00128       __ostream_type& 
00129       operator<<(long long __n);
00130 
00131       __ostream_type& 
00132       operator<<(unsigned long long __n);
00133 #endif
00134 
00135       __ostream_type& 
00136       operator<<(double __f);
00137 
00138       __ostream_type& 
00139       operator<<(float __f)
00140       { return this->operator<<(static_cast<double>(__f)); }
00141 
00142       __ostream_type& 
00143       operator<<(long double __f);
00144 
00145       __ostream_type& 
00146       operator<<(const void* __p);
00147 
00148       __ostream_type& 
00149       operator<<(__streambuf_type* __sb);
00150 
00151       // Unformatted output:
00152       __ostream_type& 
00153       put(char_type __c);
00154 
00155       __ostream_type& 
00156       write(const char_type* __s, streamsize __n);
00157 
00158       __ostream_type& 
00159       flush();
00160 
00161       // Seeks:
00162       pos_type 
00163       tellp();
00164 
00165       __ostream_type& 
00166       seekp(pos_type);
00167 
00168       __ostream_type& 
00169       seekp(off_type, ios_base::seekdir);
00170 
00171     private:
00172 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00173       // Not defined.
00174       __ostream_type& 
00175       operator=(const __ostream_type&);
00176 
00177       basic_ostream(const __ostream_type&);
00178 #endif
00179     };
00180 
00181   // 27.6.2.3  Class basic_ostream::sentry
00182   template <typename _CharT, typename _Traits>
00183     class basic_ostream<_CharT, _Traits>::sentry
00184     {
00185       // Data Members:
00186       bool              _M_ok;
00187       basic_ostream<_CharT,_Traits>&    _M_os;
00188       
00189     public:
00190       explicit
00191       sentry(basic_ostream<_CharT,_Traits>& __os);
00192 
00193       ~sentry()
00194       {
00195     // XXX MT
00196     if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
00197       {
00198         // Can't call flush directly or else will get into recursive lock.
00199         if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
00200           _M_os.setstate(ios_base::badbit);
00201       }
00202       }
00203 
00204       operator bool() 
00205       { return _M_ok; }
00206     };
00207 
00208   template<typename _CharT, typename _Traits>
00209     basic_ostream<_CharT, _Traits>&
00210     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c);
00211 
00212   template<typename _CharT, typename _Traits>
00213     basic_ostream<_CharT, _Traits>&
00214     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
00215     { return (__out << __out.widen(__c)); }
00216 
00217   // Specialization
00218   template <class _Traits> 
00219     basic_ostream<char, _Traits>&
00220     operator<<(basic_ostream<char, _Traits>& __out, char __c);
00221 
00222   // Signed and unsigned
00223   template<class _Traits>
00224     basic_ostream<char, _Traits>&
00225     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
00226     { return (__out << static_cast<char>(__c)); }
00227   
00228   template<class _Traits>
00229     basic_ostream<char, _Traits>&
00230     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
00231     { return (__out << static_cast<char>(__c)); }
00232   
00233   template<typename _CharT, typename _Traits>
00234     basic_ostream<_CharT, _Traits>&
00235     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s);
00236 
00237   template<typename _CharT, typename _Traits>
00238     basic_ostream<_CharT, _Traits> &
00239     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
00240 
00241   // Partial specializationss
00242   template<class _Traits>
00243     basic_ostream<char, _Traits>&
00244     operator<<(basic_ostream<char, _Traits>& __out, const char* __s);
00245  
00246   // Signed and unsigned
00247   template<class _Traits>
00248     basic_ostream<char, _Traits>&
00249     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
00250     { return (__out << reinterpret_cast<const char*>(__s)); }
00251 
00252   template<class _Traits>
00253     basic_ostream<char, _Traits> &
00254     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
00255     { return (__out << reinterpret_cast<const char*>(__s)); }
00256 
00257   // 27.6.2.7 Standard basic_ostream manipulators
00258   template<typename _CharT, typename _Traits>
00259     basic_ostream<_CharT, _Traits>& 
00260     endl(basic_ostream<_CharT, _Traits>& __os)
00261     { return flush(__os.put(__os.widen('\n'))); }
00262 
00263   template<typename _CharT, typename _Traits>
00264     basic_ostream<_CharT, _Traits>& 
00265     ends(basic_ostream<_CharT, _Traits>& __os)
00266     { return __os.put(_CharT()); }
00267   
00268   template<typename _CharT, typename _Traits>
00269     basic_ostream<_CharT, _Traits>& 
00270     flush(basic_ostream<_CharT, _Traits>& __os)
00271     { return __os.flush(); }
00272 
00273 } // namespace std
00274 
00275 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00276 # define export
00277 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
00278 # include <bits/ostream.tcc>
00279 #endif
00280 #endif
00281 
00282 #endif  /* _CPP_OSTREAM */
00283 

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