Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: filesize.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCVIEW_FILESIZE_H
  11. #define _INC_CSCVIEW_FILESIZE_H
  12. //
  13. // Simple class to convert a file size value to a string formatted for display.
  14. // The display format is the same used by the shell (i.e. "10.5 MB")
  15. //
  16. class FileSize
  17. {
  18. public:
  19. explicit FileSize(ULONGLONG ullSize = 0);
  20. ~FileSize(void) { }
  21. FileSize(const FileSize& rhs)
  22. { *this = rhs; }
  23. FileSize& operator = (const FileSize& rhs);
  24. int Compare(const FileSize& rhs) const
  25. { return *this > rhs ? 1 : (*this == rhs ? 0 : -1); }
  26. operator ULONGLONG() const
  27. { return m_ullSize; }
  28. ULONGLONG GetSize(void) const
  29. { return m_ullSize; }
  30. void GetString(LPTSTR pszOut, UINT cchOut) const
  31. { TraceAssert(NULL != pszOut); Format(m_ullSize, pszOut, cchOut); }
  32. private:
  33. ULONGLONG m_ullSize; // Size as a number.
  34. static int m_rgiOrders[]; // Array of format string res IDs.
  35. void Format(ULONGLONG ullSize, LPTSTR pszOut, UINT cchOut) const;
  36. void CvtSizeToText(ULONGLONG n, LPTSTR pszBuffer) const;
  37. int StrToInt(LPCTSTR lpSrc) const;
  38. LPTSTR AddCommas(ULONGLONG n, LPTSTR pszResult, int cchResult) const;
  39. bool IsDigit(TCHAR ch) const
  40. { return (ch >= TEXT('0') && ch <= TEXT('9')); }
  41. friend bool operator == (const FileSize& a, const FileSize& b);
  42. friend bool operator != (const FileSize& a, const FileSize& b);
  43. friend bool operator < (const FileSize& a, const FileSize& b);
  44. friend bool operator <= (const FileSize& a, const FileSize& b);
  45. friend bool operator > (const FileSize& a, const FileSize& b);
  46. friend bool operator >= (const FileSize& a, const FileSize& b);
  47. };
  48. //
  49. // The various comparison operators for FileSize objects.
  50. //
  51. inline bool operator == (const FileSize& a, const FileSize& b)
  52. {
  53. return a.m_ullSize == b.m_ullSize;
  54. }
  55. inline bool operator != (const FileSize& a, const FileSize& b)
  56. {
  57. return !(a == b);
  58. }
  59. inline bool operator < (const FileSize& a, const FileSize& b)
  60. {
  61. return a.m_ullSize < b.m_ullSize;
  62. }
  63. inline bool operator <= (const FileSize& a, const FileSize& b)
  64. {
  65. return (a < b) || (a == b);
  66. }
  67. inline bool operator > (const FileSize& a, const FileSize& b)
  68. {
  69. return !(a < b) && !(a == b);
  70. }
  71. inline bool operator >= (const FileSize& a, const FileSize& b)
  72. {
  73. return (a > b) || (a == b);
  74. }
  75. #endif // _INC_CSCVIEW_FILESIZE_H