OSDN Git Service

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