MsgFormat Class Reference

#include <MsgFormat.h>

List of all members.

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
MsgFormatfixed ()
MsgFormatgeneral ()
MsgFormathex ()
MsgFormatoct ()
MsgFormatscientific ()
MsgFormatprecision (int p)
MsgFormatwidth (int w)
MsgFormatset_fill (char c)
MsgFormatleft_justify (int b=1)
MsgFormatright_justify (int b=1)
MsgFormatshow_base (int b=1)
MsgFormatplus (int b=1)
MsgFormattrailing_zeros (int b=1)

Private Attributes

int prc
int wdt
fmtflags fmt
char flc

Friends

ostream & operator<< (ostream &, const MsgBoundFormat &)

Detailed Description

Definition at line 31 of file MsgFormat.h.


Member Typedef Documentation

typedef int MsgFormat::fmtflags

Definition at line 44 of file MsgFormat.h.


Constructor & Destructor Documentation

MsgFormat::MsgFormat ( int  p = 6  )  [inline]

Definition at line 48 of file MsgFormat.h.

00048                      : 
00049     prc(p), wdt(0), fmt(static_cast<fmtflags>(0)), flc(' ') { }

MsgFormat::MsgFormat ( int  p,
int  w 
) [inline]

Definition at line 50 of file MsgFormat.h.

00050                           : 
00051     prc(p), wdt(w), fmt(static_cast<fmtflags>(0)), flc(' ') { }

MsgFormat::MsgFormat ( const char *  f  ) 

Definition at line 54 of file MsgFormat.cxx.

References flc, fmt, n, 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 }


Member Function Documentation

MsgFormat& MsgFormat::fixed (  )  [inline]

Definition at line 58 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00058 { fmt=ios::fixed;      return *this;}

MsgFormat& MsgFormat::general (  )  [inline]

Definition at line 59 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00059 { fmt=ios::dec;        return *this;}

MsgFormat& MsgFormat::hex (  )  [inline]

Definition at line 60 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00060 { fmt=ios::hex;        return *this;}  

MsgFormat& MsgFormat::left_justify ( int  b = 1  )  [inline]

Definition at line 69 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00069                                    {
00070     if (b) { fmt |= ios::left; fmt &= (~ios::right); }
00071     else fmt &= ~ios::left;
00072     return *this;
00073   }

MsgFormat& MsgFormat::oct (  )  [inline]

Definition at line 61 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00061 { fmt=ios::oct;        return *this;}

MsgBoundFormat MsgFormat::operator() ( double  d  )  const [inline]

Definition at line 54 of file MsgFormat.h.

00054                                             { 
00055     return MsgBoundFormat(*this,d); 
00056   }

MsgFormat& MsgFormat::plus ( int  b = 1  )  [inline]

Definition at line 84 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00084                            {
00085     if (b) fmt |= ios::showpos; 
00086     else fmt &= ~ios::showpos; 
00087     return *this;
00088   }

MsgFormat& MsgFormat::precision ( int  p  )  [inline]

Definition at line 64 of file MsgFormat.h.

References prc.

Referenced by MsgFormatValidate::TestManipulators().

00064 { prc=p; return *this;}

MsgFormat& MsgFormat::right_justify ( int  b = 1  )  [inline]

Definition at line 74 of file MsgFormat.h.

References fmt.

00074                                     {
00075     if (b) { fmt |= ios::right; fmt &= (~ios::left); }
00076     else fmt &= ~ios::right;
00077     return *this;
00078   }

MsgFormat& MsgFormat::scientific (  )  [inline]

Definition at line 62 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00062 { fmt=ios::scientific; return *this;}

MsgFormat& MsgFormat::set_fill ( char  c  )  [inline]

Definition at line 67 of file MsgFormat.h.

References flc.

00067 { flc = c; return *this; }

MsgFormat& MsgFormat::show_base ( int  b = 1  )  [inline]

Definition at line 79 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00079                                 {
00080     if (b) fmt |= ios::showbase; 
00081     else fmt &= ~ios::showbase; 
00082     return *this;
00083   }

MsgFormat& MsgFormat::trailing_zeros ( int  b = 1  )  [inline]

Definition at line 89 of file MsgFormat.h.

References fmt.

Referenced by MsgFormatValidate::TestManipulators().

00089                                      {
00090     if (b) fmt |= ios::showpoint; 
00091     else fmt &= ~ios::showpoint;
00092     return *this;
00093   }

MsgFormat& MsgFormat::width ( int  w  )  [inline]

Definition at line 65 of file MsgFormat.h.

References wdt.

Referenced by MsgFormatValidate::TestManipulators().

00065 { wdt=w; return *this;}


Friends And Related Function Documentation

ostream& operator<< ( ostream &  ,
const MsgBoundFormat  
) [friend]

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 }


Member Data Documentation

char MsgFormat::flc [private]

Definition at line 99 of file MsgFormat.h.

Referenced by MsgFormat(), operator<<(), and set_fill().

int MsgFormat::prc [private]

Definition at line 96 of file MsgFormat.h.

Referenced by MsgFormat(), operator<<(), and precision().

int MsgFormat::wdt [private]

Definition at line 97 of file MsgFormat.h.

Referenced by MsgFormat(), operator<<(), and width().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1