OSDN Git Service

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