CMS 3D CMS Logo

StringFormat.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_STRING_FORMAT_H
00002 # define CLASSLIB_STRING_FORMAT_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/sysapi/system.h"
00007 # include <iosfwd>
00008 # include <string>
00009 # include <utility>
00010 # include <list>
00011 
00012 namespace lat {
00013 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00014 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00015 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00016 
00017 class StringFormat;
00018 
00019 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00020 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00021 
00022 std::ostream &
00023 operator<< (std::ostream &out, const StringFormat &x);
00024 
00025 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00026 
00027 class StringFormat
00028 {
00029 public:
00030     explicit StringFormat (const std::string &pattern);
00031     // implicit copy constructor
00032     // implicit assignment operator
00033     // implicit destructor
00034 
00035     const std::string & value (void) const;
00036                 operator const std::string & (void) const;
00037 
00038     StringFormat        arg (long               val,
00039                              int                fieldwidth = 0,
00040                              int                base = 10) const;
00041     StringFormat        arg (unsigned long      val,
00042                              int                fieldwidth = 0,
00043                              int                base = 10) const;
00044     StringFormat        arg (int                val,
00045                              int                fieldwidth = 0,
00046                              int                base = 10) const;
00047     StringFormat        arg (unsigned int       val,
00048                              int                fieldwidth = 0,
00049                              int                base = 10) const;
00050     StringFormat        arg (short              val,
00051                              int                fieldwidth = 0,
00052                              int                base = 10) const;
00053     StringFormat        arg (unsigned short     val,
00054                              int                fieldwidth = 0,
00055                              int                base = 10) const;
00056     StringFormat        arg (char               val, int fieldwidth = 0) const;
00057     StringFormat        arg (unsigned char      val, int fieldwidth = 0) const;
00058     StringFormat        arg (signed char        val, int fieldwidth = 0) const;
00059     StringFormat        arg (const std::string &val, int fieldwidth = 0) const;
00060     StringFormat        arg (double             val,
00061                              int                fieldwidth = 0,
00062                              char               format = 'g',
00063                              int                precision = -1) const;
00064 
00065     StringFormat        rescan (void) const;
00066 
00067 private:
00068     typedef std::list< std::pair<size_t, size_t> > ArgList;
00069 
00070     StringFormat (void);
00071     StringFormat (const std::string &value, const std::string &replacement,
00072                   size_t offset, size_t len,
00073                   ArgList::const_iterator first, ArgList::const_iterator last);
00074 
00075     void                dorescan (void);
00076     StringFormat        doarg (const std::string &replacement) const;
00077     static bool         nextarg (const std::string &in,
00078                                  size_t &offset,
00079                                  size_t &len);
00080 
00081     static std::string  pad (const char *buf, size_t len, int fieldwidth);
00082 
00083     static char *       format (char *next, unsigned long val, int base);
00084     static std::string  format (long val, int fieldwidth, int base);
00085     static std::string  format (unsigned long val, int fieldwidth, int base);
00086     static std::string  format (double val, int fieldwidth, char fmt,
00087                                 int precision);
00088 
00089     std::string         m_value;
00090     ArgList             m_args;
00091 };
00092 
00093 
00094 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00095 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00096 
00097 } // namespace lat
00098 #endif // CLASSLIB_STRING_FORMAT_H

Generated on Tue Jun 9 17:38:55 2009 for CMSSW by  doxygen 1.5.4