4 * @brief Declarations of CDiffContext and diff structures
6 // ID line follows -- this is updated by SVN
7 // $Id: DiffContext.h 6910 2009-07-12 09:06:54Z kimmov $
9 #if !defined(AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_)
10 #define AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_
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"
31 /** Interface to a provider of plugin info */
35 virtual void FetchPluginInfos(const String& filteredFilenames,
36 PackingInfo ** infoUnpacker,
37 PrediffingInfo ** infoPrediffer) = 0;
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.
47 * @note If you add new member variables, remember to copy values in
48 * CDiffContext::CDiffContext(..,CDiffContext) constructor!
50 class CDiffContext : public DiffItemList
53 /** @brief Special values for difference counts. */
56 DIFFS_UNKNOWN = -1, /**< Difference count unknown (generally). */
57 DIFFS_UNKNOWN_QUICKCOMPARE = -9, /**< Unknown because of quick-compare method. */
60 CDiffContext(const PathContext & paths, int compareMethod);
63 void UpdateVersion(DIFFITEM & di, int nIndex) const;
66 * Get the main compare method used in this compare.
67 * @return Compare method used.
69 int GetCompareMethod(void) const { return m_nCompMethod; }
73 * @name Path accessor functions.
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).
81 * Get left-side compare path.
82 * @return full path in left-side.
84 String GetLeftPath() const { return m_paths.GetLeft(false); }
85 String GetMiddlePath() const { return m_paths.GetMiddle(false); }
87 * Get right-side compare path.
88 * @return full path in right-side.
90 String GetRightPath() const { return m_paths.GetRight(false); }
91 String GetPath(int nIndex) const { return m_paths.GetPath(nIndex, false); }
93 * Get left-side compare path in normalized form.
94 * @return full path in left-side.
96 String GetNormalizedLeft() const { return m_paths.GetLeft(); }
97 String GetNormalizedMiddle() const { return m_paths.GetMiddle(); }
99 * Get right-side compare path in normalized form.
100 * @return full path in left-side.
102 String GetNormalizedRight() const { return m_paths.GetRight(); }
103 String GetNormalizedPath(int nIndex) const { return m_paths.GetPath(nIndex, true); }
104 PathContext GetNormalizedPaths() const
107 for (int nIndex = 0; nIndex < m_paths.GetSize(); nIndex++)
108 paths.SetPath(nIndex, m_paths.GetPath(nIndex, true));
113 // change an existing difference
114 bool UpdateInfoFromDiskHalf(DIFFITEM & di, int nIndex);
115 void UpdateStatusFromDisk(Poco::UIntPtr diffpos, int index);
117 bool CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
118 CompareOptions * GetCompareOptions(int compareMethod);
120 // retrieve or manufacture plugin info for specified file comparison
121 void FetchPluginInfos(const String& filteredFilenames,
122 PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
126 * @name Compare aborting interface.
127 * These functions handle compare aborting using IAbortable interface.
129 bool ShouldAbort() const;
132 * Set pointer to IAbortable interface.
133 * This function sets pointer to interface used to abort the compare when
135 * @param [in] piAbortable Pointer to interface.
137 void SetAbortable(IAbortable * piAbortable) { m_piAbortable = piAbortable; }
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.
144 const IAbortable * GetAbortable() const { return m_piAbortable; }
147 int GetCompareDirs() const { return m_paths.GetSize(); }
149 IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
150 IPluginInfos * m_piPluginInfos;
151 int m_iGuessEncodingType;
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.
159 Poco::ThreadLocal<int> m_nCurrentCompMethod;
161 bool m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
162 CompareStats *m_pCompareStats; /**< Pointer to compare statistics */
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.
170 bool m_bStopAfterFirstDiff;
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.
178 int m_nQuickCompareLimit;
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.
187 * This value is true by default.
190 bool m_bIgnoreReparsePoints;
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;
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.
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;
214 #endif // !defined(AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_)