#ifndef __STD_SSTREAM__
#define __STD_SSTREAM__
//
//
//  Copyright Digital Equipment Corporation 1996. All rights reserved.
//
//  Restricted Rights: Use, duplication, or disclosure by the U.S.
//  Government is subject to restrictions as set forth in subparagraph
//  (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR
//  52.227-14 Alt. III, as applicable.
//
//  This software is proprietary to and embodies the confidential
//  technology of Digital Equipment Corporation. Possession, use, or
//  copying of this software and media is authorized only pursuant to a
//  valid written license from Digital or an authorized sublicensor.
//
//

/***************************************************************************
 *
 * sstream - Declarations for the Standard Library basic streams
 *
 * $Id: sstream,v 1.42 1996/09/24 19:18:19 smithey Exp $
 *
 ***************************************************************************
 *
 * (c) Copyright 1994-1996 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"
#else

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

#if defined(__DECCXX)
#   ifdef __PRAGMA_ENVIRONMENT
#      pragma __environment __save
#      pragma __environment __header_defaults
#   endif
#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:
    typedef basic_ios<charT, traits>                 ios_type;
    typedef basic_string<charT, traits, Allocator >  string_type;

    typedef traits                              traits_type;
    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;


    _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                   *data_;
    streamsize              length_;
    streamsize              end_pos;
    
};


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

  public:

    typedef basic_stringbuf<charT, traits, Allocator>      sb_type;
    typedef basic_ios<charT, traits>                       ios_type;
    typedef basic_string<charT, traits, Allocator >        string_type;

    typedef traits                                         traits_type;
    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;

    _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>    sb_;

};


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

 public:

    typedef basic_stringbuf<charT, traits, Allocator>        sb_type;
    typedef basic_ios<charT, traits>                         ios_type;
    typedef basic_string<charT, traits, Allocator>           string_type;

    typedef traits                                           traits_type;
    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;

    _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            sb_;

};


/*
 *
 *  Class stringstream
 *
 */

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

  public:

    typedef basic_stringbuf<charT, traits, Allocator>        sb_type;
    typedef basic_ios<charT, traits>                         ios_type;
    typedef basic_string<charT, traits, Allocator>           string_type;

    typedef traits                                           traits_type;
    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;

    _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            sb_;

};


#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
typedef basic_stringbuf<char>                            stringbuf;
#else
typedef basic_stringbuf<char, char_traits<char>, allocator<void> > stringbuf;
#endif
#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<void> > wstringbuf;
#endif
#endif

#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
typedef basic_istringstream<char>                        istringstream;
#else
typedef basic_istringstream<char, char_traits<char>, allocator<void> > 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<void> > wistringstream;
#endif
#endif


#ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
typedef basic_ostringstream<char>                        ostringstream;
#else
typedef basic_ostringstream<char, char_traits<char>, allocator<void> >    ostringstream;
#endif
#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<void> > wostringstream;
#endif
#endif

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

#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<void> >  wstringstream;
#endif
#endif


#ifndef _RWSTD_NO_NAMESPACE
}
#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 /* __SSTREAM__ */
