home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / Rw / IOSBASE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  13.1 KB  |  606 lines

  1. #ifndef __IOSBASE_H
  2. #define __IOSBASE_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __STD_IOSBASE__
  6. #define __STD_IOSBASE__
  7. /***************************************************************************
  8.  *
  9.  * iosbase - Declarations for the Standard Library basic stream I/O
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED
  15.  *
  16.  * The software and information contained herein are proprietary to, and
  17.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  18.  * intends to preserve as trade secrets such software and information.
  19.  * This software is furnished pursuant to a written license agreement and
  20.  * may be used, copied, transmitted, and stored only in accordance with
  21.  * the terms of such license and with the inclusion of the above copyright
  22.  * notice.  This software and information or any other copies thereof may
  23.  * not be provided or otherwise made available to any other person.
  24.  *
  25.  * Notwithstanding any other lease or license that may pertain to, or
  26.  * accompany the delivery of, this computer software and information, the
  27.  * rights of the Government regarding its use, reproduction and disclosure
  28.  * are as set forth in Section 52.227-19 of the FARS Computer
  29.  * Software-Restricted Rights clause.
  30.  * 
  31.  * Use, duplication, or disclosure by the Government is subject to
  32.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  33.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  34.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  35.  * P.O. Box 2328, Corvallis, Oregon 97339.
  36.  *
  37.  * This computer software and information is distributed with "restricted
  38.  * rights."  Use, duplication or disclosure is subject to restrictions as
  39.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  40.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  41.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  42.  * then the "Alternate III" clause applies.
  43.  *
  44.  **************************************************************************/
  45.  
  46. #include <stdcomp.h>
  47.  
  48. #ifndef _RWSTD_NO_NEW_HEADER
  49. #include <cstdio>
  50. #include <cstdlib>
  51. #include <cstring>
  52. #ifndef _RWSTD_NO_WIDE_CHAR
  53. #include <cwchar>
  54. #ifndef _RWSTD_NO_WCTYPE_H
  55. #include <cwctype>
  56. #endif 
  57. #endif // _RWSTD_NO_WIDE_CHAR
  58. #include <cstddef>
  59. #else
  60. #include <stdio.h>
  61. #include <stdlib.h>
  62. #include <string.h>
  63. #ifndef _RWSTD_NO_WIDE_CHAR
  64. #ifndef _RWSTD_NO_WCHAR_H
  65. #include <wchar.h>
  66. #endif
  67. #ifndef _RWSTD_NO_WCTYPE_H
  68. #include <wctype.h>
  69. #endif
  70. #endif // _RWSTD_NO_WIDE_CHAR
  71. #include <stddef.h>
  72. #endif // _RWSTD_NO_NEW_HEADER
  73.  
  74. #include <rw/stdmutex.h> 
  75.  
  76. #ifndef _RWSTD_NO_EXCEPTIONS
  77. #ifdef _RW_STD_EXCEPT
  78. #include <exception>
  79. #endif
  80. #endif // _RWSTD_NO_EXCEPTIONS
  81.  
  82. #ifndef _RWSTD_NO_NAMESPACE
  83. namespace std {
  84. #endif
  85.  
  86.   typedef long         SZ_T;       
  87.   typedef SZ_T         streamsize;
  88.  
  89.   class _RWSTDExportTemplate __Wide_Init // RW_BUG: fix for bts-42913
  90.   {
  91.     static int    __init_cnt;
  92.   public:
  93.     static int    getinit_cnt_() { return __init_cnt;}
  94.     __Wide_Init();
  95.     ~__Wide_Init();
  96.   };
  97.  
  98.   /*
  99.    *     Class ios_base
  100.    */
  101.  
  102.   class _RWSTDExport ios_base
  103.   {
  104.   public:
  105.  
  106. #ifndef _RWSTD_NO_EXCEPTIONS
  107. #ifdef  _RW_STD_EXCEPT
  108.     class _RWSTDExport failure : public exception
  109.     {
  110.     public:
  111.       _EXPLICIT failure(const string& msg);
  112.       virtual ~failure() _RWSTD_THROW_SPEC_NULL;
  113.       virtual const char* what() const _RWSTD_THROW_SPEC_NULL;
  114.  
  115.     private:
  116.       string __str;
  117.     };
  118. #endif // _RW_STD_EXCEPT
  119. #endif // _RWSTD_NO_EXCEPTIONS
  120.     typedef int      fmtflags;
  121.     
  122.     enum fmt_flags {
  123.       boolalpha   = 0x0001,
  124.       dec         = 0x0002,
  125.       fixed       = 0x0004,
  126.       hex         = 0x0008,
  127.       internal    = 0x0010,
  128.       left        = 0x0020,
  129.       oct         = 0x0040,
  130.       right       = 0x0080,
  131.       scientific  = 0x0100,
  132.       showbase    = 0x0200, 
  133.       showpoint   = 0x0400, 
  134.       showpos     = 0x0800, 
  135.       skipws      = 0x1000, 
  136.       unitbuf     = 0x2000, 
  137.       uppercase   = 0x4000, 
  138.       adjustfield = left | right | internal,
  139.       basefield   = dec | oct | hex,
  140.       floatfield  = scientific | fixed
  141.     };
  142.     
  143.     typedef int      iostate;
  144.  
  145.     enum io_state {
  146.       goodbit     = 0x00,   
  147.       badbit      = 0x01,   
  148.       eofbit      = 0x02,  
  149.       failbit     = 0x04  
  150.     };
  151.  
  152.     typedef int      openmode;
  153.  
  154.     enum open_mode {
  155.       app         = 0x01,   
  156.       binary      = 0x02,  
  157.       in          = 0x04, 
  158.       out         = 0x08,   
  159.       trunc       = 0x10,                  
  160.       ate         = 0x20 
  161.     };
  162.  
  163.     typedef int      seekdir;
  164.  
  165.     enum seek_dir {
  166.       beg         = 0x0,    
  167.       cur         = 0x1,    
  168.       end         = 0x2   
  169.     };        
  170.  
  171.     class _RWSTDExportTemplate Init { // RW_BUG: fix for bts-42913
  172.       static int    __init_cnt;
  173.     public:
  174.       static int    getinit_cnt_() { return __init_cnt;}
  175.       Init();
  176.       ~Init();
  177.     };
  178.  
  179.     inline fmtflags flags() const;
  180.     inline fmtflags flags(fmtflags fmtfl);
  181.     inline fmtflags setf(fmtflags fmtfl);
  182.     inline fmtflags setf(fmtflags fmtfl, fmtflags mask);
  183.     inline void unsetf(fmtflags mask);
  184.  
  185.     inline streamsize precision() const;
  186.     inline streamsize precision(streamsize prec);
  187.     inline streamsize width() const;
  188.     inline streamsize width(streamsize wide);
  189.  
  190.     locale imbue(const locale& loc);
  191.     locale getloc() const
  192.     { return __loc; }
  193.  
  194.     static int xalloc();
  195.     long&  iword(int index);
  196.     void*& pword(int index);
  197.  
  198.     enum event { 
  199.       erase_event   = 0x0001,
  200.       imbue_event   = 0x0002,
  201.       copyfmt_event = 0x0004
  202.     };
  203.  
  204.     typedef void (*event_callback) (event, ios_base&, int index);
  205.     void register_callback( event_callback fn, int index);
  206.     
  207.     ios_base& copyfmt(const ios_base& rhs);
  208.     ios_base& _RW_UNSAFE_copyfmt(const ios_base& rhs);
  209.  
  210.     bool is_synch() 
  211.     { return __sync_with_stdio; }
  212.  
  213.     bool sync_with_stdio(bool sync = true)
  214.     { 
  215.       bool tmp =__sync_with_stdio;
  216.       __sync_with_stdio = sync;
  217.       return tmp;
  218.     }
  219.  
  220.   protected:
  221.  
  222.     ios_base();
  223.     virtual ~ios_base();    
  224.  
  225.     fmtflags           __fmtfl; 
  226.     streamsize         __prec;   
  227.     streamsize         __wide;   
  228.     
  229. #ifdef _RWSTD_MULTI_THREAD
  230.     _RWSTDMutex __stream_mutex;
  231. #endif
  232.  
  233.   private:
  234.  
  235.     void usersize(int);
  236.     locale             __loc;
  237.  
  238.     union ios_user_union {
  239.       long         __lword;
  240.       void        *__pword;
  241.     };
  242.  
  243.     struct register_call {
  244.       int             __index;
  245.       event_callback  __fn;
  246.     }; 
  247.  
  248.     static int                  __index;
  249.     int                         __index_cp;
  250.     int                         __index_callback;
  251.     union  ios_user_union      *__userwords;
  252.     struct register_call       *__registered_call;
  253.     static bool                 __sync_with_stdio;
  254.   };
  255.  
  256.   /*
  257.    *     inline definitions
  258.    */
  259.  
  260.   /*
  261.    * fmtflags flags() const
  262.    */
  263.  
  264.   inline ios_base::fmtflags 
  265.   ios_base::flags() const
  266.   {
  267.     return __fmtfl;
  268.   }
  269.  
  270.   /*
  271.    * fmtflags flags(fmtflags)
  272.    */
  273.  
  274.   inline ios_base::fmtflags 
  275.   ios_base::flags(ios_base::fmtflags flgs)
  276.   {
  277. #ifdef _RWSTD_MULTI_THREAD
  278.     _RWSTDGuard guard(this->__stream_mutex);
  279. #endif
  280.     ios_base::fmtflags      f = __fmtfl;
  281.     __fmtfl = flgs;
  282.     return f;
  283.   }
  284.  
  285.   /*
  286.    * fmtflags setf(fmtflags)
  287.    */
  288.  
  289.   inline ios_base::fmtflags 
  290.   ios_base::setf(ios_base::fmtflags flgs)
  291.   {
  292. #ifdef _RWSTD_MULTI_THREAD
  293.     _RWSTDGuard guard(this->__stream_mutex);
  294. #endif
  295.     ios_base::fmtflags       f = __fmtfl;
  296.     __fmtfl |= flgs;
  297.     return f;
  298.   }
  299.  
  300.   /*
  301.    * fmtflags setf(fmtflags, fmtflags)
  302.    */
  303.  
  304.   inline ios_base::fmtflags 
  305.   ios_base::setf(ios_base::fmtflags flgs, ios_base::fmtflags mask)
  306.   {
  307. #ifdef _RWSTD_MULTI_THREAD
  308.     _RWSTDGuard guard(this->__stream_mutex);
  309. #endif
  310.     ios_base::fmtflags      old = __fmtfl;
  311.     __fmtfl &= ~mask;
  312.     __fmtfl |= (flgs & mask);
  313.     return old;
  314.   }
  315.  
  316.   /*
  317.    * void unsetf(fmtflags)
  318.    */
  319.  
  320.   inline void 
  321.   ios_base::unsetf(ios_base::fmtflags fg)
  322.   {
  323. #ifdef _RWSTD_MULTI_THREAD
  324.     _RWSTDGuard guard(this->__stream_mutex);
  325. #endif
  326.     __fmtfl &= ~fg;
  327.   }
  328.  
  329.   /*
  330.    * streamsize precision() const
  331.    */
  332.  
  333.   inline streamsize 
  334.   ios_base::precision() const
  335.   {
  336.     return __prec;
  337.   }
  338.  
  339.   /*
  340.    * streamsize precision(streamsize)
  341.    */
  342.   inline streamsize 
  343.   ios_base::precision(streamsize p)
  344.   {
  345. #ifdef _RWSTD_MULTI_THREAD
  346.     _RWSTDGuard guard(this->__stream_mutex);
  347. #endif
  348.     streamsize    temp = __prec;
  349.     __prec = p;
  350.     return temp;
  351.   }
  352.  
  353.   /*
  354.    * streamsize width() const
  355.    */
  356.  
  357.   inline streamsize 
  358.   ios_base::width() const
  359.   {
  360.     return __wide;
  361.   }
  362.  
  363.   /*
  364.    * streamsize width(streamsize)
  365.    */
  366.  
  367.   inline streamsize 
  368.   ios_base::width(streamsize w)
  369.   {
  370. #ifdef _RWSTD_MULTI_THREAD
  371.     _RWSTDGuard guard(this->__stream_mutex);
  372. #endif
  373.     streamsize      i = __wide;
  374.     __wide = w;
  375.     return i;
  376.   }
  377.  
  378.   /*
  379.    *     External declarations for manipulators
  380.    */
  381.  
  382.   inline ios_base& unitbuf(ios_base& strm)
  383.   {
  384.     strm.setf(ios_base::unitbuf);
  385.     return strm;
  386.   }
  387.  
  388.   /*
  389.    * unset the unitbuf mode
  390.    */
  391.  
  392.   inline ios_base& nounitbuf(ios_base& strm)
  393.   {
  394.     strm.unsetf(ios_base::unitbuf);
  395.     return strm;
  396.   }
  397.  
  398.   /*
  399.    * says that bool will be inserted/extracted as
  400.    * false/true depending on locale
  401.    */
  402.  
  403.   inline ios_base& boolalpha(ios_base& strm)
  404.   {
  405.     strm.setf(ios_base::boolalpha);
  406.     return strm;
  407.   }
  408.  
  409.   /*
  410.    * bool is inserted/extraced as 0/1
  411.    v   */
  412.  
  413.   inline ios_base& noboolalpha(ios_base& strm)
  414.   {
  415.     strm.unsetf(ios_base::boolalpha);
  416.     return strm;
  417.   }
  418.  
  419.   /*
  420.    * shows the base of the number e.g. 0777 for oct, 0x for hex
  421.    */
  422.  
  423.   inline ios_base& showbase(ios_base& strm)
  424.   {
  425.     strm.setf(ios_base::showbase);
  426.     return strm;
  427.   }
  428.  
  429.   /*
  430.    * does not show the base
  431.    */
  432.  
  433.   inline ios_base& noshowbase(ios_base& strm)
  434.   {
  435.     strm.unsetf(ios_base::showbase);
  436.     return strm;
  437.   }
  438.  
  439.   /*
  440.    * shows the decimal point on floating insertion even if not necessary
  441.    */
  442.  
  443.   inline ios_base& showpoint(ios_base& strm)
  444.   { 
  445.     strm.setf(ios_base::showpoint);
  446.     return strm;
  447.   }
  448.  
  449.   /*
  450.    * does not show the decimal point if not necessary
  451.    */
  452.  
  453.   inline ios_base& noshowpoint(ios_base& strm)
  454.   {
  455.     strm.unsetf(ios_base::showpoint);
  456.     return strm;
  457.   }
  458.  
  459.   /*
  460.    * prints the sign of the number.  will also print '+' for positive #'s
  461.    */
  462.  
  463.   inline ios_base& showpos(ios_base& strm)
  464.   {
  465.     strm.setf(ios_base::showpos);
  466.     return strm;
  467.   }
  468.  
  469.   /*
  470.    * only shows the sign for negative values
  471.    */
  472.  
  473.   inline ios_base& noshowpos(ios_base& strm)
  474.   {
  475.     strm.unsetf(ios_base::showpos);
  476.     return strm;
  477.   }
  478.  
  479.   /*
  480.    * skips the white space when reading characters
  481.    */
  482.  
  483.   inline ios_base& skipws(ios_base& strm)
  484.   {
  485.     strm.setf(ios_base::skipws);
  486.     return strm;
  487.   }
  488.  
  489.   /*
  490.    * doesn't skip white space when reading characters
  491.    */
  492.  
  493.   inline ios_base& noskipws(ios_base& strm)
  494.   {
  495.     strm.unsetf(ios_base::skipws);
  496.     return strm;
  497.   }
  498.  
  499.   /*
  500.    * prints floating point and hex values in uppercase.
  501.    * e.g. 1.234E05, 0X1B
  502.    */
  503.  
  504.   inline ios_base& uppercase(ios_base& strm)
  505.   {
  506.     strm.setf(ios_base::uppercase);
  507.     return strm;
  508.   }
  509.  
  510.   /*
  511.    * uses lowercase for floating point and hex values
  512.    */
  513.  
  514.   inline ios_base& nouppercase(ios_base& strm)
  515.   {
  516.     strm.unsetf(ios_base::uppercase);
  517.     return strm;
  518.   }
  519.  
  520.   inline ios_base& internal(ios_base& strm)
  521.   {
  522.     strm.setf(ios_base::internal, ios_base::adjustfield);
  523.     return strm;
  524.   }
  525.  
  526.   /*
  527.    * does left justifying
  528.    */
  529.  
  530.   inline ios_base& left(ios_base& strm)
  531.   {
  532.     strm.setf(ios_base::left, ios_base::adjustfield);
  533.     return strm;
  534.   }
  535.  
  536.   /*
  537.    * does right justifying
  538.    */
  539.  
  540.   inline ios_base& right(ios_base& strm)
  541.   {
  542.     strm.setf(ios_base::right, ios_base::adjustfield);
  543.     return strm;
  544.   }
  545.  
  546.   /*
  547.    * prints integer values in decimal
  548.    */
  549.  
  550.   inline ios_base& dec(ios_base& strm)
  551.   {
  552.     strm.setf(ios_base::dec, ios_base::basefield);
  553.     return strm;
  554.   }
  555.  
  556.   /*
  557.    * prints integer values in hexadecimal
  558.    */
  559.  
  560.   inline ios_base& hex(ios_base& strm)
  561.   {
  562.     strm.setf(ios_base::hex, ios_base::basefield);
  563.     return strm;
  564.   }
  565.  
  566.   /*
  567.    * prints integer values in octal
  568.    */
  569.  
  570.   inline ios_base& oct(ios_base& strm)
  571.   {
  572.     strm.setf(ios_base::oct, ios_base::basefield);
  573.     return strm;
  574.   }
  575.  
  576.   /*
  577.    * generate floating point numbers in fixed-point notation
  578.    */
  579.  
  580.   inline ios_base& fixed(ios_base& strm)
  581.   {
  582.     strm.setf(ios_base::fixed, ios_base::floatfield);
  583.     return strm;
  584.   }
  585.  
  586.   /*
  587.    * generates floating-point numbers in scientific notation
  588.    */
  589.  
  590.   inline ios_base& scientific(ios_base& strm)
  591.   {
  592.     strm.setf(ios_base::scientific, ios_base::floatfield);
  593.     return strm;
  594.   }
  595.  
  596.   // end inlining
  597.  
  598. #ifndef _RWSTD_NO_NAMESPACE
  599. }
  600. #endif
  601.  
  602. #endif // __STD_IOSBASE__ 
  603.  
  604. #pragma option pop
  605. #endif /* __IOSBASE_H */
  606.