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

  1. #ifndef __IOMANIP_H
  2. #define __IOMANIP_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. #ifndef __STD_IOMANIP__
  6. #define __STD_IOMANIP__
  7.  
  8. /***************************************************************************
  9.  *
  10.  * iomanip - Declarations for the iomanip classes
  11.  *
  12.  ***************************************************************************
  13.  *
  14.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  15.  * ALL RIGHTS RESERVED
  16.  *
  17.  * The software and information contained herein are proprietary to, and
  18.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  19.  * intends to preserve as trade secrets such software and information.
  20.  * This software is furnished pursuant to a written license agreement and
  21.  * may be used, copied, transmitted, and stored only in accordance with
  22.  * the terms of such license and with the inclusion of the above copyright
  23.  * notice.  This software and information or any other copies thereof may
  24.  * not be provided or otherwise made available to any other person.
  25.  *
  26.  * Notwithstanding any other lease or license that may pertain to, or
  27.  * accompany the delivery of, this computer software and information, the
  28.  * rights of the Government regarding its use, reproduction and disclosure
  29.  * are as set forth in Section 52.227-19 of the FARS Computer
  30.  * Software-Restricted Rights clause.
  31.  * 
  32.  * Use, duplication, or disclosure by the Government is subject to
  33.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  34.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  35.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  36.  * P.O. Box 2328, Corvallis, Oregon 97339.
  37.  *
  38.  * This computer software and information is distributed with "restricted
  39.  * rights."  Use, duplication or disclosure is subject to restrictions as
  40.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  41.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  42.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  43.  * then the "Alternate III" clause applies.
  44.  *
  45.  **************************************************************************/
  46.  
  47. #include <stdcomp.h>
  48. #include <iostream> 
  49.  
  50. #ifndef _RWSTD_NO_NAMESPACE
  51. namespace std {
  52. #endif
  53.   
  54.   /*
  55.    * class smanip
  56.    */
  57.  
  58.   template<class T>
  59.   class smanip {
  60.  
  61.   public:
  62.     smanip(ios_base& (*pf)(ios_base&, T), T manarg)
  63.       : __pf(pf)
  64.       , __manarg(manarg)
  65.     { ; }
  66.       
  67.     ios_base&           (*__pf)(ios_base&, T);
  68.     T              __manarg;
  69.   protected:
  70.  
  71.   private:
  72.   };
  73.  
  74.   /*
  75.    * class smanip_fill
  76.    */
  77.  
  78.   template<class T, class traits>
  79.   class smanip_fill {
  80.  
  81.   public:
  82.     smanip_fill(basic_ios< T, traits >& (*pf)(basic_ios< T, traits >&, T), T manarg)
  83.       : __pf(pf)
  84.       , __manarg(manarg)
  85.     { ; }
  86.  
  87.     basic_ios< T, traits >&   (*__pf)(basic_ios< T, traits >&, T);
  88.     T              __manarg;
  89.   protected:
  90.  
  91.   private:
  92.   };
  93.  
  94.   /*
  95.    * global manipulators
  96.    */
  97.  
  98.   inline ios_base& rsios(ios_base& str, ios_base::fmtflags mask)
  99.   {
  100.     str.setf((ios_base::fmtflags)0, mask);
  101.     return str;
  102.   }
  103.  
  104.   inline ios_base& sios(ios_base& str, ios_base::fmtflags mask)
  105.   {
  106.     str.setf(mask);
  107.     return str;
  108.   }
  109.  
  110.   inline ios_base& sbase(ios_base& str, int base)
  111.   {
  112.     str.setf(base == 8 ? ios_base::oct :
  113.              base == 10 ? ios_base::dec :
  114.              base == 16 ? ios_base::hex :
  115.              ios_base::fmtflags(0), ios_base::basefield);
  116.  
  117.     return str;
  118.   }
  119.  
  120.   template < class charT, class traits >
  121.   inline basic_ios< charT, traits >& sfill( basic_ios< charT, traits >& str, charT c)
  122.   {
  123.     str.fill(c);
  124.     return str;
  125.   }
  126.  
  127.   inline ios_base& sprec(ios_base& str, int n)
  128.   {
  129.     str.precision(n);
  130.     return str;
  131.   }
  132.  
  133.   inline ios_base& swidth(ios_base& str, int n)
  134.   {
  135.     str.width(n);
  136.     return str;
  137.   }
  138.  
  139.   inline smanip<ios_base::fmtflags> resetiosflags(ios_base::fmtflags mask )
  140.   { return smanip<ios_base::fmtflags>(rsios, mask); }
  141.  
  142.   inline smanip<ios_base::fmtflags> setiosflags(ios_base::fmtflags mask )
  143.   { return smanip<ios_base::fmtflags>(sios, mask); }
  144.  
  145.   inline smanip<int> setbase(int base)
  146.   { return smanip<int>(sbase, base); }
  147.  
  148.   template < class charT >
  149.   inline smanip_fill<charT, char_traits<charT> > setfill( charT c)
  150.   { return smanip_fill<charT, char_traits<charT> >((basic_ios< charT, char_traits<charT> >& (*)(basic_ios< charT, char_traits<charT> >&, charT))sfill, c); 
  151.   }
  152.  
  153.   inline smanip<int> setprecision(int n)
  154.   { return smanip<int>(sprec, n); }
  155.  
  156.   inline smanip<int> setw(int n)
  157.   { return smanip<int>(swidth, n); }
  158.  
  159.   template<class charT, class traits, class T>
  160.   inline basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, const smanip<T>& a)
  161.   {
  162. #ifndef _RWSTD_NO_EXCEPTIONS
  163.     try {
  164.       (*a.__pf)(is, a.__manarg);
  165.     }
  166.     catch(...) {
  167.       is.setstate(ios_base::failbit);
  168.     }
  169. #else
  170.     (*a.__pf)(is, a.__manarg);
  171. #endif // _RWSTD_NO_EXCEPTIONS
  172.   
  173.     return is;
  174.   }
  175.  
  176.   template<class charT, class traits, class T>
  177.   inline basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const smanip<T>& a)
  178.   {
  179. #ifndef _RWSTD_NO_EXCEPTIONS
  180.     try {
  181.       (*a.__pf)(os, a.__manarg);
  182.     }
  183.     catch(...) {
  184.       os.setstate(ios_base::failbit);
  185.     }
  186. #else
  187.     (*a.__pf)(os, a.__manarg);
  188. #endif // _RWSTD_NO_EXCEPTIONS
  189.   
  190.     return os;
  191.   }
  192.  
  193.   template<class T, class traits>
  194.   inline basic_istream<T, traits>& operator>>(basic_istream<T, traits>& is, const smanip_fill<T, traits>& a)
  195.   {
  196. #ifndef _RWSTD_NO_EXCEPTIONS
  197.     try {
  198.       (*a.__pf)(is, a.__manarg);
  199.     }
  200.     catch(...) {
  201.       is.setstate(ios_base::failbit);
  202.     }
  203. #else
  204.     (*a.__pf)(is, a.__manarg);
  205. #endif // _RWSTD_NO_EXCEPTIONS
  206.   
  207.     return is;
  208.   }
  209.  
  210.   template<class T, class traits>
  211.   inline basic_ostream<T, traits>& operator<<(basic_ostream<T, traits>& os, const smanip_fill<T, traits>& a)
  212.   {
  213. #ifndef _RWSTD_NO_EXCEPTIONS
  214.     try {
  215.       (*a.__pf)(os, a.__manarg);
  216.     }
  217.     catch(...) {
  218.       os.setstate(ios_base ::failbit);
  219.     }
  220. #else
  221.     (*a.__pf)(os, a.__manarg);
  222. #endif // _RWSTD_NO_EXCEPTIONS
  223.   
  224.     return os;
  225.   }
  226. #ifndef _RWSTD_NO_NAMESPACE
  227. }
  228. #endif
  229.  
  230. #endif // __STD__IOMANIP__ 
  231. #ifndef __USING_STD_NAMES__
  232.   using namespace std;
  233. #endif
  234. #pragma option pop
  235. #endif /* __IOMANIP_H */
  236.