MsgFormat.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef MSGFORMAT_H
00011 #define MSGFORMAT_H
00012 #ifndef IOSTREAM
00013 #include <iostream>
00014 #define IOSTREAM
00015 #endif
00016 #ifndef IOMANIP
00017 #include <iomanip>
00018 #define IOMANIP
00019 #endif
00020 #ifndef MSGBOUNDFORMAT_H
00021 #include <MsgBoundFormat.h>
00022 #endif
00023
00024 using namespace std;
00025
00026
00027 ostream& operator<<(ostream&, const MsgBoundFormat&);
00028
00029
00030
00031 class MsgFormat
00032 {
00033 friend ostream& operator<<(ostream&, const MsgBoundFormat&);
00034 public:
00035
00036 #if __GNUC__ == 3 && __GNUC_MINOR__ >= 4
00037 typedef ios_base::fmtflags fmtflags;
00038 #elif __GNUC__ == 4
00039 typedef ios_base::fmtflags fmtflags;
00040 #else
00041 #ifdef _CPP_BITS_IOSBASE_H
00042 typedef ios_base::fmtflags fmtflags;
00043 #else
00044 typedef int fmtflags;
00045 #endif
00046 #endif
00047
00048 MsgFormat(int p=6) :
00049 prc(p), wdt(0), fmt(static_cast<fmtflags>(0)), flc(' ') { }
00050 MsgFormat(int p, int w) :
00051 prc(p), wdt(w), fmt(static_cast<fmtflags>(0)), flc(' ') { }
00052 MsgFormat(const char* f);
00053
00054 MsgBoundFormat operator()(double d) const {
00055 return MsgBoundFormat(*this,d);
00056 }
00057
00058 MsgFormat& fixed() { fmt=ios::fixed; return *this;}
00059 MsgFormat& general() { fmt=ios::dec; return *this;}
00060 MsgFormat& hex() { fmt=ios::hex; return *this;}
00061 MsgFormat& oct() { fmt=ios::oct; return *this;}
00062 MsgFormat& scientific() { fmt=ios::scientific; return *this;}
00063
00064 MsgFormat& precision(int p) { prc=p; return *this;}
00065 MsgFormat& width(int w) { wdt=w; return *this;}
00066
00067 MsgFormat& set_fill(char c) { flc = c; return *this; }
00068
00069 MsgFormat& left_justify(int b=1) {
00070 if (b) { fmt |= ios::left; fmt &= (~ios::right); }
00071 else fmt &= ~ios::left;
00072 return *this;
00073 }
00074 MsgFormat& right_justify(int b=1) {
00075 if (b) { fmt |= ios::right; fmt &= (~ios::left); }
00076 else fmt &= ~ios::right;
00077 return *this;
00078 }
00079 MsgFormat& show_base(int b=1) {
00080 if (b) fmt |= ios::showbase;
00081 else fmt &= ~ios::showbase;
00082 return *this;
00083 }
00084 MsgFormat& plus(int b=1) {
00085 if (b) fmt |= ios::showpos;
00086 else fmt &= ~ios::showpos;
00087 return *this;
00088 }
00089 MsgFormat& trailing_zeros(int b=1) {
00090 if (b) fmt |= ios::showpoint;
00091 else fmt &= ~ios::showpoint;
00092 return *this;
00093 }
00094
00095 private:
00096 int prc;
00097 int wdt;
00098 fmtflags fmt;
00099 char flc;
00100 };
00101
00102 #endif // MSGFORMAT_H