1 // Uncomment this only is you are REALLY sure templates work on your system 2 //#define WANT_TEMPLATES 3 4 #ifndef ioformat_h 5 #define ioformat_h 6 7 //Convert to string 10/05/01 8 9 #include <iostream> 10 #include <string> 11 12 using std::ostream; 13 using std::string; 14 15 #if (defined(__GNUC__) && __GNUC__ >= 3) 16 typedef std::ios_base::fmtflags opt_mode; 17 #else 18 typedef std::ios::fmtflags opt_mode; 19 #endif 20 21 22 namespace OPTPP { 23 24 class oformatstate 25 { 26 public: 27 oformatstate(ostream& ut); 28 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) ) 29 oformatstate (char code, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed); 30 #else 31 oformatstate (char code, int w=0, int p=0, char c=' ', opt_mode f=0); 32 #endif 33 friend ostream& operator << (ostream& ut, oformatstate const& fmt); 34 friend ostream& operator >> (ostream& ut, oformatstate& fmt); 35 36 private: 37 int owidth; 38 int oprecision; 39 char ofill; 40 opt_mode oflags; 41 }; 42 43 string format(double val, oformatstate const& fmt); 44 string format(int val, oformatstate const& fmt); 45 46 inline string 47 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) ) 48 d(int val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed) 49 #else 50 d(int val, int w=0, int p=0, char c=' ', opt_mode f=0) 51 #endif 52 { 53 oformatstate fmt('d', w, p, c, f); 54 return format(val, fmt); 55 } 56 inline string 57 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) ) 58 e(double val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed) 59 #else 60 e(double val, int w=0, int p=0, char c=' ', opt_mode f=0) 61 #endif 62 { 63 oformatstate fmt('e', w, p, c, f); 64 return format(val, fmt); 65 } 66 inline string 67 #if ( defined(__GNUC__) && __GNUC__ >= 3 || defined (__ICC) ) 68 f(double val, int w=0, int p=0, char c=' ', opt_mode f = std::ios_base::fixed) 69 #else 70 f(double val, int w=0, int p=0, char c=' ', opt_mode f=0) 71 #endif 72 { 73 oformatstate fmt('f', w, p, c, f); 74 return format(val, fmt); 75 } 76 77 } // namespace OPTPP 78 79 #endif 80