#include <MsgFormat.h>
Public Types | |
| typedef int | fmtflags |
Public Member Functions | |
| MsgFormat (int p=6) | |
| MsgFormat (int p, int w) | |
| MsgFormat (const char *f) | |
| MsgBoundFormat | operator() (double d) const |
| MsgFormat & | fixed () |
| MsgFormat & | general () |
| MsgFormat & | hex () |
| MsgFormat & | oct () |
| MsgFormat & | scientific () |
| MsgFormat & | precision (int p) |
| MsgFormat & | width (int w) |
| MsgFormat & | set_fill (char c) |
| MsgFormat & | left_justify (int b=1) |
| MsgFormat & | right_justify (int b=1) |
| MsgFormat & | show_base (int b=1) |
| MsgFormat & | plus (int b=1) |
| MsgFormat & | trailing_zeros (int b=1) |
Private Attributes | |
| int | prc |
| int | wdt |
| fmtflags | fmt |
| char | flc |
Friends | |
| ostream & | operator<< (ostream &, const MsgBoundFormat &) |
|
|
Definition at line 44 of file MsgFormat.h. |
|
|
Definition at line 48 of file MsgFormat.h.
|
|
||||||||||||
|
Definition at line 50 of file MsgFormat.h.
|
|
|
Definition at line 54 of file MsgFormat.cxx. References flc, fmt, prc, and wdt. 00055 {
00056 //======================================================================
00057 // Purpose: Create a message format using given formatting flags
00058 //
00059 // Inputs: f - format string a la printf (see man format)
00060 //======================================================================
00061 int i, j=0, k=0;
00062 char c, n[2][16];
00063 prc = 6;
00064 wdt = 0;
00065 fmt = static_cast<fmtflags>(0);
00066 flc = ' ';
00067 for (i=0; f[i] != '\0'; ++i) {
00068 switch(c = f[i]) {
00069 case '-': fmt |= ios::left; break;
00070 case '+': fmt |= ios::showpos; break;
00071 case ' ': break;
00072 case 'O': flc = '0'; fmt |= ios::left; break;
00073 case 'd': break;
00074 case 'u': break;
00075 case 'i': break;
00076 case 'o': fmt |= ios::oct; fmt |= ios::showbase; break;
00077 case 'x': fmt |= ios::hex; fmt |= ios::showbase; break;
00078 case 'X': fmt |= ios::hex; fmt |= ios::showbase; break;
00079 case 'f': fmt |= ios::fixed; break;
00080 case 'e': fmt |= ios::scientific; break;
00081 case 'E': fmt |= ios::scientific; break;
00082 case 'g': break;
00083 case 'G': break;
00084 default:
00085 if (c == '.') {
00086 n[j][k] = '\0';
00087 ++j;
00088 k = 0;
00089 }
00090 else {
00091 if (c >= '0' && c <= '9') n[j][k++] = c;
00092 }
00093 break;
00094 }
00095 }
00096 if (k!=0 || j!=0) {
00097 if (j==0) n[0][k] = '\0';
00098 wdt = atoi(n[0]);
00099 }
00100 if (j>0) {
00101 n[1][k] = '\0';
00102 prc = atoi(n[1]);
00103 }
00104 }
|
|
|
Definition at line 58 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00058 { fmt=ios::fixed; return *this;}
|
|
|
Definition at line 59 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00059 { fmt=ios::dec; return *this;}
|
|
|
Definition at line 60 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00060 { fmt=ios::hex; return *this;}
|
|
|
Definition at line 69 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00069 {
00070 if (b) { fmt |= ios::left; fmt &= (~ios::right); }
00071 else fmt &= ~ios::left;
00072 return *this;
00073 }
|
|
|
Definition at line 61 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00061 { fmt=ios::oct; return *this;}
|
|
|
Definition at line 54 of file MsgFormat.h. 00054 {
00055 return MsgBoundFormat(*this,d);
00056 }
|
|
|
Definition at line 84 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00084 {
00085 if (b) fmt |= ios::showpos;
00086 else fmt &= ~ios::showpos;
00087 return *this;
00088 }
|
|
|
Definition at line 64 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00064 { prc=p; return *this;}
|
|
|
Definition at line 74 of file MsgFormat.h. 00074 {
00075 if (b) { fmt |= ios::right; fmt &= (~ios::left); }
00076 else fmt &= ~ios::right;
00077 return *this;
00078 }
|
|
|
Definition at line 62 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00062 { fmt=ios::scientific; return *this;}
|
|
|
Definition at line 67 of file MsgFormat.h. 00067 { flc = c; return *this; }
|
|
|
Definition at line 79 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00079 {
00080 if (b) fmt |= ios::showbase;
00081 else fmt &= ~ios::showbase;
00082 return *this;
00083 }
|
|
|
Definition at line 89 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00089 {
00090 if (b) fmt |= ios::showpoint;
00091 else fmt &= ~ios::showpoint;
00092 return *this;
00093 }
|
|
|
Definition at line 65 of file MsgFormat.h. Referenced by MsgFormatValidate::TestManipulators(). 00065 { wdt=w; return *this;}
|
|
||||||||||||
|
Definition at line 20 of file MsgFormat.cxx. 00021 {
00022 //======================================================================
00023 // Purpose: Print a value with the given format
00024 //
00025 // Inputs: os - the stream to print to
00026 // bf - the value and format to print
00027 //
00028 // Returns: the stream printed to
00029 //======================================================================
00030 int p = os.precision();
00031 MsgFormat::fmtflags f =
00032 os.setf(bf.f.fmt,static_cast<MsgFormat::fmtflags>(0xFFFF));
00033 char c = os.fill();
00034
00035 if (bf.f.flc != c) os.fill(bf.f.flc);
00036
00037 if ((bf.f.fmt&ios::hex) || (bf.f.fmt&ios::oct)) {
00038 os.setf(bf.f.fmt, ios::basefield);
00039 os << setprecision(bf.f.prc) << setw(bf.f.wdt) << (int)bf.val;
00040 }
00041 else {
00042 os << setprecision(bf.f.prc) << setw(bf.f.wdt) << bf.val;
00043 }
00044
00045 // Reset stream
00046 if (c != os.fill()) os.fill(c);
00047 os.precision(p);
00048 os.flags(f);
00049 return os;
00050 }
|
|
|
Definition at line 99 of file MsgFormat.h. Referenced by MsgFormat(), and operator<<(). |
|
|
Definition at line 98 of file MsgFormat.h. Referenced by MsgFormat(), and operator<<(). |
|
|
Definition at line 96 of file MsgFormat.h. Referenced by MsgFormat(), and operator<<(). |
|
|
Definition at line 97 of file MsgFormat.h. Referenced by MsgFormat(), and operator<<(). |
1.3.9.1