00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #ifndef OW_FORMAT_HPP
00036 #define OW_FORMAT_HPP
00037 #include "OW_config.h"
00038 #include <iosfwd>
00039 #include "OW_StringStream.hpp"
00040 #include "OW_String.hpp"
00041
00042 namespace OW_NAMESPACE
00043 {
00044
00045
00046 class OW_COMMON_API Format
00047 {
00048 public:
00049
00050 operator String() const;
00051 String toString() const;
00052 const char* c_str() const;
00053
00054 template<typename A>
00055 Format(const char* ca, const A& a);
00056 template<typename A, typename B>
00057 Format(const char* ca, const A& a, const B& b);
00058 template<typename A, typename B, typename C>
00059 Format(const char* ca, const A& a, const B& b, const C& c);
00060 template<typename A, typename B, typename C, typename D>
00061 Format(const char* ca, const A& a, const B& b, const C& c, const D& d);
00062 template<typename A, typename B, typename C, typename D, typename E>
00063 Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e);
00064 template<typename A, typename B, typename C, typename D, typename E, typename F>
00065 Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f);
00066 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G>
00067 Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g);
00068 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H>
00069 Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h);
00070 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I>
00071 Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h, const I& i);
00072
00073 Format(const char* ca, const String& a);
00074 Format(const char* ca, const String& a, const String& b);
00075 Format(const char* ca, const String& a, const String& b, const String& c);
00076 private:
00077 OStringStream oss;
00078 char process(String& f, char c0);
00079 template<typename T> void put(const T& t);
00080
00081 void put (const String& t);
00082 void put (char t);
00083 void put (unsigned char t);
00084 void put (short t);
00085 void put (unsigned short t);
00086 void put (int t);
00087 void put (unsigned int t);
00088 void put (long t);
00089 void put (unsigned long t);
00090 void put (long long t);
00091 void put (unsigned long long t);
00092 public:
00093 friend OW_COMMON_API std::ostream& operator<<(std::ostream& os, const Format& f);
00094 };
00095
00096 template<typename T>
00097 void Format::put(const T& t)
00098 {
00099 if (!oss.good())
00100 return;
00101 oss << t;
00102 }
00103
00104 template<typename A>
00105 Format::Format(const char* ca, const A& a) : oss()
00106 {
00107 String fmt(ca);
00108 while (!fmt.empty())
00109 {
00110 switch (process(fmt, '1'))
00111 {
00112 case '1': put(a); break;
00113 }
00114 }
00115 }
00116 template<typename A, typename B>
00117 Format::Format(const char* ca, const A& a, const B& b) : oss()
00118 {
00119 String fmt(ca);
00120 while (!fmt.empty())
00121 {
00122 switch (process(fmt, '2'))
00123 {
00124 case '1': put(a); break;
00125 case '2': put(b); break;
00126 }
00127 }
00128 }
00129 template<typename A, typename B, typename C>
00130 Format::Format(const char* ca, const A& a, const B& b, const C& c) : oss()
00131 {
00132 String fmt(ca);
00133 while (!fmt.empty())
00134 {
00135 switch (process(fmt, '3'))
00136 {
00137 case '1': put(a); break;
00138 case '2': put(b); break;
00139 case '3': put(c); break;
00140 }
00141 }
00142 }
00143 template<typename A, typename B, typename C, typename D>
00144 Format::Format(const char* ca, const A& a, const B& b, const C& c, const D& d) : oss()
00145 {
00146 String fmt(ca);
00147 while (!fmt.empty())
00148 {
00149 switch (process(fmt, '4'))
00150 {
00151 case '1': put(a); break;
00152 case '2': put(b); break;
00153 case '3': put(c); break;
00154 case '4': put(d); break;
00155 }
00156 }
00157 }
00158 template<typename A, typename B, typename C, typename D, typename E>
00159 Format:: Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e) : oss()
00160 {
00161 String fmt(ca);
00162 while (!fmt.empty())
00163 {
00164 switch (process(fmt, '5'))
00165 {
00166 case '1': put(a); break;
00167 case '2': put(b); break;
00168 case '3': put(c); break;
00169 case '4': put(d); break;
00170 case '5': put(e); break;
00171 }
00172 }
00173 }
00174 template<typename A, typename B, typename C, typename D, typename E, typename F>
00175 Format::Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f) : oss()
00176 {
00177 String fmt(ca);
00178 while (!fmt.empty())
00179 {
00180 switch (process(fmt, '6'))
00181 {
00182 case '1': put(a); break;
00183 case '2': put(b); break;
00184 case '3': put(c); break;
00185 case '4': put(d); break;
00186 case '5': put(e); break;
00187 case '6': put(f); break;
00188 }
00189 }
00190 }
00191 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G>
00192 Format::Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g) : oss()
00193 {
00194 String fmt(ca);
00195 while (!fmt.empty())
00196 {
00197 switch (process(fmt, '7'))
00198 {
00199 case '1': put(a); break;
00200 case '2': put(b); break;
00201 case '3': put(c); break;
00202 case '4': put(d); break;
00203 case '5': put(e); break;
00204 case '6': put(f); break;
00205 case '7': put(g); break;
00206 }
00207 }
00208 }
00209 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H>
00210 Format::Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h) : oss()
00211 {
00212 String fmt(ca);
00213 while (!fmt.empty())
00214 {
00215 switch (process(fmt, '8'))
00216 {
00217 case '1': put(a); break;
00218 case '2': put(b); break;
00219 case '3': put(c); break;
00220 case '4': put(d); break;
00221 case '5': put(e); break;
00222 case '6': put(f); break;
00223 case '7': put(g); break;
00224 case '8': put(h); break;
00225 }
00226 }
00227 }
00228 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H, typename I>
00229 Format::Format(const char* ca, const A& a, const B& b, const C& c, const D& d, const E& e, const F& f, const G& g, const H& h, const I& i) : oss()
00230 {
00231 String fmt(ca);
00232 while (!fmt.empty())
00233 {
00234 switch (process(fmt, '9'))
00235 {
00236 case '1': put(a); break;
00237 case '2': put(b); break;
00238 case '3': put(c); break;
00239 case '4': put(d); break;
00240 case '5': put(e); break;
00241 case '6': put(f); break;
00242 case '7': put(g); break;
00243 case '8': put(h); break;
00244 case '9': put(i); break;
00245 }
00246 }
00247 }
00248
00249 }
00250
00251 #endif
00252