// -*- C++ -*-
#ifndef __STD_SSTREAM__
#define __STD_SSTREAM__

/***************************************************************************
 *
 * sstream - Declarations for the Standard Library basic streams
 *
 ***************************************************************************
 *    
 *  Copyright 2000 Compaq Computer Corporation
 *
 *  COMPAQ Registered in U.S. Patent and Trademark Office.
 *
 *  Confidential computer software. Valid license from Compaq required for
 *  possession, use or copying. Consistent with FAR 12.211 and 12.212,
 *  Commercial Computer Software, Computer Software Documentation, and
 *  Technical Data for Commercial Items are licensed to the U.S. Government
 *  under vendor's standard commercial license.
 *
 ****************************************************************************
 *
 * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
 * ALL RIGHTS RESERVED
 *
 * The software and information contained herein are proprietary to, and
 * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
 * intends to preserve as trade secrets such software and information.
 * This software is furnished pursuant to a written license agreement and
 * may be used, copied, transmitted, and stored only in accordance with
 * the terms of such license and with the inclusion of the above copyright
 * notice.  This software and information or any other copies thereof may
 * not be provided or otherwise made available to any other person.
 *
 * Notwithstanding any other lease or license that may pertain to, or
 * accompany the delivery of, this computer software and information, the
 * rights of the Government regarding its use, reproduction and disclosure
 * are as set forth in Section 52.227-19 of the FARS Computer
 * Software-Restricted Rights clause.
 * 
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
 * Technical Data and Computer Software clause at DFARS 252.227-7013.
 * Contractor/Manufacturer is Rogue Wave Software, Inc.,
 * P.O. Box 2328, Corvallis, Oregon 97339.
 *
 * This computer software and information is distributed with "restricted
 * rights."  Use, duplication or disclosure is subject to restrictions as
 * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
 * Computer Software-Restricted Rights (April 1985)."  If the Clause at
 * 18-52.227-74 "Rights in Data General" is specified in the contract,
 * then the "Alternate III" clause applies.
 *
 **************************************************************************/

#include <compnent.hxx>
#ifndef __USE_STD_IOSTREAM
#error "cannot include sstream -- define __USE_STD_IOSTREAM to override default - see section 7.1.2 of the C++ Using Guide"
#else

#include <streambuf>
#include <istream>
#include <ostream>

#if defined(__DECCXX)
#   ifdef __PRAGMA_ENVIRONMENT
#      pragma __environment __save
#      pragma __environment __cxx_header_defaults
#   endif
#endif

#if defined(__VMS) && defined(__DECCXX) && !defined(__DECFIXCXXL1158)
#pragma __extern_prefix __save
#pragma __extern_prefix "CXXL$" 
#endif


#ifndef _RWSTD_NO_NAMESPACE
namespace std{
#endif
  
  template<class charT, class traits, class Allocator>
  class _RWSTDExportTemplate basic_stringbuf : public basic_streambuf<charT, traits>
  {

  public:
    //
    // Types:
    //
    typedef charT                                    char_type;
    typedef _TYPENAME traits::int_type               int_type;
    typedef _TYPENAME traits::pos_type               pos_type;
    typedef _TYPENAME traits::off_type               off_type;
    typedef traits                                   traits_type;
  
    typedef basic_ios<charT, traits>                 ios_type;
    typedef basic_string<charT, traits, Allocator >  string_type;

    _EXPLICIT basic_stringbuf(ios_base::openmode which = 
                              ios_base::in | ios_base::out );
     
    _EXPLICIT basic_stringbuf(const string_type& str,
                              ios_base::openmode which = 
                              ios_base::in | ios_base::out );
    
    virtual ~basic_stringbuf();
     
    string_type str() const;
    void str(const string_type& str_arg);

  protected:

    virtual int_type overflow(int_type c = traits::eof());
    virtual int_type pbackfail(int_type c = traits::eof());
    virtual int_type underflow();
    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
                             ios_base::openmode which =
                             ios_base::in | ios_base::out);

    virtual pos_type seekpos(pos_type sp,
                             ios_base::openmode which =
                             ios_base::in | ios_base::out);

    virtual basic_streambuf<charT,traits>* setbuf(char_type* s, streamsize n);
    virtual streamsize xsputn(const char_type *s, streamsize n);

  private:
    charT                   *_RWdata;
    streamsize               _RWlength;
    streamsize               _RWend_pos;
  };


  template<class charT, class traits, class Allocator>
  class _RWSTDExportTemplate basic_istringstream : public basic_istream<charT, traits>
  {

  public:
    //
    // Types:
    //
    typedef charT                                           char_type;
    typedef _TYPENAME traits::int_type                      int_type;
    typedef _TYPENAME traits::pos_type                      pos_type;
    typedef _TYPENAME traits::off_type                      off_type;
    typedef traits                                          traits_type;
  
    typedef basic_stringbuf<charT, traits, Allocator>       sb_type;
    typedef basic_ios<charT, traits>                        ios_type;
    typedef basic_string<charT, traits, Allocator >         string_type;

    _EXPLICIT basic_istringstream(ios_base::openmode which = ios_base::in);
    _EXPLICIT basic_istringstream(const string_type& str,
                                  ios_base::openmode which = ios_base::in);

    virtual ~basic_istringstream();

    basic_stringbuf<charT, traits, Allocator> *rdbuf() const;
    string_type str() const;

    void str(const string_type& str);

  protected:

  private:
    basic_stringbuf<charT, traits, Allocator>    _RWsb;
  };


  template<class charT, class traits, class Allocator>
  class _RWSTDExportTemplate basic_ostringstream : public basic_ostream<charT, traits>
  {

  public:
    //
    // Types:
    //
    typedef charT                                             char_type;
    typedef _TYPENAME traits::int_type                        int_type;
    typedef _TYPENAME traits::pos_type                        pos_type;
    typedef _TYPENAME traits::off_type                        off_type;
    typedef traits                                            traits_type;
      
    typedef basic_stringbuf<charT, traits, Allocator>         sb_type;
    typedef basic_ios<charT, traits>                          ios_type;
    typedef basic_string<charT, traits, Allocator>            string_type;

    _EXPLICIT basic_ostringstream(ios_base::openmode which = ios_base::out);
    _EXPLICIT basic_ostringstream(const string_type& str,
                                  ios_base::openmode which = ios_base::out);

    virtual ~basic_ostringstream();
    basic_stringbuf<charT, traits, Allocator> *rdbuf() const;

    string_type str() const;
    void str(const string_type& str);

  protected:

  private:
    sb_type            _RWsb;
  };


  /*
   *  Class stringstream
   */

  template<class charT, class traits, class Allocator>
  class _RWSTDExportTemplate basic_stringstream : public basic_iostream<charT, traits>
  {

  public:
    //
    // Types:
    //
    typedef charT                                             char_type;
    typedef _TYPENAME traits::int_type                        int_type;
    typedef _TYPENAME traits::pos_type                        pos_type;
    typedef _TYPENAME traits::off_type                        off_type;
    typedef traits                                            traits_type;
      
    typedef basic_stringbuf<charT, traits, Allocator>         sb_type;
    typedef basic_ios<charT, traits>                          ios_type;
    typedef basic_string<charT, traits, Allocator>            string_type;


    _EXPLICIT basic_stringstream(ios_base::openmode which = ios_base::out | 
                                 ios_base::in);

    _EXPLICIT basic_stringstream(const string_type& str,
                                 ios_base::openmode which = 
                                 ios_base::out | ios_base::in);

    virtual ~basic_stringstream();
    basic_stringbuf<charT, traits, Allocator> *rdbuf() const;
    string_type str() const;
    void str(const string_type& str);

  protected:

  private:
    sb_type            _RWsb;
  };


#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  typedef basic_stringbuf<char>                                      stringbuf;
#else
  typedef basic_stringbuf<char, char_traits<char>, allocator<char> > stringbuf;
#endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  
#ifndef _RWSTD_NO_WIDE_CHAR
#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  typedef basic_stringbuf<wchar_t>                                            wstringbuf;
#else
  typedef basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstringbuf;
#endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
#endif // _RWSTD_NO_WIDE_CHAR

#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  typedef basic_istringstream<char>                                      istringstream;
#else
  typedef basic_istringstream<char, char_traits<char>, allocator<char> > istringstream;
#endif
  
#ifndef _RWSTD_NO_WIDE_CHAR
#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  typedef basic_istringstream<wchar_t>                                            wistringstream;
#else
  typedef basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wistringstream;
#endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
#endif // _RWSTD_NO_WIDE_CHAR 


#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  typedef basic_ostringstream<char>                                         ostringstream;
#else
  typedef basic_ostringstream<char, char_traits<char>, allocator<char> >    ostringstream;
#endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES 
  
#ifndef _RWSTD_NO_WIDE_CHAR
#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  typedef basic_ostringstream<wchar_t>                                            wostringstream;
#else
  typedef basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wostringstream;
#endif // _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES 
#endif // _RWSTD_NO_WIDE_CHAR

#ifndef _RWSTD_NO_DEFAULT_TEMPLATES
  typedef basic_stringstream<char>                                        stringstream;
#else
  typedef basic_stringstream<char, char_traits<char>, allocator<char> >   stringstream;
#endif // _RWSTD_NO_DEFAULT_TEMPLATES 

#ifndef _RWSTD_NO_WIDE_CHAR
#ifndef _RWSTD_NO_DEFAULT_TEMPLATES
  typedef basic_stringstream<wchar_t>                                             wstringstream;
#else
  typedef basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >  wstringstream;
#endif // _RWSTD_NO_DEFAULT_TEMPLATES
#endif // _RWSTD_NO_WIDE_CHAR


#ifndef _RWSTD_NO_NAMESPACE
}
#endif

#if defined(__VMS) && defined(__DECCXX) && !defined(__DECFIXCXXL1158)
#   pragma __extern_prefix __restore
#endif


#ifdef _RWSTD_COMPILE_INSTANTIATE
#include <sstream.cc>
#endif

#if defined(__DECCXX)
#   ifdef __PRAGMA_ENVIRONMENT
#      pragma __environment __restore
#   endif
#endif

#endif // __USE_STD_IOSTREAM

#endif // __STD_SSTREAM__ 

