// -*- C++ -*-
#ifndef __RWSTD_IOTRAITS
#define __RWSTD_IOTRAITS
/***************************************************************************
 *
 * iotraits - Declarations for traits 
 *
 ***************************************************************************
 *    
 *  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 iotraits -- define __USE_STD_IOSTREAM to override default - see section 7.1.2 of the C++ Using Guide"
#else

#include <iosfwd>

#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

  /*
   * Class mbstate_t
   */

#ifdef _RWSTD_NO_MBSTATE_T
  struct _RWSTDExport mbstate_t
  { 
    mbstate_t( long state=0 ) 
      : _RWmbstate(state) { ; }

    mbstate_t(const mbstate_t& state) 
      : _RWmbstate(state._RWmbstate) { ; }
              
    mbstate_t& operator=(const mbstate_t& state)
    {
      if ( &state != this )
        _RWmbstate= state._RWmbstate;              
      return *this;
    }

    mbstate_t& operator=(const long state)
    {
      _RWmbstate= state;              
      return *this;
    } 

    bool operator==(const mbstate_t& state) const
    {
      return ( _RWmbstate == state._RWmbstate );
    }

    bool operator!=(const mbstate_t& state) const
    {
      return ( !(_RWmbstate == state._RWmbstate) );
    }
                   
    long _RWmbstate;                
  };          

#endif // _RWSTD_NO_MBSTATE_T 

  /*
   * Class fpos
   */

  /* It maintains all the information necessary to restore an arbitrary
   * sequence, controlled by the Standard C++ library, to a previous stream
   * position and conversion state.
   */

  template <class stateT>
  class _RWSTDExportTemplate fpos
  {
  public:
    //
    // Types:
    //
    typedef stateT  state_type;
      
    inline fpos(long off = 0);
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
    inline fpos(long, long, state_type);
#else
    inline fpos(long, fpos_t, state_type);
#endif

#ifdef _RWSTD_NO_MBSTATE_T
    inline _EXPLICIT fpos(state_type);
#endif
    inline bool good();
    inline operator long() const;

    inline fpos(const fpos<stateT>&);
    inline fpos<stateT>& operator= (const fpos<stateT>&);

    inline long         offset() const;
    inline long         offset (long);

    inline state_type   state () const;

#if defined(__DECCXX) && !defined(__DECFIXCXXL1608) 
    inline void state (state_type);
#else
    inline state_type   state (state_type);
#endif


#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
    inline long           pos(long);
    inline long           pos() const; 
#else
    inline fpos_t         pos(fpos_t);
    inline fpos_t         pos() const; 
#endif
                            
    inline fpos<stateT>& operator+=(const fpos<stateT> &off);
    inline fpos<stateT>  operator+(const fpos<stateT> &off) const;

    inline fpos<stateT>& operator-=(const fpos<stateT> &off);
    inline fpos<stateT>  operator-(const fpos<stateT> &off) const;

    inline fpos<stateT>& operator+=(int off);
    inline fpos<stateT>  operator+(int off) const;

    inline fpos<stateT>& operator-=(int off);
    inline fpos<stateT>  operator-(int off) const;

    inline fpos<stateT>& operator+=(long off);
    inline fpos<stateT>  operator+(long off) const;

    inline fpos<stateT>& operator-=(long off);
    inline fpos<stateT>  operator-(long off) const;

    inline bool operator==(const fpos<stateT>& rhs) const;
    inline bool operator!=(const fpos<stateT>& rhs) const;

    inline bool operator< (const fpos<stateT>& rhs) const;
    inline bool operator> (const fpos<stateT>& rhs) const;

    inline bool operator<= (const fpos<stateT>& rhs) const;
    inline bool operator>= (const fpos<stateT>& rhs) const;

    inline bool operator==(const int& rhs) const;
    inline bool operator!=(const int& rhs) const;

    inline bool operator< (const int& rhs) const;
    inline bool operator> (const int& rhs) const;

    inline bool operator<= (const int& rhs) const;
    inline bool operator>= (const int& rhs) const;

    inline bool operator==(const long& rhs) const;
    inline bool operator!=(const long& rhs) const;

    inline bool operator< (const long& rhs) const;
    inline bool operator> (const long& rhs) const;

    inline bool operator<= (const long& rhs) const;
    inline bool operator>= (const long& rhs) const;
                      
  private:

    long               _RWpos;     // signed displacement
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
    long               _RWfp ;     // absolute position
#else
    fpos_t             _RWfp ;     // absolute position
#endif
    state_type         _RWstate;   // conversion state
    bool               _RWstatus;  // status
  };


  /*
   *     Class fpos member functions
   */

  /*
   * fpos(long)
   */

  template <class stateT>
  inline
  fpos<stateT>::fpos(long off)
  : _RWpos(off)
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
  , _RWfp(long(0))
#else
  , _RWfp(fpos_t(0))
#endif
  , _RWstate(stateT()) 
  , _RWstatus(true)
  {
    if ( off == -1 ) _RWstatus = false;
  }

  /*
   * fpos(stateT)
   */

#ifdef _RWSTD_NO_MBSTATE_T
  template <class stateT>
  inline
  fpos<stateT>::fpos(stateT state)
  : _RWpos(0)
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
  , _RWfp(long(0))
#else
  , _RWfp(fpos_t(0))
#endif
  , _RWstate(state)
  , _RWstatus(true)
  {;}
#endif // _RWSTD_NO_MBSTATE_T 

  /*
   * fpos(long,fpos_t,state_type)
   */

  template <class stateT>
  inline
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
  fpos<stateT>::fpos(long off,long fposit,state_type state)
#else
  fpos<stateT>::fpos(long off,fpos_t fposit,state_type state)
#endif
  : _RWpos(off)
  , _RWfp(fposit)
  , _RWstate(state)
  , _RWstatus(true)
  { ; }
 
  /*
   * fpos(const fpos&)
   */

  template <class stateT> 
  inline
  fpos<stateT>::fpos(const fpos<stateT>& str_pos)
  {
    _RWpos   = str_pos._RWpos;
    _RWfp    = str_pos._RWfp;
    _RWstate = str_pos._RWstate;
    _RWstatus = str_pos._RWstatus;      
  }

  /*
   * int offset(long)
   */

  template <class stateT>
  inline long 
  fpos<stateT>::offset(long off)
  {
    long var=_RWpos;
    _RWpos = off; 
    return var;
  }

  /*
   * long pos(long)
   */

  template <class stateT>
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
  inline long 
  fpos<stateT>::pos(long posi)
#else
  inline fpos_t
  fpos<stateT>::pos(fpos_t posi)
#endif
  {
    long var=_RWfp;
    _RWfp = posi;
    return var;
  }

  /*
   * state_type state(state_type)
   */

  template <class stateT>
#if defined(__DECCXX) && !defined(__DECFIXCXXL1608) 
  inline void
#else
  inline _TYPENAME fpos<stateT>::state_type 
#endif
  fpos<stateT>::state(state_type state)
  {
#if defined(__DECCXX) && !defined(__DECFIXCXXL1608) 
#else
    state_type var=_RWstate; 
#endif
    _RWstate = state;
#if defined(__DECCXX) && !defined(__DECFIXCXXL1608) 
#else
    return var;
#endif
  }

  /*
   *  bool good ( )
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::good() 
  {
    return _RWstatus;
  }

  /*
   * operator long ( )
   */
 
  template <class stateT>
  inline fpos<stateT>::operator long() const
  {
    return (long)( _RWfp + _RWpos );
  }

  /*
   * fpos& operator=(const fpos&)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator=(const fpos<stateT>& str_pos)
  {
    if ( &str_pos != this )
    {
      _RWpos    = str_pos._RWpos;
      _RWfp     = str_pos._RWfp;
      _RWstate  = str_pos._RWstate;
      _RWstatus = str_pos._RWstatus;
    }
    return *this;
  }

  /*
   * long pos() const
   */

  template <class stateT>
#if defined(__DECCXX) && !defined(__DECFIXCXXL997) && (defined(__VMS)||defined(__linux__))
  inline long 
#else
  inline fpos_t
#endif
  fpos<stateT>::pos() const
  {
    return _RWfp;
  }

  /*
   * long offset() const
   */

  template <class stateT>
  inline long 
  fpos<stateT>::offset() const
  {
    return _RWpos;
  }

  /*
   * state_type state() const
   */

  template <class stateT>
  inline _TYPENAME fpos<stateT>::state_type 
  fpos<stateT>::state() const
  {
    return _RWstate;
  }
 
  /*
   * fpos& operator+=(const fpos&)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator+=(const fpos<stateT>& off)
  {
    _RWpos += off._RWpos + off._RWfp;
    return *this;
  }

  /*
   * fpos operator+(const fpos&) const
   */

  template <class stateT>
  inline fpos<stateT> 
  fpos<stateT>::operator+(const fpos<stateT>& off) const
  {
    fpos<stateT> temp(*this);
    temp._RWpos += off._RWpos + off._RWfp; 
    return temp;
  }

  /*
   * fpos operator-(const fpos<stateT>& off) const
   */

  template <class stateT>
  inline fpos<stateT> 
  fpos<stateT>::operator-(const fpos<stateT>& off) const
  {
    fpos<stateT> temp(*this);
    temp._RWpos -= (off._RWpos + off._RWfp); 
    return temp;
  }

  /*
   * fpos& operator-=(const fpos&)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator-=(const fpos<stateT>& off)
  {
    _RWpos -= (off._RWpos + off._RWfp);
    return *this;
  }

  /*
   * fpos& operator+=(int)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator+=(int off)
  {
    _RWpos += off;
    return *this;
  }

  /*
   * fpos operator+(int) const
   */

  template <class stateT>
  inline fpos<stateT> 
  fpos<stateT>::operator+(int off) const
  {
    fpos<stateT> temp(*this);
    temp._RWpos += off; 
    return temp;
  }

  /*
   * fpos operator-(int off) const
   */

  template <class stateT>
  inline fpos<stateT> 
  fpos<stateT>::operator-(int off) const
  {
    fpos<stateT> temp(*this);
    temp._RWpos -= off; 
    return temp;
  }

  /*
   * fpos& operator-=(int)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator-=(int off)
  {
    _RWpos -= off;
    return *this;
  }

  /*
   * fpos& operator-=(long)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator-=(long off)
  {
    _RWpos -= off;
    return *this;
  }

  /*
   * fpos operator-(long off) const
   */

  template <class stateT>
  inline fpos<stateT> 
  fpos<stateT>::operator-(long off) const
  {
    fpos<stateT> temp(*this);
    temp._RWpos -= off; 
    return temp;
  }

  /*
   * fpos& operator+=(long)
   */

  template <class stateT>
  inline fpos<stateT>& 
  fpos<stateT>::operator+=(long off)
  {
    _RWpos += off;
    return *this;
  }

  /*
   * fpos operator+(long) const
   */

  template <class stateT>
  inline fpos<stateT> 
  fpos<stateT>::operator+(long off) const
  {
    fpos<stateT> temp(*this);
    temp._RWpos += off; 
    return temp;
  }
 
  /*
   * bool operator==(const fpos&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator==(const fpos<stateT>& pos) const
  { 
    if ( !(_RWstatus || pos._RWstatus) ) return true;
    return ( ( (_RWpos+_RWfp) == (pos._RWpos+pos._RWfp) ) 
#ifndef _RWSTD_NO_MBSTATE_COMPARE
             && ( _RWstate == pos._RWstate )
#endif 
             &&  ( _RWstatus == pos._RWstatus ) );
  }

  /*
   * bool operator!=(const fpos&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator!=(const fpos<stateT>& pos) const
  {
    return !(*this == pos);
  }

  /*
   * bool operator< (const fpos&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator< (const fpos<stateT>& pos) const
  {
    return ( (_RWpos+_RWfp) < (pos._RWpos + pos._RWfp) );
  }

  /*
   * bool operator> (const fpos&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator> (const fpos<stateT>& pos) const
  {
    return ( (_RWpos+_RWfp) > (pos._RWpos + pos._RWfp) );
  }

  /*
   * bool operator<= (const fpos&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator<= (const fpos<stateT>& pos) const
  {
    return ( (_RWpos+_RWfp) <= (pos._RWpos + pos._RWfp) );
  }

  /*
   * bool operator>= (const fpos&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator>= (const fpos<stateT>& pos) const
  {
    return ( (_RWpos+_RWfp) >= (pos._RWpos + pos._RWfp) );
  }

  /*
   * bool operator==(const int&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator==(const int& pos) const
  { 
    return (  (_RWpos+_RWfp) == pos );
  }

  /*
   * bool operator!=(const int&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator!=(const int& pos) const
  {
    return !(*this == pos);
  }

  /*
   * bool operator< (const int&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator< (const int& pos) const
  {
    return ( (_RWpos+_RWfp) < pos );
  }

  /*
   * bool operator> (const int&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator> (const int& pos) const
  { 
    return ( (_RWpos+_RWfp) > pos );
  }

  /*
   * bool operator<= (const int&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator<= (const int& pos) const
  { 
    return ( (_RWpos+_RWfp) <= pos );
  }

  /*
   * bool operator>= (const int&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator>= (const int& pos) const
  {
    return ( (_RWpos+_RWfp) >= pos );
  }

  /*
   * bool operator==(const long&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator==(const long& pos) const
  { 
    return (  (_RWpos+_RWfp) == pos );
  }

  /*
   * bool operator!=(const long&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator!=(const long& pos) const
  {
    return !(*this == pos);
  }

  /*
   * bool operator< (const long&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator< (const long& pos) const
  {
    return ( (_RWpos+_RWfp) < pos );
  }

  /*
   * bool operator> (const long&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator> (const long& pos) const
  { 
    return ( (_RWpos+_RWfp) > pos );
  }

  /*
   * bool operator<= (const long&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator<= (const long& pos) const
  { 
    return ( (_RWpos+_RWfp) >= pos );
  }

  /*
   * bool operator>= (const long&) const
   */

  template <class stateT>
  inline bool 
  fpos<stateT>::operator>= (const long& pos) const
  {
    return ( (_RWpos+_RWfp) <= pos );
  }

#ifndef _RWSTD_NO_NAMESPACE
}
#endif

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

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

#endif // __USE_STD_IOSTREAM

#endif // __RWSTD_IOTRAITS
