- Timestamp:
- 02/04/08 22:42:46 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 047516e
- Parents:
- f6edbcd
- Location:
- include
- Files:
-
- 2 edited
-
checkHelpers.hpp (modified) (7 diffs)
-
strEx.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
include/checkHelpers.hpp
r99e4d8f rde8ef76 134 134 return strEx::itos_as_BKMG(value); 135 135 } 136 static std::wstring print_perf(TType value) { 137 return strEx::itos_as_BKMG(value); 136 static std::wstring get_perf_unit(TType value) { 137 return strEx::find_proper_unit_BKMG(value); 138 } 139 static std::wstring print_perf(TType value, std::wstring unit) { 140 return strEx::format_BKMG(value, unit); 138 141 } 139 142 static TType parse(std::wstring s) { … … 187 190 return strEx::itos(value); 188 191 } 189 static std::wstring print_perf(TType value) { 192 static std::wstring get_perf_unit(TType value) { 193 return _T(""); 194 } 195 static std::wstring print_perf(TType value, std::wstring unit) { 190 196 return strEx::itos(value); 191 197 } … … 211 217 return strEx::itos(value); 212 218 } 213 static std::wstring print_perf(int value) { 219 static std::wstring get_perf_unit(int value) { 220 return _T(""); 221 } 222 static std::wstring print_perf(int value, std::wstring unit) { 214 223 return strEx::itos(value); 215 224 } … … 238 247 return strEx::itos(value); 239 248 } 240 static std::wstring print_perf(__int64 value) { 249 static std::wstring get_perf_unit(__int64 value) { 250 return _T(""); 251 } 252 static std::wstring print_perf(__int64 value, std::wstring unit) { 241 253 return strEx::itos(value); 242 254 } … … 262 274 return strEx::stod(s); 263 275 } 264 static std::wstring print_perf(double value) { 276 static std::wstring get_perf_unit(double value) { 277 return _T(""); 278 } 279 static std::wstring print_perf(double value, std::wstring unit) { 265 280 return strEx::itos(value); 266 281 } … … 360 375 } 361 376 static std::wstring gatherPerfData(std::wstring alias, TType &value, TType warn, TType crit) { 362 return MAKE_PERFDATA(alias, THandler::print_perf(value), _T(""), THandler::print_perf(warn), THandler::print_perf(crit)); 377 std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value))); 378 return MAKE_PERFDATA(alias, THandler::print_perf(value, unit), unit, THandler::print_perf(warn, unit), THandler::print_perf(crit, unit)); 363 379 } 364 380 … … 495 511 THandler::print_unformated(warn), THandler::print_unformated(crit)); 496 512 } else { 513 std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value.value))); 497 514 return 498 MAKE_PERFDATA(alias, THandler::print_perf(value.value ), _T(""),499 THandler::print_perf(warn ), THandler::print_perf(crit));515 MAKE_PERFDATA(alias, THandler::print_perf(value.value, unit), unit, 516 THandler::print_perf(warn, unit), THandler::print_perf(crit, unit)); 500 517 } 501 518 } -
include/strEx.h
r5ac88c0a rde8ef76 310 310 return ret; 311 311 } 312 inline std::wstring format_BKMG(unsigned __int64 i, std::wstring unit) { 313 double cpy = static_cast<double>(i); 314 TCHAR postfix[] = _T(BKMG_RANGE); 315 if (unit.length() != 1) 316 return itos(cpy); 317 for (int i=0;i<BKMG_SIZE;i++) { 318 if (unit[0] == postfix[i]) { 319 std::wstringstream ss; 320 ss << std::setiosflags(std::ios::fixed) << std::setprecision(3) << cpy; 321 std::wstring s = ss.str(); 322 std::wstring::size_type pos = s.find_last_not_of(_T("0")); 323 if (pos != std::string::npos) { 324 s = s.substr(0,pos); 325 } 326 return s; 327 } 328 cpy/=1024; 329 } 330 return itos(cpy); 331 } 332 inline std::wstring find_proper_unit_BKMG(unsigned __int64 i) { 333 double cpy = static_cast<double>(i); 334 TCHAR postfix[] = _T(BKMG_RANGE); 335 int idx = 0; 336 while ((cpy > 999)&&(idx<BKMG_SIZE)) { 337 cpy/=1024; 338 idx++; 339 } 340 return std::wstring(1, postfix[idx]); 341 } 312 342 313 343 typedef std::list<std::wstring> splitList;
Note: See TracChangeset
for help on using the changeset viewer.








