LCOV - code coverage report
Current view: top level - src/lib - LineDiffProcessor.h (source / functions) Hit Total Coverage
Test: mediawiki/php/wikidiff2 test coverage report Lines: 3 3 100.0 %
Date: 2023-07-04 10:20:16 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #ifndef LINEDIFFPROCESSOR_H
       2             : #define LINEDIFFPROCESSOR_H
       3             : #include "DiffEngine.h"
       4             : #include "WordDiffCache.h"
       5             : 
       6             : namespace wikidiff2 {
       7             : 
       8             : /**
       9             :  * Class to do post-processing operations on line diffs.
      10             :  */
      11             : class LineDiffProcessor {
      12             :     public:
      13             :         typedef std::basic_string<char, std::char_traits<char>, WD2_ALLOCATOR<char> > String;
      14             :         typedef Diff<String> StringDiff;
      15             :         typedef Diff<Word> WordDiff;
      16             :         typedef DiffOp<String> StringDiffOp;
      17             :         typedef DiffOp<String>::PointerVector PointerVector;
      18             :         typedef PointerVector::iterator PointerVectorIterator;
      19             : 
      20             :         /**
      21             :          * Options to be passed to the constructor
      22             :          */
      23             :         struct Config {
      24             :             /**
      25             :              * Changed lines with a similarity value below this threshold will
      26             :              * be split into a deleted line and added line. This helps matching
      27             :              * up moved lines in some cases.
      28             :              */
      29             :             double changeThreshold;
      30             : 
      31             :             /**
      32             :              * The minimum similarity which must be maintained during a split
      33             :              * detection search. The split size increases until either the
      34             :              * similarity between the LHS and the multiple RHS lines becomes
      35             :              * less than initialSplitThreshold, or maxSplitSize is reached.
      36             :              */
      37             :             double initialSplitThreshold;
      38             : 
      39             :             /**
      40             :              * The minimum similarity between one LHS line and multiple RHS
      41             :              * lines which must be achieved to format the block as a split.
      42             :              */
      43             :             double finalSplitThreshold;
      44             : 
      45             :             /**
      46             :              * The maximum number of RHS lines which can be compared with
      47             :              * one LHS line.
      48             :              */
      49             :             int64_t maxSplitSize;
      50             :         };
      51             : 
      52          47 :         LineDiffProcessor(const Config & config_, WordDiffCache & wordDiffCache_)
      53          47 :             : config(config_), wordDiffCache(wordDiffCache_)
      54          47 :         {}
      55             : 
      56             :         /**
      57             :          * Process the line diff. Detect dissimilar changes and replace them
      58             :          * with add+delete options.
      59             :          *
      60             :          * @param lineDiff In/out parameter. The contents will be replaced with
      61             :          *   the new diff.
      62             :          */
      63             :         void process(StringDiff & lineDiff);
      64             : 
      65             :         /**
      66             :          * Empty line pointer vector
      67             :          */
      68             :         static PointerVector empty;
      69             : 
      70             :     private:
      71             :         /**
      72             :          * The cache used for all necessary word diff operations
      73             :          */
      74             :         WordDiffCache & wordDiffCache;
      75             : 
      76             :         /**
      77             :          * The config options
      78             :          */
      79             :         Config config;
      80             : 
      81             :         /**
      82             :          * The return value of getSplit
      83             :          */
      84             :         struct SplitInfo {
      85             :             /** The number of lines in the RHS that correspond to the single LHS line */
      86             :             int size;
      87             :             /** The similarity metric */
      88             :             double similarity;
      89             :         };
      90             : 
      91             :         void detectChanges(StringDiff & result, StringDiffOp & diffOp);
      92             : 
      93             :         SplitInfo getSplit(
      94             :             PointerVectorIterator pDel, PointerVectorIterator pDelEnd,
      95             :             PointerVectorIterator pAdd, PointerVectorIterator pAddEnd);
      96             : 
      97             :         const WordDiffStats & getConcatDiffStats(
      98             :             PointerVectorIterator from, PointerVectorIterator fromEnd,
      99             :             PointerVectorIterator to, PointerVectorIterator toEnd);
     100             : 
     101             : };
     102             : 
     103             : } // namespace wikidiff2
     104             : 
     105             : #endif // LINEDIFFPROCESSOR_H

Generated by: LCOV version 1.13