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.

92 lines
2.2 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. DIFF.H
  5. History:
  6. --*/
  7. #ifndef DIFF_H
  8. #define DIFF_H
  9. class CDifference;
  10. class CDeltaVisitor;
  11. class CDelta;
  12. class CDiffAlgorithm;
  13. class CDiffAlgortihmFactory;
  14. class CDiffEngine;
  15. class CDifference // Represents each of the elements in a CDelta object
  16. {
  17. public:
  18. virtual ~CDifference();
  19. enum ChangeType
  20. {
  21. NoChange,
  22. Added,
  23. Deleted
  24. };
  25. virtual ChangeType GetChangeType() const = 0; // types of change that caused the difference
  26. virtual const wchar_t * GetUnit() const = 0; // comparison unit (0-terminated string)
  27. virtual int GetOldUnitPosition() const = 0; // 0-based position in old sequence. -1 if Added
  28. virtual int GetNewUnitPosition() const = 0; // 0-based position in new sequence. -1 if Deleted
  29. virtual const wchar_t * GetPrefix() const = 0; //prpend this string to unit string
  30. virtual const wchar_t * GetSufix() const = 0; //append this string to unit string
  31. virtual bool IsFirst() const = 0; //is this first difference in delta?
  32. virtual bool IsLast() const = 0; //is this last difference in delta?
  33. };
  34. class LTAPIENTRY CDeltaVisitor
  35. {
  36. public:
  37. //called for each element in a CDelta
  38. virtual void VisitDifference(const CDifference & diff) const = 0;
  39. };
  40. class CDelta // sequence of CDifference elements
  41. {
  42. public:
  43. virtual ~CDelta();
  44. // Starts a visit to all CDifference elements in CDelta
  45. virtual void Traverse(const CDeltaVisitor & dv) = 0;
  46. };
  47. class LTAPIENTRY CDiffAlgorithm
  48. {
  49. public:
  50. virtual ~CDiffAlgorithm();
  51. // Computes a CDelta object based on a certain diff algorithm
  52. virtual CDelta * CalculateDelta(
  53. const wchar_t * seq1,
  54. const wchar_t * seq2) = 0;
  55. };
  56. // Encapsulates the creation of the diff algorithm
  57. class LTAPIENTRY CDiffAlgorithmFactory
  58. {
  59. public:
  60. virtual CDiffAlgorithm * CreateDiffAlgorithm() = 0;
  61. };
  62. // Generic diff engine that calculates delta and processes each difference in it
  63. class LTAPIENTRY CDiffEngine
  64. {
  65. public:
  66. static void Diff(CDiffAlgorithm & diffalg,
  67. const wchar_t * seq1,
  68. const wchar_t * seq2,
  69. const CDeltaVisitor & dv);
  70. };
  71. #if !defined(_DEBUG) || defined(IMPLEMENT)
  72. #include "diff.inl"
  73. #endif
  74. #endif // DIFF_H