00001 #pragma ident "$Id: NumberFormatter.hpp 2938 2011-10-23 19:39:11Z yanweignss $"
00002
00008 #ifndef GPSTK_NUMBERFORMATTER_HPP
00009 #define GPSTK_NUMBERFORMATTER_HPP
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <string>
00034
00035 namespace gpstk
00036 {
00037
00049 class NumberFormatter
00050 {
00051 public:
00052 static std::string format(int value);
00053
00054 static std::string format(int value, int width);
00055
00056 static std::string format0(int value, int width);
00057
00058 static std::string formatHex(int value);
00059
00060 static std::string formatHex(int value, int width);
00061
00062 static std::string format(unsigned value);
00063
00064 static std::string format(unsigned value, int width);
00065
00066 static std::string format0(unsigned int value, int width);
00067
00068 static std::string formatHex(unsigned value);
00069
00070 static std::string formatHex(unsigned value, int width);
00071
00072 static std::string format(long value);
00073
00074 static std::string format(long value, int width);
00075
00076 static std::string format0(long value, int width);
00077
00078 static std::string formatHex(long value);
00079
00080 static std::string formatHex(long value, int width);
00081
00082 static std::string format(unsigned long value);
00083
00084 static std::string format(unsigned long value, int width);
00085
00086 static std::string format0(unsigned long value, int width);
00087
00088 static std::string formatHex(unsigned long value);
00089
00090 static std::string formatHex(unsigned long value, int width);
00091
00092 static std::string format(float value);
00093
00094 static std::string format(double value);
00095
00096 static std::string format(double value, int precision);
00097
00098 static std::string format(double value, int width, int precision);
00099
00100
00101 static void append(std::string& str, int value);
00102
00103 static void append(std::string& str, int value, int width);
00104
00105 static void append0(std::string& str, int value, int width);
00106
00107 static void appendHex(std::string& str, int value);
00108
00109 static void appendHex(std::string& str, int value, int width);
00110
00111 static void append(std::string& str, unsigned value);
00112
00113 static void append(std::string& str, unsigned value, int width);
00114
00115 static void append0(std::string& str, unsigned int value, int width);
00116
00117 static void appendHex(std::string& str, unsigned value);
00118
00119 static void appendHex(std::string& str, unsigned value, int width);
00120
00121 static void append(std::string& str, long value);
00122
00123 static void append(std::string& str, long value, int width);
00124
00125 static void append0(std::string& str, long value, int width);
00126
00127 static void appendHex(std::string& str, long value);
00128
00129 static void appendHex(std::string& str, long value, int width);
00130
00131 static void append(std::string& str, unsigned long value);
00132
00133 static void append(std::string& str, unsigned long value, int width);
00134
00135 static void append0(std::string& str, unsigned long value, int width);
00136
00137 static void appendHex(std::string& str, unsigned long value);
00138
00139 static void appendHex(std::string& str, unsigned long value, int width);
00140
00141 static void append(std::string& str, float value);
00142
00143 static void append(std::string& str, double value);
00144
00145 static void append(std::string& str, double value, int precision);
00146
00147 static void append(std::string& str, double value, int width, int precision);
00148
00149 };
00150
00151
00152
00153
00154
00155 inline std::string NumberFormatter::format(int value)
00156 {
00157 std::string result;
00158 append(result, value);
00159 return result;
00160 }
00161
00162
00163 inline std::string NumberFormatter::format(int value, int width)
00164 {
00165 std::string result;
00166 append(result, value, width);
00167 return result;
00168 }
00169
00170
00171 inline std::string NumberFormatter::format0(int value, int width)
00172 {
00173 std::string result;
00174 append0(result, value, width);
00175 return result;
00176 }
00177
00178
00179 inline std::string NumberFormatter::formatHex(int value)
00180 {
00181 std::string result;
00182 appendHex(result, value);
00183 return result;
00184 }
00185
00186
00187 inline std::string NumberFormatter::formatHex(int value, int width)
00188 {
00189 std::string result;
00190 appendHex(result, value, width);
00191 return result;
00192 }
00193
00194
00195 inline std::string NumberFormatter::format(unsigned value)
00196 {
00197 std::string result;
00198 append(result, value);
00199 return result;
00200 }
00201
00202
00203 inline std::string NumberFormatter::format(unsigned value, int width)
00204 {
00205 std::string result;
00206 append(result, value, width);
00207 return result;
00208 }
00209
00210
00211 inline std::string NumberFormatter::format0(unsigned int value, int width)
00212 {
00213 std::string result;
00214 append0(result, value, width);
00215 return result;
00216 }
00217
00218
00219 inline std::string NumberFormatter::formatHex(unsigned value)
00220 {
00221 std::string result;
00222 appendHex(result, value);
00223 return result;
00224 }
00225
00226
00227 inline std::string NumberFormatter::formatHex(unsigned value, int width)
00228 {
00229 std::string result;
00230 appendHex(result, value, width);
00231 return result;
00232 }
00233
00234
00235 inline std::string NumberFormatter::format(long value)
00236 {
00237 std::string result;
00238 append(result, value);
00239 return result;
00240 }
00241
00242
00243 inline std::string NumberFormatter::format(long value, int width)
00244 {
00245 std::string result;
00246 append(result, value, width);
00247 return result;
00248 }
00249
00250
00251 inline std::string NumberFormatter::format0(long value, int width)
00252 {
00253 std::string result;
00254 append0(result, value, width);
00255 return result;
00256 }
00257
00258
00259 inline std::string NumberFormatter::formatHex(long value)
00260 {
00261 std::string result;
00262 appendHex(result, value);
00263 return result;
00264 }
00265
00266
00267 inline std::string NumberFormatter::formatHex(long value, int width)
00268 {
00269 std::string result;
00270 appendHex(result, value, width);
00271 return result;
00272 }
00273
00274
00275 inline std::string NumberFormatter::format(unsigned long value)
00276 {
00277 std::string result;
00278 append(result, value);
00279 return result;
00280 }
00281
00282
00283 inline std::string NumberFormatter::format(unsigned long value, int width)
00284 {
00285 std::string result;
00286 append(result, value, width);
00287 return result;
00288 }
00289
00290
00291 inline std::string NumberFormatter::format0(unsigned long value, int width)
00292 {
00293 std::string result;
00294 append0(result, value, width);
00295 return result;
00296 }
00297
00298
00299 inline std::string NumberFormatter::formatHex(unsigned long value)
00300 {
00301 std::string result;
00302 appendHex(result, value);
00303 return result;
00304 }
00305
00306
00307 inline std::string NumberFormatter::formatHex(unsigned long value, int width)
00308 {
00309 std::string result;
00310 appendHex(result, value, width);
00311 return result;
00312 }
00313
00314 inline std::string NumberFormatter::format(float value)
00315 {
00316 std::string result;
00317 append(result, value);
00318 return result;
00319 }
00320
00321
00322 inline std::string NumberFormatter::format(double value)
00323 {
00324 std::string result;
00325 append(result, value);
00326 return result;
00327 }
00328
00329
00330 inline std::string NumberFormatter::format(double value, int precision)
00331 {
00332 std::string result;
00333 append(result, value, precision);
00334 return result;
00335 }
00336
00337
00338 inline std::string NumberFormatter::format(double value, int width, int precision)
00339 {
00340 std::string result;
00341 append(result, value, width, precision);
00342 return result;
00343 }
00344
00345 }
00346
00347
00348 #endif //GPSTK_NUMBERFORMATTER_HPP
00349