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.

91 lines
2.5 KiB

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