OSDN Git Service

Merge rev.7791
[winmerge-jp/winmerge-jp.git] / Src / DiffContext.h
1 /**
2  *  @file DiffContext.h
3  *
4  *  @brief Declarations of CDiffContext and diff structures
5  */
6 // ID line follows -- this is updated by SVN
7 // $Id: DiffContext.h 6910 2009-07-12 09:06:54Z kimmov $
8
9 #if !defined(AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_)
10 #define AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_
11 #pragma once
12
13 #include "PathContext.h"
14 #include "DiffFileInfo.h"
15 #include "DiffItemList.h"
16
17 class PackingInfo;
18 class PrediffingInfo;
19 class IDiffFilter;
20 struct DIFFITEM;
21 class CompareStats;
22 class IAbortable;
23 class CDiffWrapper;
24 class FilterList;
25 class CompareOptions;
26 struct DIFFOPTIONS;
27
28 /** Interface to a provider of plugin info */
29 class IPluginInfos
30 {
31 public:
32         virtual void FetchPluginInfos(LPCTSTR filteredFilenames, 
33                                       PackingInfo ** infoUnpacker, 
34                                       PrediffingInfo ** infoPrediffer) = 0;
35 };
36
37 /**
38  * The folder compare context.
39  * This class holds data of the current folder compare. There are paths
40  * to compare, filters used, compare options etc. And compare results list
41  * is also contained in this class. Many compare classes and functions have
42  * a pointer to instance of this class. 
43  *
44  * @note If you add new member variables, remember to copy values in
45  * CDiffContext::CDiffContext(..,CDiffContext) constructor!
46  */
47 class CDiffContext : public DiffItemList
48 {
49 public:
50         /** @brief Special values for difference counts. */
51         enum
52         {
53                 DIFFS_UNKNOWN = -1, /**< Difference count unknown (generally). */
54                 DIFFS_UNKNOWN_QUICKCOMPARE = -9, /**< Unknown because of quick-compare method. */
55         };
56
57         CDiffContext(const PathContext & paths, int compareMethod);
58         ~CDiffContext();
59
60         void UpdateVersion(DIFFITEM & di, BOOL bLeft) const;
61
62         /**
63          * Get the main compare method used in this compare.
64          * @return Compare method used.
65          */
66         int GetCompareMethod(void) const { return m_nCompMethod; }
67
68         //@{
69         /**
70          * @name Path accessor functions.
71          *
72          * These functions return left/right path associated to DiffContext.
73          * There is no setter fuctions and path can be set only via constructor.
74          * Normalized paths are preferred to use - short paths are expanded
75          * and trailing slashes removed (except from root path).
76          */
77         /**
78          * Get left-side compare path.
79          * @return full path in left-side.
80          */
81         String GetLeftPath() const { return m_paths.GetLeft(FALSE); }
82         String GetMiddlePath() const { return m_paths.GetMiddle(FALSE); }
83         /**
84          * Get right-side compare path.
85          * @return full path in right-side.
86          */
87         String GetRightPath() const { return m_paths.GetRight(FALSE); }
88         String GetPath(int nIndex) const { return m_paths.GetPath(nIndex, FALSE); }
89         /**
90          * Get left-side compare path in normalized form.
91          * @return full path in left-side.
92          */
93         String GetNormalizedLeft() const { return m_paths.GetLeft(); }
94         String GetNormalizedMiddle() const { return m_paths.GetMiddle(); }
95         /**
96          * Get right-side compare path in normalized form.
97          * @return full path in left-side.
98          */
99         String GetNormalizedRight() const { return m_paths.GetRight(); }
100         String GetNormalizedPath(int nIndex) const { return m_paths.GetPath(nIndex, TRUE); }
101         PathContext GetNormalizedPaths() const
102         {
103                 PathContext paths;
104                 for (int nIndex = 0; nIndex < m_paths.GetSize(); nIndex++)
105                         paths.SetPath(nIndex, m_paths.GetPath(nIndex, TRUE).c_str());
106                 return paths;
107         }
108         //@}
109
110         // change an existing difference
111         BOOL UpdateInfoFromDiskHalf(DIFFITEM & di, int nIndex);
112         void UpdateStatusFromDisk(UINT_PTR diffpos, BOOL bLeft, BOOL bRight);
113         void UpdateStatusFromDisk(POSITION diffpos, BOOL bLeft, BOOL bMiddle, BOOL bRight);
114
115         BOOL CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
116         CompareOptions * GetCompareOptions(int compareMethod);
117
118         // retrieve or manufacture plugin info for specified file comparison
119         void FetchPluginInfos(LPCTSTR filteredFilenames,
120                 PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
121
122         //@{
123         /**
124          * @name Compare aborting interface.
125          * These functions handle compare aborting using IAbortable interface.
126          */
127         bool ShouldAbort() const;
128
129         /**
130          * Set pointer to IAbortable interface.
131          * This function sets pointer to interface used to abort the compare when
132          * user wants to.
133          * @param [in] piAbortable Pointer to interface.
134          */
135         void SetAbortable(IAbortable * piAbortable) { m_piAbortable = piAbortable; }
136
137         /**
138          * Returns a pointer to current IAbortable interface.
139          * This function returns a pointer to interface used to abort the compare.
140          * @return Pointer to current IAbortable interface.
141          */
142         const IAbortable * GetAbortable() const { return m_piAbortable; }
143         //@}
144
145         int GetCompareDirs() const { return m_paths.GetSize(); }
146
147         IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
148         IPluginInfos * m_piPluginInfos;
149         int m_iGuessEncodingType;
150
151         /**
152          * The current and effective compare method.
153          * During the compare we may change compare method per file. This may
154          * happen for various reasons. But the change is always temporarily and
155          * we must return to the main method indicated by m_nCompMethod.
156          */
157         int m_nCurrentCompMethod;
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         /**
179          * Walk into unique folders and add contents.
180          * This enables/disables walking into unique folders. If we don't walk into
181          * unique folders, they are shown as such in folder compare results. If we
182          * walk into unique folders, we'll show all files in the unique folder and
183          * in possible subfolders.
184          *
185          * This value is true by default.
186          */
187         bool m_bWalkUniques;
188
189         bool m_bRecursive; /**< Do we include subfolders to compare? */
190         bool m_bPluginsEnabled; /**< Are plugins enabled? */
191         FilterList * m_pFilterList; /**< Filter list for line filters */
192         BOOL m_bScanUnpairedDir; /** Scan into unpaired directories **/
193         CDiffWrapper *m_pDiffWrapper;
194
195 private:
196         /**
197          * The main compare method used.
198          * This is the main compare method set when compare is started. There
199          * can be temporary switches to other method (e.g. for large file) but
200          * this main method must be set back for next file.
201          */
202         int m_nCompMethod;
203
204         DIFFOPTIONS *m_pOptions; /**< Generalized compare options. */
205         CompareOptions *m_pCompareOptions; /**< Per compare method compare options. */
206         PathContext m_paths; /**< (root) paths for this context */
207         IAbortable *m_piAbortable; /**< Interface for aborting the compare. */
208 };
209
210 #endif // !defined(AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_)