home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / Rw / iotraits.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  13.0 KB  |  619 lines

  1. #ifndef __IOTRAITS_H
  2. #define __IOTRAITS_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __RWSTD_IOTRAITS
  6. #define __RWSTD_IOTRAITS
  7. /***************************************************************************
  8.  *
  9.  * iotraits - Declarations for traits 
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  14.  *
  15.  * This computer software is owned by Rogue Wave Software, Inc. and is
  16.  * protected by U.S. copyright laws and other laws and by international
  17.  * treaties.  This computer software is furnished by Rogue Wave Software,
  18.  * Inc. pursuant to a written license agreement and may be used, copied,
  19.  * transmitted, and stored only in accordance with the terms of such
  20.  * license and with the inclusion of the above copyright notice.  This
  21.  * computer software or any other copies thereof may not be provided or
  22.  * otherwise made available to any other person.
  23.  *
  24.  * U.S. Government Restricted Rights.  This computer software is provided
  25.  * with Restricted Rights.  Use, duplication, or disclosure by the
  26.  * Government is subject to restrictions as set forth in subparagraph (c)
  27.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  28.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  29.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  30.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  31.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  32.  *
  33.  **************************************************************************/
  34.  
  35. #include <iosfwd>
  36. #ifndef _RWSTD_NO_NAMESPACE
  37. namespace std {
  38. #endif
  39.  
  40.   /*
  41.    * Class mbstate_t
  42.    */
  43.  
  44. #ifdef _RWSTD_NO_MBSTATE_T
  45.   struct _RWSTDExport mbstate_t
  46.   { 
  47.     mbstate_t( long state=0 ) 
  48.       : __mbstate(state) { ; }
  49.  
  50.     mbstate_t(const mbstate_t& state) 
  51.       : __mbstate(state.__mbstate) { ; }
  52.               
  53.     mbstate_t& operator=(const mbstate_t& state)
  54.     {
  55.       if ( &state != this )
  56.         __mbstate= state.__mbstate;              
  57.       return *this;
  58.     }
  59.  
  60.     mbstate_t& operator=(const long state)
  61.     {
  62.       __mbstate= state;              
  63.       return *this;
  64.     } 
  65.  
  66.     bool operator==(const mbstate_t& state) const
  67.     {
  68.       return ( __mbstate == state.__mbstate );
  69.     }
  70.  
  71.     bool operator!=(const mbstate_t& state) const
  72.     {
  73.       return ( !(__mbstate == state.__mbstate) );
  74.     }
  75.                    
  76.     long __mbstate;                
  77.   };          
  78.  
  79. #endif // _RWSTD_NO_MBSTATE_T 
  80.  
  81.   /*
  82.    * Class fpos
  83.    */
  84.  
  85.   /* It maintains all the information necessary to restore an arbitrary
  86.    * sequence, controlled by the Standard C++ library, to a previous stream
  87.    * position and conversion state.
  88.    */
  89.  
  90.   template <class stateT>
  91.   class _RWSTDExportTemplate fpos
  92.   {
  93.   public:
  94.     //
  95.     // Types:
  96.     //
  97.     typedef stateT  state_type;
  98.       
  99.     inline fpos(long off = 0);
  100.  
  101. #ifdef _RWSTD_NO_MBSTATE_T
  102.     inline _EXPLICIT fpos(state_type);
  103. #endif
  104.     inline operator long() const;
  105.  
  106.     inline fpos(const fpos<stateT>&);
  107.     inline fpos<stateT>& operator= (const fpos<stateT>&);
  108.  
  109.     inline state_type   state () const;
  110.     inline state_type   state (state_type);
  111.  
  112.     inline fpos<stateT>& operator+=(const fpos<stateT> &off);
  113.     inline fpos<stateT>  operator+(const fpos<stateT> &off) const;
  114.  
  115.     inline fpos<stateT>& operator-=(const fpos<stateT> &off);
  116.     inline fpos<stateT>  operator-(const fpos<stateT> &off) const;
  117.  
  118.     inline fpos<stateT>& operator+=(int off);
  119.     inline fpos<stateT>  operator+(int off) const;
  120.  
  121.     inline fpos<stateT>& operator-=(int off);
  122.     inline fpos<stateT>  operator-(int off) const;
  123.  
  124.     inline fpos<stateT>& operator+=(long off);
  125.     inline fpos<stateT>  operator+(long off) const;
  126.  
  127.     inline fpos<stateT>& operator-=(long off);
  128.     inline fpos<stateT>  operator-(long off) const;
  129.  
  130.     inline bool operator==(const fpos<stateT>& rhs) const;
  131.     inline bool operator!=(const fpos<stateT>& rhs) const;
  132.  
  133.     inline bool operator< (const fpos<stateT>& rhs) const;
  134.     inline bool operator> (const fpos<stateT>& rhs) const;
  135.  
  136.     inline bool operator<= (const fpos<stateT>& rhs) const;
  137.     inline bool operator>= (const fpos<stateT>& rhs) const;
  138.  
  139.     inline bool operator==(const int& rhs) const;
  140.     inline bool operator!=(const int& rhs) const;
  141.  
  142.     inline bool operator< (const int& rhs) const;
  143.     inline bool operator> (const int& rhs) const;
  144.  
  145.     inline bool operator<= (const int& rhs) const;
  146.     inline bool operator>= (const int& rhs) const;
  147.  
  148.     inline bool operator==(const long& rhs) const;
  149.     inline bool operator!=(const long& rhs) const;
  150.  
  151.     inline bool operator< (const long& rhs) const;
  152.     inline bool operator> (const long& rhs) const;
  153.  
  154.     inline bool operator<= (const long& rhs) const;
  155.     inline bool operator>= (const long& rhs) const;
  156.                       
  157.   private:
  158.  
  159.     long               __pos;     // signed displacement
  160.     state_type         __state;   // conversion state
  161.     bool               __status;  // status
  162.   };
  163.   /*
  164.    *     Class fpos member functions
  165.    */
  166.  
  167.   /*
  168.    * fpos(long)
  169.    */
  170.  
  171.   template <class stateT>
  172.   inline
  173.   fpos<stateT>::fpos(long off)
  174.   : __pos(off)
  175.   , __state(stateT()) 
  176.   , __status(true)
  177.   {
  178.     if ( off == -1 ) __status = false;
  179.   }
  180.  
  181.   /*
  182.    * fpos(stateT)
  183.    */
  184.  
  185. #ifdef _RWSTD_NO_MBSTATE_T
  186.   template <class stateT>
  187.   inline
  188.   fpos<stateT>::fpos(stateT state)
  189.   : __pos(0)
  190.   , __state(state)
  191.   , __status(true)
  192.   {;}
  193. #endif // _RWSTD_NO_MBSTATE_T 
  194.  
  195.   /*
  196.    * fpos(const fpos&)
  197.    */
  198.  
  199.   template <class stateT> 
  200.   inline
  201.   fpos<stateT>::fpos(const fpos<stateT>& str_pos)
  202.   {
  203.     __pos   = str_pos.__pos;
  204.     __state = str_pos.__state;
  205.     __status = str_pos.__status;      
  206.   }
  207.  
  208.   /*
  209.    * state_type state(state_type)
  210.    */
  211.  
  212.   template <class stateT>
  213.   inline _TYPENAME fpos<stateT>::state_type 
  214.   fpos<stateT>::state(state_type state)
  215.   {
  216.     state_type var=__state; 
  217.     __state = state;
  218.     return var;
  219.   }
  220.  
  221.   /*
  222.    * operator long ( )
  223.    */
  224.  
  225.   template <class stateT>
  226.   inline fpos<stateT>::operator long() const
  227.   {
  228.     return (long) __pos;
  229.   }
  230.  
  231.   /*
  232.    * fpos& operator=(const fpos&)
  233.    */
  234.  
  235.   template <class stateT>
  236.   inline fpos<stateT>& 
  237.   fpos<stateT>::operator=(const fpos<stateT>& str_pos)
  238.   {
  239.     if ( &str_pos != this )
  240.     {
  241.       __pos    = str_pos.__pos;
  242.       __state  = str_pos.__state;
  243.       __status = str_pos.__status;
  244.     }
  245.     return *this;
  246.   }
  247.  
  248.   /*
  249.    * state_type state() const
  250.    */
  251.  
  252.   template <class stateT>
  253.   inline _TYPENAME fpos<stateT>::state_type 
  254.   fpos<stateT>::state() const
  255.   {
  256.     return __state;
  257.   }
  258.  
  259.   /*
  260.    * fpos& operator+=(const fpos&)
  261.    */
  262.  
  263.   template <class stateT>
  264.   inline fpos<stateT>& 
  265.   fpos<stateT>::operator+=(const fpos<stateT>& off)
  266.   {
  267.     __pos += off.__pos;
  268.     return *this;
  269.   }
  270.  
  271.   /*
  272.    * fpos operator+(const fpos&) const
  273.    */
  274.  
  275.   template <class stateT>
  276.   inline fpos<stateT> 
  277.   fpos<stateT>::operator+(const fpos<stateT>& off) const
  278.   {
  279.     fpos<stateT> temp(*this);
  280.     temp.__pos += off.__pos; 
  281.     return temp;
  282.   }
  283.  
  284.   /*
  285.    * fpos operator-(const fpos<stateT>& off) const
  286.    */
  287.  
  288.   template <class stateT>
  289.   inline fpos<stateT> 
  290.   fpos<stateT>::operator-(const fpos<stateT>& off) const
  291.   {
  292.     fpos<stateT> temp(*this);
  293.     temp.__pos -= off.__pos; 
  294.     return temp;
  295.   }
  296.  
  297.   /*
  298.    * fpos& operator-=(const fpos&)
  299.    */
  300.  
  301.   template <class stateT>
  302.   inline fpos<stateT>& 
  303.   fpos<stateT>::operator-=(const fpos<stateT>& off)
  304.   {
  305.     __pos -= off.__pos;
  306.     return *this;
  307.   }
  308.  
  309.   /*
  310.    * fpos& operator+=(int)
  311.    */
  312.  
  313.   template <class stateT>
  314.   inline fpos<stateT>& 
  315.   fpos<stateT>::operator+=(int off)
  316.   {
  317.     __pos += off;
  318.     return *this;
  319.   }
  320.  
  321.   /*
  322.    * fpos operator+(int) const
  323.    */
  324.  
  325.   template <class stateT>
  326.   inline fpos<stateT> 
  327.   fpos<stateT>::operator+(int off) const
  328.   {
  329.     fpos<stateT> temp(*this);
  330.     temp.__pos += off; 
  331.     return temp;
  332.   }
  333.  
  334.   /*
  335.    * fpos operator-(int off) const
  336.    */
  337.  
  338.   template <class stateT>
  339.   inline fpos<stateT> 
  340.   fpos<stateT>::operator-(int off) const
  341.   {
  342.     fpos<stateT> temp(*this);
  343.     temp.__pos -= off; 
  344.     return temp;
  345.   }
  346.  
  347.   /*
  348.    * fpos& operator-=(int)
  349.    */
  350.  
  351.   template <class stateT>
  352.   inline fpos<stateT>& 
  353.   fpos<stateT>::operator-=(int off)
  354.   {
  355.     __pos -= off;
  356.     return *this;
  357.   }
  358.  
  359.   /*
  360.    * fpos& operator-=(long)
  361.    */
  362.  
  363.   template <class stateT>
  364.   inline fpos<stateT>& 
  365.   fpos<stateT>::operator-=(long off)
  366.   {
  367.     __pos -= off;
  368.     return *this;
  369.   }
  370.  
  371.   /*
  372.    * fpos operator-(long off) const
  373.    */
  374.  
  375.   template <class stateT>
  376.   inline fpos<stateT> 
  377.   fpos<stateT>::operator-(long off) const
  378.   {
  379.     fpos<stateT> temp(*this);
  380.     temp.__pos -= off; 
  381.     return temp;
  382.   }
  383.  
  384.   /*
  385.    * fpos& operator+=(long)
  386.    */
  387.  
  388.   template <class stateT>
  389.   inline fpos<stateT>& 
  390.   fpos<stateT>::operator+=(long off)
  391.   {
  392.     __pos += off;
  393.     return *this;
  394.   }
  395.  
  396.   /*
  397.    * fpos operator+(long) const
  398.    */
  399.  
  400.   template <class stateT>
  401.   inline fpos<stateT> 
  402.   fpos<stateT>::operator+(long off) const
  403.   {
  404.     fpos<stateT> temp(*this);
  405.     temp.__pos += off; 
  406.     return temp;
  407.   }
  408.  
  409.   /*
  410.    * bool operator==(const fpos&) const
  411.    */
  412.  
  413.   template <class stateT>
  414.   inline bool 
  415.   fpos<stateT>::operator==(const fpos<stateT>& pos) const
  416.   { 
  417.     if ( !(__status || pos.__status) ) return true;
  418.     return ( ( __pos == pos.__pos ) 
  419. #ifndef _RWSTD_NO_MBSTATE_COMPARE
  420.              && ( __state == pos.__state )
  421. #endif 
  422.              &&  ( __status == pos.__status ) );
  423.   }
  424.  
  425.   /*
  426.    * bool operator!=(const fpos&) const
  427.    */
  428.  
  429.   template <class stateT>
  430.   inline bool 
  431.   fpos<stateT>::operator!=(const fpos<stateT>& pos) const
  432.   {
  433.     return !(*this == pos);
  434.   }
  435.  
  436.   /*
  437.    * bool operator< (const fpos&) const
  438.    */
  439.  
  440.   template <class stateT>
  441.   inline bool 
  442.   fpos<stateT>::operator< (const fpos<stateT>& pos) const
  443.   {
  444.     return ( __pos < pos.__pos );
  445.   }
  446.  
  447.   /*
  448.    * bool operator> (const fpos&) const
  449.    */
  450.  
  451.   template <class stateT>
  452.   inline bool 
  453.   fpos<stateT>::operator> (const fpos<stateT>& pos) const
  454.   {
  455.     return ( __pos > pos.__pos );
  456.   }
  457.  
  458.   /*
  459.    * bool operator<= (const fpos&) const
  460.    */
  461.  
  462.   template <class stateT>
  463.   inline bool 
  464.   fpos<stateT>::operator<= (const fpos<stateT>& pos) const
  465.   {
  466.     return ( __pos <= pos.__pos );
  467.   }
  468.  
  469.   /*
  470.    * bool operator>= (const fpos&) const
  471.    */
  472.  
  473.   template <class stateT>
  474.   inline bool 
  475.   fpos<stateT>::operator>= (const fpos<stateT>& pos) const
  476.   {
  477.     return ( __pos >= pos.__pos );
  478.   }
  479.  
  480.   /*
  481.    * bool operator==(const int&) const
  482.    */
  483.  
  484.   template <class stateT>
  485.   inline bool 
  486.   fpos<stateT>::operator==(const int& pos) const
  487.   { 
  488.     return (  __pos == pos );
  489.   }
  490.  
  491.   /*
  492.    * bool operator!=(const int&) const
  493.    */
  494.  
  495.   template <class stateT>
  496.   inline bool 
  497.   fpos<stateT>::operator!=(const int& pos) const
  498.   {
  499.     return !(*this == pos);
  500.   }
  501.  
  502.   /*
  503.    * bool operator< (const int&) const
  504.    */
  505.  
  506.   template <class stateT>
  507.   inline bool 
  508.   fpos<stateT>::operator< (const int& pos) const
  509.   {
  510.     return ( __pos < pos );
  511.   }
  512.  
  513.   /*
  514.    * bool operator> (const int&) const
  515.    */
  516.  
  517.   template <class stateT>
  518.   inline bool 
  519.   fpos<stateT>::operator> (const int& pos) const
  520.   { 
  521.     return ( __pos > pos );
  522.   }
  523.  
  524.   /*
  525.    * bool operator<= (const int&) const
  526.    */
  527.  
  528.   template <class stateT>
  529.   inline bool 
  530.   fpos<stateT>::operator<= (const int& pos) const
  531.   { 
  532.     return ( __pos <= pos );
  533.   }
  534.  
  535.   /*
  536.    * bool operator>= (const int&) const
  537.    */
  538.  
  539.   template <class stateT>
  540.   inline bool 
  541.   fpos<stateT>::operator>= (const int& pos) const
  542.   {
  543.     return ( __pos >= pos );
  544.   }
  545.  
  546.   /*
  547.    * bool operator==(const long&) const
  548.    */
  549.  
  550.   template <class stateT>
  551.   inline bool 
  552.   fpos<stateT>::operator==(const long& pos) const
  553.   { 
  554.     return (  __pos == pos );
  555.   }
  556.  
  557.   /*
  558.    * bool operator!=(const long&) const
  559.    */
  560.  
  561.   template <class stateT>
  562.   inline bool 
  563.   fpos<stateT>::operator!=(const long& pos) const
  564.   {
  565.     return !(*this == pos);
  566.   }
  567.  
  568.   /*
  569.    * bool operator< (const long&) const
  570.    */
  571.  
  572.   template <class stateT>
  573.   inline bool 
  574.   fpos<stateT>::operator< (const long& pos) const
  575.   {
  576.     return ( __pos < pos );
  577.   }
  578.  
  579.   /*
  580.    * bool operator> (const long&) const
  581.    */
  582.  
  583.   template <class stateT>
  584.   inline bool 
  585.   fpos<stateT>::operator> (const long& pos) const
  586.   { 
  587.     return ( __pos > pos );
  588.   }
  589.  
  590.   /*
  591.    * bool operator<= (const long&) const
  592.    */
  593.  
  594.   template <class stateT>
  595.   inline bool 
  596.   fpos<stateT>::operator<= (const long& pos) const
  597.   { 
  598.     return ( __pos >= pos );
  599.   }
  600.  
  601.   /*
  602.    * bool operator>= (const long&) const
  603.    */
  604.  
  605.   template <class stateT>
  606.   inline bool 
  607.   fpos<stateT>::operator>= (const long& pos) const
  608.   {
  609.     return ( __pos <= pos );
  610.   }
  611.  
  612. #ifndef _RWSTD_NO_NAMESPACE
  613. }
  614. #endif
  615.  
  616. #endif // __RWSTD_IOTRAITS
  617. #pragma option pop
  618. #endif /* __IOTRAITS_H */
  619.