Subversion Repositories Kolibri OS

Rev

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

  1. // basic_ios locale and locale-related member functions -*- C++ -*-
  2.  
  3. // Copyright (C) 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_TCC
  31. #define _CPP_BITS_BASICIOS_TCC 1
  32.  
  33. namespace std
  34. {
  35.   template<typename _CharT, typename _Traits>
  36.     basic_streambuf<_CharT, _Traits>*
  37.     basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
  38.     {
  39.       basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
  40.       _M_streambuf = __sb;
  41.       this->clear();
  42.       return __old;
  43.     }
  44.  
  45.   template<typename _CharT, typename _Traits>
  46.     basic_ios<_CharT, _Traits>&
  47.     basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
  48.     {
  49.       // Per 27.1.1.1, do not call imbue, yet must trash all caches
  50.       // associated with imbue()
  51.  
  52.       // Alloc any new word array first, so if it fails we have "rollback".
  53.       _Words* __words = (__rhs._M_word_limit <= _S_local_words) ?
  54.         _M_word_array : new _Words[__rhs._M_word_limit];
  55.  
  56.       // XXX This is the only reason _Callback_list was defined
  57.       // inline. The suspicion is that this increased compilation
  58.       // times dramatically for functions that use this member
  59.       // function (inserters_extractors, ios_manip_fmtflags). FIX ME,
  60.       // clean this stuff up. Callbacks are broken right now, anyway.
  61.  
  62.       // Bump refs before doing callbacks, for safety.
  63.       _Callback_list* __cb = __rhs._M_callbacks;
  64.       if (__cb)
  65.         __cb->_M_add_reference();
  66.       _M_call_callbacks(erase_event);
  67.       if (_M_words != _M_word_array)
  68.         delete [] _M_words;
  69.       _M_dispose_callbacks();
  70.  
  71.       _M_callbacks = __cb;  // NB: Don't want any added during above.
  72.       for (int __i = 0; __i < __rhs._M_word_limit; ++__i)
  73.         __words[__i] = __rhs._M_words[__i];
  74.       if (_M_words != _M_word_array)
  75.         delete [] _M_words;
  76.       _M_words = __words;
  77.       _M_word_limit = __rhs._M_word_limit;
  78.  
  79.       this->flags(__rhs.flags());
  80.       this->width(__rhs.width());
  81.       this->precision(__rhs.precision());
  82.       this->tie(__rhs.tie());
  83.       this->fill(__rhs.fill());
  84.       // The next is required to be the last assignment.
  85.       this->exceptions(__rhs.exceptions());
  86.      
  87.       _M_call_callbacks(copyfmt_event);
  88.       return *this;
  89.     }
  90.  
  91.   template<typename _CharT, typename _Traits>
  92.     char
  93.     basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
  94.     { return _M_ios_fctype->narrow(__c, __dfault); }
  95.  
  96.   template<typename _CharT, typename _Traits>
  97.     _CharT
  98.     basic_ios<_CharT, _Traits>::widen(char __c) const
  99.     { return _M_ios_fctype->widen(__c); }
  100.  
  101.   // Locales:
  102.   template<typename _CharT, typename _Traits>
  103.     locale
  104.     basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
  105.     {
  106.       locale __old(this->getloc());
  107.       ios_base::imbue(__loc);
  108.       _M_cache_facets(__loc);
  109.       if (this->rdbuf() != 0)
  110.         this->rdbuf()->pubimbue(__loc);
  111.       return __old;
  112.     }
  113.  
  114.   template<typename _CharT, typename _Traits>
  115.     void
  116.     basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
  117.     {
  118.       // NB: This may be called more than once on the same object.
  119.       ios_base::_M_init();
  120.       _M_cache_facets(_M_ios_locale);
  121.       _M_tie = 0;
  122.       _M_fill = this->widen(' ');
  123.       _M_exception = goodbit;
  124.       _M_streambuf = __sb;
  125.       _M_streambuf_state = __sb ? goodbit : badbit;
  126.     }
  127.  
  128.   template<typename _CharT, typename _Traits>
  129.     void
  130.     basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc)
  131.     {
  132.       if (has_facet<__ctype_type>(__loc))
  133.         _M_ios_fctype = &use_facet<__ctype_type>(__loc);
  134.       // Should be filled in by ostream and istream, respectively.
  135.       if (has_facet<__numput_type>(__loc))
  136.         _M_fnumput = &use_facet<__numput_type>(__loc);
  137.       if (has_facet<__numget_type>(__loc))
  138.         _M_fnumget = &use_facet<__numget_type>(__loc);
  139.     }
  140. } // namespace std
  141.  
  142. #endif // _CPP_BITS_BASICIOS_TCC
  143.  
  144.  
  145.  
  146.