ossrv_pub/io_stream_api/inc/stdapis/stlport/stl/_sstream.h
changeset 0 e4d67989cc36
child 22 ddc455616bd6
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
       
     3  * Copyright (c) 1999
       
     4  * Silicon Graphics Computer Systems, Inc.
       
     5  *
       
     6  * Copyright (c) 1999 
       
     7  * Boris Fomitchev
       
     8  *
       
     9  * This material is provided "as is", with absolutely no warranty expressed
       
    10  * or implied. Any use is at your own risk.
       
    11  *
       
    12  * Permission to use or copy this software for any purpose is hereby granted 
       
    13  * without fee, provided the above notices are retained on all copies.
       
    14  * Permission to modify the code and to distribute modified code is granted,
       
    15  * provided the above notices are retained, and a notice that the code was
       
    16  * modified is included with the above copyright notice.
       
    17  *
       
    18  */ 
       
    19 
       
    20 
       
    21 // This header defines classes basic_stringbuf, basic_istringstream,
       
    22 // basic_ostringstream, and basic_stringstream.  These classes 
       
    23 // represent streamsbufs and streams whose sources or destinations are
       
    24 // C++ strings.
       
    25 
       
    26 #ifndef _STLP_SSTREAM_H
       
    27 #define _STLP_SSTREAM_H
       
    28 
       
    29 #ifndef _STLP_INTERNAL_STREAMBUF
       
    30 # include <stl/_streambuf.h>
       
    31 #endif
       
    32 
       
    33 #ifndef _STLP_INTERNAL_ISTREAM_H
       
    34 # include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
       
    35 #endif
       
    36 
       
    37 #ifndef _STLP_STRING_H
       
    38 # include <stl/_string.h>
       
    39 #endif
       
    40 
       
    41 _STLP_BEGIN_NAMESPACE
       
    42 
       
    43 //----------------------------------------------------------------------
       
    44 // This version of basic_stringbuf relies on the internal details of
       
    45 // basic_string.  It relies on the fact that, in this implementation,
       
    46 // basic_string's iterators are pointers.  It also assumes (as allowed
       
    47 // by the standard) that _CharT is a POD type.
       
    48 
       
    49 // We have a very small buffer for the put area, just so that we don't
       
    50 // have to use append() for every sputc.  Conceptually, the buffer
       
    51 // immediately follows the end of the underlying string.  We use this
       
    52 // buffer when appending to write-only streambufs, but we don't use it
       
    53 // for read-write streambufs.
       
    54 
       
    55 template <class _CharT, class _Traits, class _Alloc>
       
    56 #ifdef __SYMBIAN32__
       
    57 NONSHARABLE_CLASS ( basic_stringbuf ) : public basic_streambuf<_CharT, _Traits>
       
    58 #else
       
    59 class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
       
    60 #endif
       
    61 {
       
    62 public:                         // Typedefs.
       
    63   typedef _CharT                     char_type;
       
    64   typedef typename _Traits::int_type int_type;
       
    65   typedef typename _Traits::pos_type pos_type;
       
    66   typedef typename _Traits::off_type off_type;
       
    67   typedef _Traits                    traits_type;
       
    68 
       
    69   typedef basic_streambuf<_CharT, _Traits>          _Base;
       
    70   typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Self;
       
    71   typedef basic_string<_CharT, _Traits, _Alloc>     _String;
       
    72 
       
    73 public:                         // Constructors, destructor.
       
    74   _STLP_DECLSPEC explicit basic_stringbuf(ios_base::openmode __mode
       
    75                                       = ios_base::in | ios_base::out);
       
    76   _STLP_DECLSPEC explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
       
    77                                       = ios_base::in | ios_base::out);
       
    78   _STLP_DECLSPEC virtual ~basic_stringbuf();
       
    79 
       
    80 public:                         // Get or set the string.
       
    81   _String str() const { 
       
    82       if ( _M_mode & ios_base::out )
       
    83            _M_append_buffer();
       
    84       return _M_str; 
       
    85    }
       
    86   _STLP_DECLSPEC void str(const _String& __s);
       
    87 
       
    88 protected:                      // Overridden virtual member functions.
       
    89   virtual int_type underflow();
       
    90   virtual int_type uflow();
       
    91   virtual int_type pbackfail(int_type __c);
       
    92   virtual int_type overflow(int_type __c);
       
    93   int_type pbackfail() {return pbackfail(_Traits::eof());}
       
    94   int_type overflow() {return overflow(_Traits::eof());}
       
    95 
       
    96   virtual streamsize xsputn(const char_type* __s, streamsize __n);
       
    97   virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
       
    98 
       
    99   virtual _Base* setbuf(_CharT* __buf, streamsize __n);
       
   100   virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
       
   101                            ios_base::openmode __mode 
       
   102                                       = ios_base::in | ios_base::out);
       
   103   virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
       
   104                                       = ios_base::in | ios_base::out);
       
   105   ios_base::openmode _M_mode;
       
   106 
       
   107 private:                        // Helper functions.
       
   108   // Append the internal buffer to the string if necessary.
       
   109   void _M_append_buffer() const;
       
   110   void _M_set_ptrs();
       
   111 
       
   112 private:
       
   113   mutable basic_string<_CharT, _Traits, _Alloc> _M_str;
       
   114 
       
   115   enum _JustName { _S_BufSiz = 8 };
       
   116   _CharT _M_Buf[ 8 /* _S_BufSiz */];
       
   117 };
       
   118 
       
   119 # if defined (_STLP_USE_TEMPLATE_EXPORT)
       
   120 _STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >;
       
   121 #  if !defined (_STLP_NO_WCHAR_T)
       
   122 _STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
       
   123 #  endif
       
   124 # endif /* _STLP_USE_TEMPLATE_EXPORT */
       
   125 
       
   126 //----------------------------------------------------------------------
       
   127 // Class basic_istringstream, an input stream that uses a stringbuf.
       
   128 
       
   129 template <class _CharT, class _Traits, class _Alloc>
       
   130 #ifdef __SYMBIAN32__
       
   131 NONSHARABLE_CLASS ( basic_istringstream ) : public basic_istream<_CharT, _Traits>
       
   132 #else
       
   133 class basic_istringstream : public basic_istream<_CharT, _Traits>
       
   134 #endif
       
   135 {
       
   136 public:                         // Typedefs
       
   137   typedef typename _Traits::char_type   char_type;
       
   138   typedef typename _Traits::int_type    int_type;
       
   139   typedef typename _Traits::pos_type    pos_type;
       
   140   typedef typename _Traits::off_type    off_type;
       
   141   typedef _Traits traits_type;
       
   142 
       
   143   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
       
   144   typedef basic_istream<_CharT, _Traits>            _Base;
       
   145   typedef basic_string<_CharT, _Traits, _Alloc>     _String;
       
   146   typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Buf;
       
   147 
       
   148 public:                         // Constructors, destructor.
       
   149   basic_istringstream(ios_base::openmode __mode = ios_base::in);
       
   150   basic_istringstream(const _String& __str,
       
   151                       ios_base::openmode __mode = ios_base::in);
       
   152   ~basic_istringstream();
       
   153 
       
   154 public:                         // Member functions
       
   155 
       
   156   basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
       
   157     { return __CONST_CAST(_Buf*,&_M_buf); }
       
   158 
       
   159   _String str() const { return _M_buf.str(); }
       
   160   void str(const _String& __s) { _M_buf.str(__s); }
       
   161   
       
   162 private:
       
   163   basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
       
   164 };
       
   165 
       
   166 
       
   167 //----------------------------------------------------------------------
       
   168 // Class basic_ostringstream, an output stream that uses a stringbuf.
       
   169 
       
   170 template <class _CharT, class _Traits, class _Alloc>
       
   171 #ifdef __SYMBIAN32__
       
   172 NONSHARABLE_CLASS ( basic_ostringstream ) : public basic_ostream<_CharT, _Traits>
       
   173 #else
       
   174 class basic_ostringstream : public basic_ostream<_CharT, _Traits>
       
   175 #endif
       
   176 {
       
   177 public:                         // Typedefs
       
   178   typedef typename _Traits::char_type   char_type;
       
   179   typedef typename _Traits::int_type    int_type;
       
   180   typedef typename _Traits::pos_type    pos_type;
       
   181   typedef typename _Traits::off_type    off_type;
       
   182   typedef _Traits traits_type;
       
   183 
       
   184   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
       
   185   typedef basic_ostream<_CharT, _Traits>            _Base;
       
   186   typedef basic_string<_CharT, _Traits, _Alloc>     _String;
       
   187   typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Buf;
       
   188 
       
   189 public:                         // Constructors, destructor.
       
   190   basic_ostringstream(ios_base::openmode __mode = ios_base::out);
       
   191   basic_ostringstream(const _String& __str,
       
   192                       ios_base::openmode __mode = ios_base::out);
       
   193   ~basic_ostringstream();
       
   194 
       
   195 public:                         // Member functions.
       
   196 
       
   197   basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
       
   198     { return __CONST_CAST(_Buf*,&_M_buf); }
       
   199 
       
   200   _String str() const { return _M_buf.str(); }
       
   201     void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE
       
   202 
       
   203 
       
   204 private:
       
   205   basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
       
   206 };
       
   207 
       
   208 
       
   209 //----------------------------------------------------------------------
       
   210 // Class basic_stringstream, a bidirectional stream that uses a stringbuf.
       
   211 
       
   212 template <class _CharT, class _Traits, class _Alloc>
       
   213 #ifdef __SYMBIAN32__
       
   214 NONSHARABLE_CLASS ( basic_stringstream ) : public basic_iostream<_CharT, _Traits>
       
   215 #else
       
   216 class basic_stringstream : public basic_iostream<_CharT, _Traits>
       
   217 #endif
       
   218 {
       
   219 public:                         // Typedefs
       
   220   typedef typename _Traits::char_type char_type;
       
   221   typedef typename _Traits::int_type  int_type;
       
   222   typedef typename _Traits::pos_type  pos_type;
       
   223   typedef typename _Traits::off_type  off_type;
       
   224   typedef _Traits  traits_type;
       
   225 
       
   226   typedef basic_ios<_CharT, _Traits>                 _Basic_ios;
       
   227   typedef basic_iostream<_CharT, _Traits>            _Base;
       
   228   typedef basic_string<_CharT, _Traits, _Alloc>      _String;
       
   229   typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Buf;
       
   230   
       
   231   typedef ios_base::openmode openmode;
       
   232 
       
   233 public:                         // Constructors, destructor.
       
   234   _STLP_DECLSPEC basic_stringstream(openmode __mod = ios_base::in | ios_base::out);
       
   235   _STLP_DECLSPEC basic_stringstream(const _String& __str,
       
   236                      openmode __mod = ios_base::in | ios_base::out);
       
   237   ~basic_stringstream();
       
   238 
       
   239 public:                         // Member functions.
       
   240 
       
   241   basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
       
   242     { return __CONST_CAST(_Buf*,&_M_buf); }
       
   243 
       
   244   _String str() const { return _M_buf.str(); }
       
   245     void str(const _String& __s) { _M_buf.str(__s); }
       
   246 
       
   247 private:
       
   248   basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
       
   249 };
       
   250 
       
   251 
       
   252 # if defined (_STLP_USE_TEMPLATE_EXPORT)
       
   253 _STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >;
       
   254 _STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >;
       
   255 _STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >;
       
   256 #  if !defined (_STLP_NO_WCHAR_T)
       
   257 _STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
       
   258 _STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
       
   259 _STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
       
   260 #  endif
       
   261 # endif /* _STLP_USE_TEMPLATE_EXPORT */
       
   262 
       
   263 _STLP_END_NAMESPACE
       
   264 
       
   265 # if  defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
       
   266 #  include <stl/_sstream.c>
       
   267 # endif
       
   268 
       
   269 #endif /* _STLP_SSTREAM_H */
       
   270 
       
   271 // Local Variables:
       
   272 // mode:C++
       
   273 // End: