ioformat.h

00001 // Uncomment this only is you are REALLY sure templates work on your system
00002 //#define WANT_TEMPLATES  
00003 
00004 #ifndef ioformat_h
00005 #define ioformat_h
00006 
00007 //Convert to string 10/05/01
00008 
00009 #include <iostream>
00010 #include <string>
00011 
00012 using std::ostream;
00013 using std::string;
00014 
00015 #if (defined(__GNUC__) && __GNUC__ >= 3)
00016 typedef std::ios_base::fmtflags   opt_mode;
00017 #else
00018 typedef std::ios::fmtflags opt_mode;
00019 #endif
00020 
00021 
00022 namespace OPTPP {
00023 
00024 class oformatstate
00025 {
00026 public:
00027   oformatstate(ostream& ut);
00028 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) )
00029   oformatstate (char code, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed);
00030 #else
00031   oformatstate (char code, int w=0, int p=0, char c=' ', opt_mode f=0);
00032 #endif
00033   friend ostream& operator << (ostream& ut, oformatstate const& fmt);
00034   friend ostream& operator >> (ostream& ut, oformatstate& fmt);
00035   
00036 private:
00037   int owidth;
00038   int oprecision;
00039   char ofill;
00040   opt_mode oflags;
00041 };
00042 
00043 string format(double val, oformatstate const& fmt);
00044 string format(int    val, oformatstate const& fmt);
00045 
00046 inline string
00047 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) )
00048 d(int val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed)
00049 #else
00050 d(int val, int w=0, int p=0, char c=' ', opt_mode f=0)
00051 #endif
00052 {
00053   oformatstate fmt('d', w, p, c, f);
00054   return format(val, fmt);
00055 }
00056 inline string
00057 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) )
00058 e(double val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed)
00059 #else
00060 e(double val, int w=0, int p=0, char c=' ', opt_mode f=0)
00061 #endif
00062 {
00063   oformatstate fmt('e', w, p, c, f);
00064   return format(val, fmt);
00065 }
00066 inline string
00067 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) )
00068 f(double val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed)
00069 #else
00070 f(double val, int w=0, int p=0, char c=' ', opt_mode f=0)
00071 #endif
00072 {
00073   oformatstate fmt('f', w, p, c, f);
00074   return format(val, fmt);
00075 }
00076 
00077 } // namespace OPTPP
00078 
00079 #endif
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3