home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / iomanip.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  5.8 KB  |  226 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.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  15.  *
  16.  * This computer software is owned by Rogue Wave Software, Inc. and is
  17.  * protected by U.S. copyright laws and other laws and by international
  18.  * treaties.  This computer software is furnished by Rogue Wave Software,
  19.  * Inc. pursuant to a written license agreement and may be used, copied,
  20.  * transmitted, and stored only in accordance with the terms of such
  21.  * license and with the inclusion of the above copyright notice.  This
  22.  * computer software or any other copies thereof may not be provided or
  23.  * otherwise made available to any other person.
  24.  *
  25.  * U.S. Government Restricted Rights.  This computer software is provided
  26.  * with Restricted Rights.  Use, duplication, or disclosure by the
  27.  * Government is subject to restrictions as set forth in subparagraph (c)
  28.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  29.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  30.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  31.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  32.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  33.  *
  34.  **************************************************************************/
  35.  
  36. #include <stdcomp.h>
  37. #include <iostream> 
  38.  
  39. #ifndef _RWSTD_NO_NAMESPACE
  40. namespace std {
  41. #endif
  42.   
  43.   /*
  44.    * class smanip
  45.    */
  46.  
  47.   template<class T>
  48.   class smanip {
  49.  
  50.   public:
  51.     smanip(ios_base& (*pf)(ios_base&, T), T manarg)
  52.       : __pf(pf)
  53.       , __manarg(manarg)
  54.     { ; }
  55.       
  56.     ios_base&           (*__pf)(ios_base&, T);
  57.     T              __manarg;
  58.   protected:
  59.  
  60.   private:
  61.   };
  62.  
  63.   /*
  64.    * class smanip_fill
  65.    */
  66.  
  67.   template<class T, class traits>
  68.   class smanip_fill {
  69.  
  70.   public:
  71.     smanip_fill(basic_ios< T, traits >& (*pf)(basic_ios< T, traits >&, T), T manarg)
  72.       : __pf(pf)
  73.       , __manarg(manarg)
  74.     { ; }
  75.  
  76.     basic_ios< T, traits >&   (*__pf)(basic_ios< T, traits >&, T);
  77.     T              __manarg;
  78.   protected:
  79.  
  80.   private:
  81.   };
  82.  
  83.   /*
  84.    * global manipulators
  85.    */
  86.  
  87.   inline ios_base& rsios(ios_base& str, ios_base::fmtflags mask)
  88.   {
  89.     str.setf((ios_base::fmtflags)0, mask);
  90.     return str;
  91.   }
  92.  
  93.   inline ios_base& sios(ios_base& str, ios_base::fmtflags mask)
  94.   {
  95.     str.setf(mask);
  96.     return str;
  97.   }
  98.  
  99.   inline ios_base& sbase(ios_base& str, int base)
  100.   {
  101.     str.setf(base == 8 ? ios_base::oct :
  102.              base == 10 ? ios_base::dec :
  103.              base == 16 ? ios_base::hex :
  104.              ios_base::fmtflags(0), ios_base::basefield);
  105.  
  106.     return str;
  107.   }
  108.  
  109.   template < class charT, class traits >
  110.   inline basic_ios< charT, traits >& sfill( basic_ios< charT, traits >& str, charT c)
  111.   {
  112.     str.fill(c);
  113.     return str;
  114.   }
  115.  
  116.   inline ios_base& sprec(ios_base& str, int n)
  117.   {
  118.     str.precision(n);
  119.     return str;
  120.   }
  121.  
  122.   inline ios_base& swidth(ios_base& str, int n)
  123.   {
  124.     str.width(n);
  125.     return str;
  126.   }
  127.  
  128.   inline smanip<ios_base::fmtflags> resetiosflags(ios_base::fmtflags mask )
  129.   { return smanip<ios_base::fmtflags>(rsios, mask); }
  130.  
  131.   inline smanip<ios_base::fmtflags> setiosflags(ios_base::fmtflags mask )
  132.   { return smanip<ios_base::fmtflags>(sios, mask); }
  133.  
  134.   inline smanip<int> setbase(int base)
  135.   { return smanip<int>(sbase, base); }
  136.  
  137.   template < class charT >
  138.   inline smanip_fill<charT, char_traits<charT> > setfill( charT c)
  139.   { return smanip_fill<charT, char_traits<charT> >((basic_ios< charT, char_traits<charT> >& (*)(basic_ios< charT, char_traits<charT> >&, charT))sfill, c); 
  140.   }
  141.  
  142.   inline smanip<int> setprecision(int n)
  143.   { return smanip<int>(sprec, n); }
  144.  
  145.   inline smanip<int> setw(int n)
  146.   { return smanip<int>(swidth, n); }
  147.  
  148.   template<class charT, class traits, class T>
  149.   inline basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, const smanip<T>& a)
  150.   {
  151. #ifndef _RWSTD_NO_EXCEPTIONS
  152.     try {
  153.       (*a.__pf)(is, a.__manarg);
  154.     }
  155.     catch(...) {
  156.       is.setstate(ios_base::failbit);
  157.     }
  158. #else
  159.     (*a.__pf)(is, a.__manarg);
  160. #endif // _RWSTD_NO_EXCEPTIONS
  161.   
  162.     return is;
  163.   }
  164.  
  165.   template<class charT, class traits, class T>
  166.   inline basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const smanip<T>& a)
  167.   {
  168. #ifndef _RWSTD_NO_EXCEPTIONS
  169.     try {
  170.       (*a.__pf)(os, a.__manarg);
  171.     }
  172.     catch(...) {
  173.       os.setstate(ios_base::failbit);
  174.     }
  175. #else
  176.     (*a.__pf)(os, a.__manarg);
  177. #endif // _RWSTD_NO_EXCEPTIONS
  178.   
  179.     return os;
  180.   }
  181.  
  182.   template<class T, class traits>
  183.   inline basic_istream<T, traits>& operator>>(basic_istream<T, traits>& is, const smanip_fill<T, traits>& a)
  184.   {
  185. #ifndef _RWSTD_NO_EXCEPTIONS
  186.     try {
  187.       (*a.__pf)(is, a.__manarg);
  188.     }
  189.     catch(...) {
  190.       is.setstate(ios_base::failbit);
  191.     }
  192. #else
  193.     (*a.__pf)(is, a.__manarg);
  194. #endif // _RWSTD_NO_EXCEPTIONS
  195.   
  196.     return is;
  197.   }
  198.  
  199.   template<class T, class traits>
  200.   inline basic_ostream<T, traits>& operator<<(basic_ostream<T, traits>& os, const smanip_fill<T, traits>& a)
  201.   {
  202. #ifndef _RWSTD_NO_EXCEPTIONS
  203.     try {
  204.       (*a.__pf)(os, a.__manarg);
  205.     }
  206.     catch(...) {
  207.       os.setstate(ios_base ::failbit);
  208.     }
  209. #else
  210.     (*a.__pf)(os, a.__manarg);
  211. #endif // _RWSTD_NO_EXCEPTIONS
  212.   
  213.     return os;
  214.   }
  215. #ifndef _RWSTD_NO_NAMESPACE
  216. }
  217. #endif
  218.  
  219. #endif // __STD__IOMANIP__ 
  220. #ifndef __USING_STD_NAMES__
  221.   using namespace std;
  222. #endif
  223.  
  224. #pragma option pop
  225. #endif /* __IOMANIP_H */
  226.