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.

81 lines
1.4 KiB

  1. //
  2. // Systrack - System resource tracking
  3. // Copyright (c) Microsoft Corporation, 1997
  4. //
  5. //
  6. // header: history.hxx
  7. // author: silviuc
  8. // created: Wed Nov 11 12:17:11 1998
  9. //
  10. #ifndef _HISTORY_HXX_INCLUDED_
  11. #define _HISTORY_HXX_INCLUDED_
  12. #include "assert.hxx"
  13. template<class T, unsigned Sz>
  14. class History
  15. {
  16. private:
  17. bool _Empty;
  18. unsigned _Size;
  19. unsigned _Index;
  20. T _Data [Sz];
  21. public:
  22. History () {
  23. _Empty = true;
  24. _Size = Sz;
  25. _Index = 0;
  26. ZeroMemory (_Data, sizeof _Data);
  27. }
  28. const T& Last () const {
  29. assert_ (_Size != 0);
  30. return _Data [(_Index + _Size - 1) % _Size];
  31. }
  32. const T& First () const {
  33. return _Data [_Index];
  34. }
  35. void Add (const T& Value) {
  36. if (_Empty == true) {
  37. for (unsigned I = 0; I < _Size; I++)
  38. _Data[I] = Value;
  39. _Empty = false;
  40. }
  41. _Data[_Index] = Value;
  42. _Index = (_Index + 1) % _Size;
  43. }
  44. void Reset (const T& Value) {
  45. for (unsigned Index = 0; Index < _Size; Index++) {
  46. _Data[Index] = Value;
  47. }
  48. }
  49. bool Delta (const T& DeltaValue) const {
  50. return (First() < Last()) && ((Last() - First()) > DeltaValue);
  51. }
  52. };
  53. // ...
  54. #endif // #ifndef _HISTORY_HXX_INCLUDED_
  55. //
  56. // end of header: history.hxx
  57. //