Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. // Iostreams base classes -*- C++ -*-
  2.  
  3. // Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
  4. //
  5. // This file is part of the GNU ISO C++ Library.  This library is free
  6. // software; you can redistribute it and/or modify it under the
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 2, or (at your option)
  9. // any later version.
  10.  
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. // GNU General Public License for more details.
  15.  
  16. // You should have received a copy of the GNU General Public License along
  17. // with this library; see the file COPYING.  If not, write to the Free
  18. // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  19. // USA.
  20.  
  21. // As a special exception, you may use this file as part of a free software
  22. // library without restriction.  Specifically, if other files instantiate
  23. // templates or use macros or inline functions from this file, or you compile
  24. // this file and link it with other files to produce an executable, this
  25. // file does not by itself cause the resulting executable to be covered by
  26. // the GNU General Public License.  This exception does not however
  27. // invalidate any other reasons why the executable file might be covered by
  28. // the GNU General Public License.
  29.  
  30. #ifndef _CPP_BITS_BASICIOS_H
  31. #define _CPP_BITS_BASICIOS_H 1
  32.  
  33. #pragma GCC system_header
  34.  
  35. #include <bits/sbuf_iter.h>
  36. #include <bits/locale_facets.h>
  37.  
  38. namespace std
  39. {
  40.   // 27.4.5  Template class basic_ios
  41.   template<typename _CharT, typename _Traits>
  42.     class basic_ios : public ios_base
  43.     {
  44.     public:
  45.       // Types:
  46.       typedef _CharT                            char_type;
  47.       typedef typename _Traits::int_type        int_type;
  48.       typedef typename _Traits::pos_type        pos_type;
  49.       typedef typename _Traits::off_type        off_type;
  50.       typedef _Traits                           traits_type;
  51.  
  52.       // Non-standard Types:
  53.       typedef ctype<_CharT>                             __ctype_type;
  54.       typedef ostreambuf_iterator<_CharT, _Traits>      __ostreambuf_iter;
  55.       typedef num_put<_CharT, __ostreambuf_iter>        __numput_type;
  56.       typedef istreambuf_iterator<_CharT, _Traits>      __istreambuf_iter;
  57.       typedef num_get<_CharT, __istreambuf_iter>        __numget_type;
  58.      
  59.       // Data members:
  60.     private:
  61.       basic_ostream<_CharT, _Traits>*   _M_tie;
  62.       char_type                         _M_fill;
  63.       iostate                           _M_exception;
  64.  
  65.     protected:
  66.       basic_streambuf<_CharT, _Traits>* _M_streambuf;
  67.       iostate                           _M_streambuf_state;
  68.  
  69.       // Cached use_facet<ctype>, which is based on the current locale info.
  70.       const __ctype_type*               _M_ios_fctype;      
  71.       // From ostream.
  72.       const __numput_type*              _M_fnumput;
  73.       // From istream.
  74.       const __numget_type*              _M_fnumget;
  75.  
  76.     public:
  77.       inline const __ctype_type*       
  78.       _M_get_fctype_ios(void)
  79.       { return _M_ios_fctype; }
  80.  
  81.       operator void*() const
  82.       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
  83.  
  84.       inline bool
  85.       operator!() const
  86.       { return this->fail(); }
  87.  
  88.       inline iostate
  89.       rdstate() const
  90.       { return _M_streambuf_state; }
  91.  
  92.       inline void
  93.       clear(iostate __state = goodbit)
  94.       {
  95.         if (this->rdbuf())
  96.           _M_streambuf_state = __state;
  97.         else
  98.           _M_streambuf_state = __state | badbit;
  99.         if ((this->rdstate() & this->exceptions()))
  100.           __throw_ios_failure("basic_ios::clear(iostate) caused exception");
  101.       }
  102.  
  103.       inline void
  104.       setstate(iostate __state)
  105.       { this->clear(this->rdstate() | __state); }
  106.  
  107.       inline bool
  108.       good() const
  109.       { return this->rdstate() == 0; }
  110.  
  111.       inline bool
  112.       eof() const
  113.       { return (this->rdstate() & eofbit) != 0; }
  114.  
  115.       inline bool
  116.       fail() const
  117.       { return (this->rdstate() & (badbit | failbit)) != 0; }
  118.  
  119.       inline bool
  120.       bad() const
  121.       { return (this->rdstate() & badbit) != 0; }
  122.  
  123.       inline iostate
  124.       exceptions() const
  125.       { return _M_exception; }
  126.  
  127.       inline void
  128.       exceptions(iostate __except)
  129.       {
  130.         _M_exception = __except;
  131.         this->clear(_M_streambuf_state);
  132.       }
  133.  
  134.       // Constructor/destructor:
  135.       explicit
  136.       basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base()
  137.       { this->init(__sb); }
  138.  
  139.       virtual
  140.       ~basic_ios() { }
  141.      
  142.       // Members:
  143.       inline basic_ostream<_CharT, _Traits>*
  144.       tie() const      
  145.       { return _M_tie; }
  146.  
  147.       inline basic_ostream<_CharT, _Traits>*
  148.       tie(basic_ostream<_CharT, _Traits>* __tiestr)
  149.       {
  150.         basic_ostream<_CharT, _Traits>* __old = _M_tie;
  151.         _M_tie = __tiestr;
  152.         return __old;
  153.       }
  154.  
  155.       inline basic_streambuf<_CharT, _Traits>*
  156.       rdbuf() const    
  157.       { return _M_streambuf; }
  158.  
  159.       basic_streambuf<_CharT, _Traits>*
  160.       rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
  161.  
  162.       basic_ios&
  163.       copyfmt(const basic_ios& __rhs);
  164.  
  165.       inline char_type
  166.       fill() const
  167.       { return _M_fill; }
  168.  
  169.       inline char_type
  170.       fill(char_type __ch)
  171.       {
  172.         char_type __old = _M_fill;
  173.         _M_fill = __ch;
  174.         return __old;
  175.       }
  176.  
  177.       // Locales:
  178.       locale
  179.       imbue(const locale& __loc);
  180.  
  181.       char
  182.       narrow(char_type __c, char __dfault) const;
  183.  
  184.       char_type
  185.       widen(char __c) const;
  186.      
  187.     protected:
  188.       // 27.4.5.1  basic_ios constructors
  189.       basic_ios() : ios_base()
  190.       { }
  191.  
  192.       void
  193.       init(basic_streambuf<_CharT, _Traits>* __sb);
  194.  
  195.       bool
  196.       _M_check_facet(const locale::facet* __f)
  197.       {
  198.         bool __ret = false;
  199.         if (__f)
  200.           __ret = true;
  201.         else
  202.           __throw_bad_cast();
  203.         return __ret;
  204.       }
  205.  
  206.       void
  207.       _M_cache_facets(const locale& __loc);
  208.     };
  209. } // namespace std
  210.  
  211. #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
  212. # define export
  213. #include <bits/basic_ios.tcc>
  214. #endif
  215.  
  216. #endif /* _CPP_BITS_BASICIOS_H */
  217.  
  218.  
  219.