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         /**
154          * The current and effective compare method.
155          * During the compare we may change compare method per file. This may
156          * happen for various reasons. But the change is always temporarily and
157          * we must return to the main method indicated by m_nCompMethod.
158          */
159         Poco::ThreadLocal<int> m_nCurrentCompMethod;
160
161         bool m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
162         CompareStats *m_pCompareStats; /**< Pointer to compare statistics */
163
164         /**
165          * Optimize compare by stopping after first difference.
166          * In some compare methods (currently quick compare) we can stop the
167          * compare right after finding the first difference. This speeds up the
168          * compare, but also causes compare statistics to be inaccurate.
169          */
170         bool m_bStopAfterFirstDiff;
171
172         /**
173          * Threshold size for switching to quick compare.
174          * When diffutils compare is selected, files bigger (in bytes) than this
175          * value are compared using Quick compare. This is because diffutils simply
176          * cannot compare large files. And large files are usually binary files.
177          */
178         int m_nQuickCompareLimit;
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
192         bool m_bRecursive; /**< Do we include subfolders to compare? */
193         bool m_bPluginsEnabled; /**< Are plugins enabled? */
194         boost::scoped_ptr<FilterList> m_pFilterList; /**< Filter list for line filters */
195         CDiffWrapper *m_pDiffWrapper;
196
197 private:
198         /**
199          * The main compare method used.
200          * This is the main compare method set when compare is started. There
201          * can be temporary switches to other method (e.g. for large file) but
202          * this main method must be set back for next file.
203          */
204         int m_nCompMethod;
205
206         boost::scoped_ptr<DIFFOPTIONS> m_pOptions; /**< Generalized compare options. */
207         boost::scoped_ptr<CompareOptions> m_pContentCompareOptions; /**< Per compare method compare options. */
208         boost::scoped_ptr<CompareOptions> m_pQuickCompareOptions;   /**< Per compare method compare options. */
209         PathContext m_paths; /**< (root) paths for this context */
210         IAbortable *m_piAbortable; /**< Interface for aborting the compare. */
211         Poco::FastMutex m_mutex;
212 };
213
214 #endif // !defined(AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_)