OSDN Git Service

Merge
[winmerge-jp/winmerge-jp.git] / Src / DiffContext.h
1 /**
2  *  @file DiffContext.h
3  *
4  *  @brief Declarations of CDiffContext and diff structures
5  */
6 #pragma once
7
8 #define POCO_NO_UNWINDOWS 1
9 #include <Poco/Mutex.h>
10 #include <memory>
11 #include "PathContext.h"
12 #include "DiffFileInfo.h"
13 #include "DiffItemList.h"
14 #include "FilterList.h"
15
16 class PackingInfo;
17 class PrediffingInfo;
18 class IDiffFilter;
19 class CompareStats;
20 class IAbortable;
21 class CDiffWrapper;
22 class CompareOptions;
23 struct DIFFOPTIONS;
24 class FilterCommentsManager;
25
26 /** Interface to a provider of plugin info */
27 class IPluginInfos
28 {
29 public:
30         virtual void FetchPluginInfos(const String& filteredFilenames, 
31                                       PackingInfo ** infoUnpacker, 
32                                       PrediffingInfo ** infoPrediffer) = 0;
33 };
34
35 /**
36  * The folder compare context.
37  * This class holds data of the current folder compare. There are paths
38  * to compare, filters used, compare options etc. And compare results list
39  * is also contained in this class. Many compare classes and functions have
40  * a pointer to instance of this class. 
41  *
42  * @note If you add new member variables, remember to copy values in
43  * CDiffContext::CDiffContext(..,CDiffContext) constructor!
44  */
45 class CDiffContext : public DiffItemList
46 {
47 public:
48         /** @brief Special values for difference counts. */
49         enum
50         {
51                 DIFFS_UNKNOWN = -1, /**< Difference count unknown (generally). */
52                 DIFFS_UNKNOWN_QUICKCOMPARE = -9, /**< Unknown because of quick-compare method. */
53         };
54
55         CDiffContext(const PathContext & paths, int compareMethod);
56         ~CDiffContext();
57
58         void UpdateVersion(DIFFITEM &di, int nIndex) const;
59
60         /**
61          * Get the main compare method used in this compare.
62          * @return Compare method used.
63          */
64         int GetCompareMethod(void) const { return m_nCompMethod; }
65
66         //@{
67         /**
68          * @name Path accessor functions.
69          *
70          * These functions return left/right path associated to DiffContext.
71          * There is no setter fuctions and path can be set only via constructor.
72          * Normalized paths are preferred to use - short paths are expanded
73          * and trailing slashes removed (except from root path).
74          */
75         /**
76          * Get left-side compare path.
77          * @return full path in left-side.
78          */
79         String GetLeftPath() const { return m_paths.GetLeft(false); }
80         String GetMiddlePath() const { return m_paths.GetMiddle(false); }
81         /**
82          * Get right-side compare path.
83          * @return full path in right-side.
84          */
85         String GetRightPath() const { return m_paths.GetRight(false); }
86         String GetPath(int nIndex) const { return m_paths.GetPath(nIndex, false); }
87         /**
88          * Get left-side compare path in normalized form.
89          * @return full path in left-side.
90          */
91         String GetNormalizedLeft() const { return m_paths.GetLeft(); }
92         String GetNormalizedMiddle() const { return m_paths.GetMiddle(); }
93         /**
94          * Get right-side compare path in normalized form.
95          * @return full path in left-side.
96          */
97         String GetNormalizedRight() const { return m_paths.GetRight(); }
98         String GetNormalizedPath(int nIndex) const { return m_paths.GetPath(nIndex, true); }
99         PathContext GetNormalizedPaths() const
100         {
101                 PathContext paths;
102                 for (int nIndex = 0; nIndex < m_paths.GetSize(); nIndex++)
103                         paths.SetPath(nIndex, m_paths.GetPath(nIndex, true));
104                 return paths;
105         }
106         //@}
107
108         // change an existing difference
109         bool UpdateInfoFromDiskHalf(DIFFITEM &di, int nIndex);
110         void UpdateStatusFromDisk(DIFFITEM *diffpos, int nIndex);
111
112         bool CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
113         CompareOptions * GetCompareOptions(int compareMethod);
114
115         // retrieve or manufacture plugin info for specified file comparison
116         void FetchPluginInfos(const String& filteredFilenames,
117                 PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
118
119         //@{
120         /**
121          * @name Compare aborting interface.
122          * These functions handle compare aborting using IAbortable interface.
123          */
124         bool ShouldAbort() const;
125
126         /**
127          * Set pointer to IAbortable interface.
128          * This function sets pointer to interface used to abort the compare when
129          * user wants to.
130          * @param [in] piAbortable Pointer to interface.
131          */
132         void SetAbortable(IAbortable * piAbortable) { m_piAbortable = piAbortable; }
133
134         /**
135          * Returns a pointer to current IAbortable interface.
136          * This function returns a pointer to interface used to abort the compare.
137          * @return Pointer to current IAbortable interface.
138          */
139         const IAbortable * GetAbortable() const { return m_piAbortable; }
140         //@}
141
142         int GetCompareDirs() const { return m_paths.GetSize(); }
143
144         void Swap(int idx1, int idx2)
145         {
146                 String tmp;
147                 tmp = m_paths.GetPath(idx1);
148                 m_paths.SetPath(idx1, m_paths.GetPath(idx2));
149                 m_paths.SetPath(idx2, tmp);
150                 DiffItemList::Swap(idx1, idx2);
151         }
152
153         IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
154         IPluginInfos * m_piPluginInfos;
155         int m_iGuessEncodingType;
156
157         bool m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
158         CompareStats *m_pCompareStats; /**< Pointer to compare statistics */
159
160         /**
161          * Optimize compare by stopping after first difference.
162          * In some compare methods (currently quick compare) we can stop the
163          * compare right after finding the first difference. This speeds up the
164          * compare, but also causes compare statistics to be inaccurate.
165          */
166         bool m_bStopAfterFirstDiff;
167
168         /**
169          * Threshold size for switching to quick compare.
170          * When diffutils compare is selected, files bigger (in bytes) than this
171          * value are compared using Quick compare. This is because diffutils simply
172          * cannot compare large files. And large files are usually binary files.
173          */
174         int m_nQuickCompareLimit;
175
176         /**
177          * Walk into unique folders and add contents.
178          * This enables/disables walking into unique folders. If we don't walk into
179          * unique folders, they are shown as such in folder compare results. If we
180          * walk into unique folders, we'll show all files in the unique folder and
181          * in possible subfolders.
182          *
183          * This value is true by default.
184          */
185         bool m_bWalkUniques;
186         bool m_bIgnoreReparsePoints;
187         bool m_bIgnoreCodepage;
188
189         bool m_bRecursive; /**< Do we include subfolders to compare? */
190         bool m_bPluginsEnabled; /**< Are plugins enabled? */
191         std::unique_ptr<FilterList> m_pFilterList; /**< Filter list for line filters */
192         FilterCommentsManager *m_pFilterCommentsManager;
193
194 private:
195         /**
196          * The main compare method used.
197          * This is the main compare method set when compare is started. There
198          * can be temporary switches to other method (e.g. for large file) but
199          * this main method must be set back for next file.
200          */
201         int m_nCompMethod;
202
203         std::unique_ptr<DIFFOPTIONS> m_pOptions; /**< Generalized compare options. */
204         std::unique_ptr<CompareOptions> m_pContentCompareOptions; /**< Per compare method compare options. */
205         std::unique_ptr<CompareOptions> m_pQuickCompareOptions;   /**< Per compare method compare options. */
206         PathContext m_paths; /**< (root) paths for this context */
207         IAbortable *m_piAbortable; /**< Interface for aborting the compare. */
208         Poco::FastMutex m_mutex;
209 };