OSDN Git Service

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