home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / iotraits.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  14.8 KB  |  758 lines

  1. #ifndef __RWSTD_IOTRAITS
  2. #define __RWSTD_IOTRAITS
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * iotraits - Declarations for traits 
  8.  *
  9.  * $Id: iotraits,v 1.7 1996/09/24 19:17:50 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  * 
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #include <iosfwd>
  46.  
  47.  
  48. #ifndef _RWSTD_NO_NAMESPACE
  49. namespace std {
  50. #endif
  51.  
  52. /*
  53.  * these are all necessary for the "traits" class
  54.  */
  55.  
  56. /*
  57.  * MBSTATE_T
  58.  * 
  59.  */
  60.  
  61. // should come from the C library
  62. // not from there
  63.  
  64. #ifdef _RWSTD_NO_MBSTATE_T
  65. struct _RWSTDExport mbstate_t { 
  66.                                   
  67.                    mbstate_t( long state=0 ) 
  68.                    : mbstate_(state) { ; }
  69.  
  70.                    mbstate_t(const mbstate_t& state) 
  71.                    : mbstate_(state.mbstate_) { ; }
  72.               
  73.                    mbstate_t& operator=(const mbstate_t& state)
  74.                     {
  75.                        if ( &state != this )
  76.                          mbstate_= state.mbstate_;              
  77.  
  78.                        return *this;
  79.                     }
  80.  
  81.                    mbstate_t& operator=(const long state)
  82.                     {
  83.                        mbstate_= state;              
  84.  
  85.                        return *this;
  86.                     } 
  87.  
  88.                    bool operator==(const mbstate_t& state) const
  89.                     {
  90.                        return ( mbstate_ == state.mbstate_ );
  91.                     }
  92.  
  93.                    bool operator!=(const mbstate_t& state) const
  94.                     {
  95.                        return ( !(mbstate_ == state.mbstate_) );
  96.                     }
  97.  
  98.                    
  99.                    long mbstate_;                
  100.                       
  101.                  };          
  102.  
  103. #endif /* _RWSTD_NO_MBSTATE_T */
  104.  
  105. /*
  106.  * class FPOS
  107.  *
  108.  * it maintains all of the information necessary to restore an arbitrary
  109.  * sequence, controlled by the Standard C++ library, to a previous stream
  110.  * position and conversion state.
  111.  */
  112.  
  113.  
  114. /*
  115.  *
  116.  *     CLASS fpos
  117.  *
  118.  */
  119.  
  120. #ifndef _RWSTD_NO_SIMPLE_DEFAULT_TEMPLATES
  121. template <class stateT = mbstate_t> 
  122. #else
  123. template <class stateT>
  124. #endif
  125. class _RWSTDExportTemplate fpos {
  126.  
  127.   public:
  128.           
  129.     typedef stateT  state_type;
  130.  
  131.     inline fpos(long off = 0);
  132.  
  133.     inline fpos(long, long, state_type);
  134.  
  135. #ifdef _RWSTD_NO_MBSTATE_T
  136.     inline fpos(state_type);
  137. #endif
  138.  
  139.     inline bool good();
  140.  
  141.     inline operator long() const;
  142.  
  143.     inline fpos(const fpos<stateT>&);
  144.     inline fpos<stateT>& operator= (const fpos<stateT>&);
  145.  
  146.     inline long         offset (long);
  147.     inline state_type   state (state_type);
  148.     inline long         pos(long);
  149.  
  150.     inline long         offset() const;
  151.     inline long         pos() const; 
  152.     inline state_type   state () const;
  153.                        
  154.     inline fpos<stateT>& operator+=(const fpos<stateT> &off);
  155.     inline fpos<stateT>  operator+(const fpos<stateT> &off) const;
  156.     inline fpos<stateT>& operator-=(const fpos<stateT> &off);
  157.     inline fpos<stateT>  operator-(const fpos<stateT> &off) const;
  158.  
  159.     inline fpos<stateT>& operator+=(int off);
  160.     inline fpos<stateT>  operator+(int off) const;
  161.     inline fpos<stateT>& operator-=(int off);
  162.     inline fpos<stateT>  operator-(int off) const;
  163.  
  164.     inline fpos<stateT>& operator+=(long off);
  165.     inline fpos<stateT>  operator+(long off) const;
  166.     inline fpos<stateT>& operator-=(long off);
  167.     inline fpos<stateT>  operator-(long off) const;
  168.  
  169.     inline bool operator==(const fpos<stateT>& rhs) const;
  170.     inline bool operator!=(const fpos<stateT>& rhs) const;
  171.  
  172.     inline bool operator< (const fpos<stateT>& rhs) const;
  173.     inline bool operator> (const fpos<stateT>& rhs) const;
  174.     inline bool operator<= (const fpos<stateT>& rhs) const;
  175.     inline bool operator>= (const fpos<stateT>& rhs) const;
  176.  
  177.     inline bool operator==(const int& rhs) const;
  178.     inline bool operator!=(const int& rhs) const;
  179.  
  180.     inline bool operator< (const int& rhs) const;
  181.     inline bool operator> (const int& rhs) const;
  182.     inline bool operator<= (const int& rhs) const;
  183.     inline bool operator>= (const int& rhs) const;
  184.  
  185.     inline bool operator==(const long& rhs) const;
  186.     inline bool operator!=(const long& rhs) const;
  187.  
  188.     inline bool operator< (const long& rhs) const;
  189.     inline bool operator> (const long& rhs) const;
  190.     inline bool operator<= (const long& rhs) const;
  191.     inline bool operator>= (const long& rhs) const;
  192.  
  193.                       
  194.  private:
  195.  
  196.     long               pos_;     // signed displacement
  197.     long           fp_ ;     // absolute position
  198.     state_type         state_;   // conversion state
  199.     bool               status_;  // status                                                             
  200. };
  201.  
  202.  
  203. /*
  204.  *
  205.  *     CLASS fpos MEMBER FUNCTIONS
  206.  *
  207.  */
  208.  
  209.  
  210. /*
  211.  * fpos(long)
  212.  */
  213.  
  214. template <class stateT>
  215. inline
  216. fpos<stateT>::fpos(long off)
  217. : pos_(off)
  218. , fp_(0)
  219. , state_(0) 
  220. , status_(true)
  221. {
  222.   if ( off == -1 ) status_ = false;
  223. }
  224.  
  225. /*
  226.  * fpos(stateT)
  227.  */
  228. #ifdef _RWSTD_NO_MBSTATE_T
  229. template <class stateT>
  230. inline
  231. fpos<stateT>::fpos(stateT state)
  232. : pos_(0)
  233. , fp_(0)
  234. , state_(state)
  235. , status_(true)
  236. {;}
  237. #endif
  238.  
  239. /*
  240.  * fpos(long,fpos_t,state_type)
  241.  */
  242.  
  243. template <class stateT>
  244. inline
  245. fpos<stateT>::fpos(long off,long fposit,state_type state)
  246. : pos_(off)
  247. , fp_(fposit)
  248. , state_(state)
  249. , status_(true)
  250. { ; }
  251.  
  252.  
  253. /*
  254.  * fpos(const fpos&)
  255.  */
  256.  
  257. template <class stateT> 
  258. inline
  259. fpos<stateT>::fpos(const fpos<stateT>& str_pos)
  260. {
  261.       pos_   = str_pos.pos_;
  262.       fp_    = str_pos.fp_;
  263.       state_ = str_pos.state_;
  264.       status_ = str_pos.status_;      
  265. }
  266.  
  267.  
  268. /*
  269.  * int offset(long)
  270.  */
  271.  
  272. template <class stateT>
  273. inline long 
  274. fpos<stateT>::offset(long off)
  275. {
  276.   long var=pos_;
  277.   pos_ = off; 
  278.  
  279.   return var;
  280. }
  281.  
  282. /*
  283.  * long pos(long)
  284.  */
  285.  
  286. template <class stateT>
  287. inline long
  288. fpos<stateT>::pos(long posi)
  289. {
  290.   long var=fp_;
  291.   fp_ = posi;
  292.  
  293.   return var;
  294. }
  295.  
  296.  
  297. /*
  298.  * state_type state(state_type)
  299.  */
  300.  
  301. template <class stateT>
  302. inline _TYPENAME fpos<stateT>::state_type 
  303. fpos<stateT>::state(state_type state)
  304. {
  305.   state_type var=state_; 
  306.   state_ = state;
  307.  
  308.   return var;
  309. }
  310.  
  311.  
  312. /*
  313.  *  bool good ( )
  314.  */
  315.  
  316. template <class stateT>
  317. inline bool 
  318. fpos<stateT>::good() 
  319. {
  320.   return status_;
  321. }
  322.  
  323.  
  324. /*
  325.  * operator long ( )
  326.  */
  327.  
  328. template <class stateT>
  329. inline fpos<stateT>::operator long() const
  330. {
  331.   return (long)( fp_ + pos_ );
  332. }
  333.  
  334. /*
  335.  * fpos& operator=(const fpos&)
  336.  */
  337.  
  338. template <class stateT>
  339. inline fpos<stateT>& 
  340. fpos<stateT>::operator=(const fpos<stateT>& str_pos)
  341. {
  342.   if ( &str_pos != this )
  343.    {
  344.       pos_    = str_pos.pos_;
  345.       fp_     = str_pos.fp_;
  346.       state_  = str_pos.state_;
  347.       status_ = str_pos.status_;
  348.    }
  349.  
  350.   return *this;
  351. }
  352.  
  353. /*
  354.  * long pos() const
  355.  */
  356.  
  357. template <class stateT>
  358. inline long
  359. fpos<stateT>::pos() const
  360. {
  361.   return fp_;
  362. }
  363.  
  364.  
  365. /*
  366.  * long offset() const
  367.  */
  368.  
  369. template <class stateT>
  370. inline long 
  371. fpos<stateT>::offset() const
  372. {
  373.   return pos_;
  374. }
  375.  
  376. /*
  377.  * state_type state() const
  378.  */
  379.  
  380. template <class stateT>
  381. inline _TYPENAME fpos<stateT>::state_type 
  382. fpos<stateT>::state() const
  383. {
  384.   return state_;
  385. }
  386.  
  387.  
  388. /*
  389.  * fpos& operator+=(const fpos&)
  390.  */
  391.  
  392. template <class stateT>
  393. inline fpos<stateT>& 
  394. fpos<stateT>::operator+=(const fpos<stateT>& off)
  395. {
  396.   pos_ += off.pos_ + off.fp_;
  397.  
  398.   return *this;
  399. }
  400.  
  401. /*
  402.  * fpos operator+(const fpos&) const
  403.  */
  404.  
  405. template <class stateT>
  406. inline fpos<stateT> 
  407. fpos<stateT>::operator+(const fpos<stateT>& off) const
  408. {
  409.   fpos<stateT> temp(*this);
  410.   temp.pos_ += off.pos_ + off.fp_; 
  411.   return temp;
  412. }
  413.  
  414. /*
  415.  * fpos operator-(const fpos<stateT>& off) const
  416.  */
  417.  
  418. template <class stateT>
  419. inline fpos<stateT> 
  420. fpos<stateT>::operator-(const fpos<stateT>& off) const
  421. {
  422.   fpos<stateT> temp(*this);
  423.   temp.pos_ -= (off.pos_ + off.fp_); 
  424.   return temp;
  425. }
  426.  
  427.  
  428. /*
  429.  * fpos& operator-=(const fpos&)
  430.  */
  431.  
  432. template <class stateT>
  433. inline fpos<stateT>& 
  434. fpos<stateT>::operator-=(const fpos<stateT>& off)
  435. {
  436.   pos_ -= (off.pos_ + off.fp_);
  437.  
  438.   return *this;
  439. }
  440.  
  441.  
  442. /*
  443.  * fpos& operator+=(int)
  444.  */
  445.  
  446. template <class stateT>
  447. inline fpos<stateT>& 
  448. fpos<stateT>::operator+=(int off)
  449. {
  450.   pos_ += off;
  451.  
  452.   return *this;
  453. }
  454.  
  455. /*
  456.  * fpos operator+(int) const
  457.  */
  458.  
  459. template <class stateT>
  460. inline fpos<stateT> 
  461. fpos<stateT>::operator+(int off) const
  462. {
  463.   fpos<stateT> temp(*this);
  464.   temp.pos_ += off; 
  465.   return temp;
  466. }
  467.  
  468. /*
  469.  * fpos operator-(int off) const
  470.  */
  471.  
  472. template <class stateT>
  473. inline fpos<stateT> 
  474. fpos<stateT>::operator-(int off) const
  475. {
  476.   fpos<stateT> temp(*this);
  477.   temp.pos_ -= off; 
  478.   return temp;
  479. }
  480.  
  481.  
  482. /*
  483.  * fpos& operator-=(int)
  484.  */
  485.  
  486. template <class stateT>
  487. inline fpos<stateT>& 
  488. fpos<stateT>::operator-=(int off)
  489. {
  490.   pos_ -= off;
  491.  
  492.   return *this;
  493. }
  494.  
  495. /*
  496.  * fpos& operator-=(long)
  497.  */
  498.  
  499. template <class stateT>
  500. inline fpos<stateT>& 
  501. fpos<stateT>::operator-=(long off)
  502. {
  503.   pos_ -= off;
  504.  
  505.   return *this;
  506. }
  507.  
  508. /*
  509.  * fpos operator-(long off) const
  510.  */
  511.  
  512. template <class stateT>
  513. inline fpos<stateT> 
  514. fpos<stateT>::operator-(long off) const
  515. {
  516.   fpos<stateT> temp(*this);
  517.   temp.pos_ -= off; 
  518.   return temp;
  519. }
  520.  
  521. /*
  522.  * fpos& operator+=(long)
  523.  */
  524.  
  525. template <class stateT>
  526. inline fpos<stateT>& 
  527. fpos<stateT>::operator+=(long off)
  528. {
  529.   pos_ += off;
  530.  
  531.   return *this;
  532. }
  533.  
  534. /*
  535.  * fpos operator+(long) const
  536.  */
  537.  
  538. template <class stateT>
  539. inline fpos<stateT> 
  540. fpos<stateT>::operator+(long off) const
  541. {
  542.   fpos<stateT> temp(*this);
  543.   temp.pos_ += off; 
  544.   return temp;
  545. }
  546.  
  547.  
  548. /*
  549.  * bool operator==(const fpos&) const
  550.  */
  551.  
  552. template <class stateT>
  553. inline bool 
  554. fpos<stateT>::operator==(const fpos<stateT>& pos) const
  555.   if ( !(status_ || pos.status_) ) return true;
  556.   return ( ( (pos_+fp_) == (pos.pos_+pos.fp_) ) && ( state_ == pos.state_ ) 
  557.   &&  ( status_ == pos.status_ ) );
  558. }
  559.  
  560. /*
  561.  * bool operator!=(const fpos&) const
  562.  */
  563.  
  564. template <class stateT>
  565. inline bool 
  566. fpos<stateT>::operator!=(const fpos<stateT>& pos) const
  567. {
  568.   return !(*this == pos);
  569. }
  570.  
  571.  
  572. /*
  573.  * bool operator< (const fpos&) const
  574.  */
  575.  
  576. template <class stateT>
  577. inline bool 
  578. fpos<stateT>::operator< (const fpos<stateT>& pos) const
  579. {
  580.   return ( (pos_+fp_) < (pos.pos_ + pos.fp_) );
  581. }
  582.  
  583. /*
  584.  * bool operator> (const fpos&) const
  585.  */
  586.  
  587. template <class stateT>
  588. inline bool 
  589. fpos<stateT>::operator> (const fpos<stateT>& pos) const
  590. {
  591.  return ( (pos_+fp_) > (pos.pos_ + pos.fp_) );
  592. }
  593.  
  594. /*
  595.  * bool operator<= (const fpos&) const
  596.  */
  597.  
  598. template <class stateT>
  599. inline bool 
  600. fpos<stateT>::operator<= (const fpos<stateT>& pos) const
  601. {
  602.  return ( (pos_+fp_) <= (pos.pos_ + pos.fp_) );
  603. }
  604.  
  605. /*
  606.  * bool operator>= (const fpos&) const
  607.  */
  608.  
  609. template <class stateT>
  610. inline bool 
  611. fpos<stateT>::operator>= (const fpos<stateT>& pos) const
  612. {
  613.    return ( (pos_+fp_) >= (pos.pos_ + pos.fp_) );
  614. }
  615.  
  616.  
  617. /*
  618.  * bool operator==(const int&) const
  619.  */
  620.  
  621. template <class stateT>
  622. inline bool 
  623. fpos<stateT>::operator==(const int& pos) const
  624.   return (  (pos_+fp_) == pos );
  625. }
  626.  
  627. /*
  628.  * bool operator!=(const int&) const
  629.  */
  630.  
  631. template <class stateT>
  632. inline bool 
  633. fpos<stateT>::operator!=(const int& pos) const
  634. {
  635.   return !(*this == pos);
  636. }
  637.  
  638.  
  639. /*
  640.  * bool operator< (const int&) const
  641.  */
  642.  
  643. template <class stateT>
  644. inline bool 
  645. fpos<stateT>::operator< (const int& pos) const
  646. {
  647.   return ( (pos_+fp_) < pos );
  648. }
  649.  
  650. /*
  651.  * bool operator> (const int&) const
  652.  */
  653.  
  654. template <class stateT>
  655. inline bool 
  656. fpos<stateT>::operator> (const int& pos) const
  657.  return ( (pos_+fp_) > pos );
  658. }
  659.  
  660. /*
  661.  * bool operator<= (const int&) const
  662.  */
  663.  
  664. template <class stateT>
  665. inline bool 
  666. fpos<stateT>::operator<= (const int& pos) const
  667.  return ( (pos_+fp_) <= pos );
  668. }
  669.  
  670. /*
  671.  * bool operator>= (const int&) const
  672.  */
  673.  
  674. template <class stateT>
  675. inline bool 
  676. fpos<stateT>::operator>= (const int& pos) const
  677. {
  678.    return ( (pos_+fp_) >= pos );
  679. }
  680.  
  681.  
  682. /*
  683.  * bool operator==(const long&) const
  684.  */
  685.  
  686. template <class stateT>
  687. inline bool 
  688. fpos<stateT>::operator==(const long& pos) const
  689.   return (  (pos_+fp_) == pos );
  690. }
  691.  
  692. /*
  693.  * bool operator!=(const long&) const
  694.  */
  695.  
  696. template <class stateT>
  697. inline bool 
  698. fpos<stateT>::operator!=(const long& pos) const
  699. {
  700.   return !(*this == pos);
  701. }
  702.  
  703. /*
  704.  * bool operator< (const long&) const
  705.  */
  706.  
  707. template <class stateT>
  708. inline bool 
  709. fpos<stateT>::operator< (const long& pos) const
  710. {
  711.   return ( (pos_+fp_) < pos );
  712. }
  713.  
  714. /*
  715.  * bool operator> (const long&) const
  716.  */
  717.  
  718. template <class stateT>
  719. inline bool 
  720. fpos<stateT>::operator> (const long& pos) const
  721.  return ( (pos_+fp_) > pos );
  722. }
  723.  
  724. /*
  725.  * bool operator<= (const long&) const
  726.  */
  727.  
  728. template <class stateT>
  729. inline bool 
  730. fpos<stateT>::operator<= (const long& pos) const
  731.  return ( (pos_+fp_) >= pos );
  732. }
  733.  
  734. /*
  735.  * bool operator>= (const long&) const
  736.  */
  737.  
  738. template <class stateT>
  739. inline bool 
  740. fpos<stateT>::operator>= (const long& pos) const
  741. {
  742.    return ( (pos_+fp_) <= pos );
  743. }
  744.  
  745. #ifndef _RWSTD_NO_NAMESPACE
  746. }
  747. #endif
  748.  
  749. #pragma option pop
  750. #endif // __RWSTD_IOTRAITS
  751.