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