OSDN Git Service

Don't pass `DIFFITEM *` by casting to `uintptr_t` (1)
authorGreyMerlin <greymerlin7@gmail.com>
Sat, 5 Jan 2019 21:01:22 +0000 (13:01 -0800)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 16 Jan 2019 14:32:56 +0000 (23:32 +0900)
* Change DIFFITEM from `struct` to `class`
* Incorporate `ListEntry` class directly into DIFFITEM
* Change handling of m_Root (now m_pRoot) and `children`
* Eliminate all casting between `DIFFITEM *` and `uintptr_t`
* Isolate all manipulation of `DIFFITEM` linkage to be within the DIFFITEM class.

* Add `#include "StdAfx.h"` and `#define new DEBUG_NEW` to a few files
* Cleanup various related comments
* Eliminate the `ListEntry.h` file.  Also, it was never part of the project's Solution Explorer
tree.

30 files changed:
Src/7zCommon.h
Src/CompareEngines/BinaryCompare.h
Src/CompareEngines/TimeSizeCompare.h
Src/CompareStats.h
Src/DiffContext.cpp
Src/DiffContext.h
Src/DiffFileData.cpp
Src/DiffFileInfo.cpp
Src/DiffItem.cpp
Src/DiffItem.h
Src/DiffItemList.cpp
Src/DiffItemList.h
Src/DiffThread.cpp
Src/DirActions.cpp
Src/DirActions.h
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirItem.cpp
Src/DirItemIterator.h
Src/DirScan.cpp
Src/DirScan.h
Src/DirTravel.cpp
Src/DirView.cpp
Src/DirView.h
Src/DirViewColItems.cpp
Src/DirViewColItems.h
Src/FolderCmp.cpp
Src/HexMergeDoc.cpp
Src/ListEntry.h [deleted file]
Src/Test.cpp

index 72588c7..2df616e 100644 (file)
@@ -13,7 +13,7 @@
 
 class CDirView;
 class CListCtrl;
-struct DIFFITEM;
+class DIFFITEM;
 
 extern __declspec(thread) Merge7z::Proxy Merge7z;
 
index 32c04dd..984a876 100644 (file)
@@ -5,7 +5,7 @@
  */
 #pragma once
 
-struct DIFFITEM;
+class DIFFITEM;
 class PathContext;
 
 namespace CompareEngines
index 9988214..a3750c2 100644 (file)
@@ -5,7 +5,7 @@
  */
 #pragma once
 
-struct DIFFITEM;
+class DIFFITEM;
 
 namespace CompareEngines
 {
index cd5b6b9..381d3ad 100644 (file)
@@ -11,7 +11,7 @@
 #include <vector>
 #include <array>
 
-struct DIFFITEM;
+class DIFFITEM;
 
 /**
  * @brief Class holding directory compare stats.
index c26065b..2efd2fc 100644 (file)
@@ -24,6 +24,7 @@
  *  @brief Implementation of CDiffContext
  */ 
 
+#include "StdAfx.h"
 #include "DiffContext.h"
 #include <Poco/ScopedLock.h>
 #include "CompareOptions.h"
 #include "IAbortable.h"
 #include "DiffWrapper.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 using Poco::FastMutex;
 
 //////////////////////////////////////////////////////////////////////
@@ -87,7 +92,7 @@ CDiffContext::~CDiffContext()
  * @param [in] diffpos DIFFITEM to update.
  * @param [in] nIndex index to update 
  */
-void CDiffContext::UpdateStatusFromDisk(uintptr_t diffpos, int nIndex)
+void CDiffContext::UpdateStatusFromDisk(DIFFITEM *diffpos, int nIndex)
 {
        DIFFITEM &di = GetDiffRefAt(diffpos);
        di.diffFileInfo[nIndex].ClearPartial();
@@ -103,7 +108,7 @@ void CDiffContext::UpdateStatusFromDisk(uintptr_t diffpos, int nIndex)
  * @param [in] nIndex index to update
  * @return true if file exists
  */
-bool CDiffContext::UpdateInfoFromDiskHalf(DIFFITEM & di, int nIndex)
+bool CDiffContext::UpdateInfoFromDiskHalf(DIFFITEM &di, int nIndex)
 {
        String filepath = paths::ConcatPath(paths::ConcatPath(m_paths[nIndex], di.diffFileInfo[nIndex].path), di.diffFileInfo[nIndex].filename);
        DiffFileInfo & dfi = di.diffFileInfo[nIndex];
@@ -142,7 +147,7 @@ static bool CheckFileForVersion(const String& ext)
  * @param [in,out] di DIFFITEM to update.
  * @param [in] bLeft If true left-side file is updated, right-side otherwise.
  */
-void CDiffContext::UpdateVersion(DIFFITEM & di, int nIndex) const
+void CDiffContext::UpdateVersion(DIFFITEM &di, int nIndex) const
 {
        DiffFileInfo & dfi = di.diffFileInfo[nIndex];
        // Check only binary files
index 939d5e7..bebca40 100644 (file)
@@ -16,7 +16,6 @@
 class PackingInfo;
 class PrediffingInfo;
 class IDiffFilter;
-struct DIFFITEM;
 class CompareStats;
 class IAbortable;
 class CDiffWrapper;
@@ -56,7 +55,7 @@ public:
        CDiffContext(const PathContext & paths, int compareMethod);
        ~CDiffContext();
 
-       void UpdateVersion(DIFFITEM & di, int nIndex) const;
+       void UpdateVersion(DIFFITEM &di, int nIndex) const;
 
        /**
         * Get the main compare method used in this compare.
@@ -107,8 +106,8 @@ public:
        //@}
 
        // change an existing difference
-       bool UpdateInfoFromDiskHalf(DIFFITEM & di, int nIndex);
-       void UpdateStatusFromDisk(uintptr_t diffpos, int nIndex);
+       bool UpdateInfoFromDiskHalf(DIFFITEM &di, int nIndex);
+       void UpdateStatusFromDisk(DIFFITEM *diffpos, int nIndex);
 
        bool CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
        CompareOptions * GetCompareOptions(int compareMethod);
index 08bb1f1..26d4803 100644 (file)
@@ -6,6 +6,7 @@
  * @date  Created: 2003-08-22
  */
 
+#include "stdafx.h"
 #include "DiffFileData.h"
 #include <io.h>
 #include <memory>
 #include "FileTransform.h"
 #include "unicoder.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
 /**
  * @brief Simple initialization of DiffFileData
  * @note Diffcounts are initialized to invalid values, not zeros.
index dbc798e..e538739 100644 (file)
  * @brief Implementation for DiffFileInfo routines
  */
 
+#include "stdafx.h"
 #include "DiffFileInfo.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 /**
  * @brief Clears FileInfo data.
  */
index 694fb91..b5af7d0 100644 (file)
@@ -4,15 +4,24 @@
  *  @brief Implementation of DIFFITEM
  */ 
 
+#include "stdafx.h"
 #include "DiffItem.h"
 #include "paths.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 DIFFITEM DIFFITEM::emptyitem;
 
 /** @brief DIFFITEM's destructor */
 DIFFITEM::~DIFFITEM()
 {
        RemoveChildren();
+       RemoveSiblings();
+       assert(children == nullptr);
+       assert(Flink == nullptr);
+       assert(Blink == nullptr);
 }
 
 /** @brief Return path to left/right file, including all but file name */
@@ -30,7 +39,7 @@ int DIFFITEM::GetDepth() const
 {
        const DIFFITEM *cur;
        int depth;
-       for (depth = 0, cur = parent; cur != nullptr; depth++, cur = cur->parent)
+       for (depth = 0, cur = parent; cur->parent != nullptr; depth++, cur = cur->parent)
                ;
        return depth;
 }
@@ -41,7 +50,7 @@ int DIFFITEM::GetDepth() const
 bool DIFFITEM::IsAncestor(const DIFFITEM *pdi) const
 {
        const DIFFITEM *cur;
-       for (cur = this; cur != nullptr; cur = cur->parent)
+       for (cur = this; cur->parent != nullptr; cur = cur->parent)
        {
                if (cur->parent == pdi)
                        return true;
@@ -49,21 +58,27 @@ bool DIFFITEM::IsAncestor(const DIFFITEM *pdi) const
        return false;
 }
 
-/** @brief Return whether the current item has children */
-bool DIFFITEM::HasChildren() const
+/** @brief Remove and delete all sibling DIFFITEM entries, via Flink */
+void DIFFITEM::RemoveSiblings()
 {
-       DIFFITEM *p = static_cast<DIFFITEM *>(children.IsSibling(children.Flink));
-       return (p != nullptr) ? true : false;
+       DIFFITEM *pRem = Flink;
+       while (pRem != nullptr)
+       {
+               assert(pRem->parent == parent);
+               assert(pRem->Blink == this);
+               DIFFITEM *pNext = pRem->Flink;
+               pRem->RemoveSelf();     // destroys Flink (so we use pRem instead)
+               delete pRem;
+               pRem = pNext;
+       }
+       RemoveSelf();
 }
 
+/** @brief Remove and delete all children DIFFITEM entries */
 void DIFFITEM::RemoveChildren()
 {
-       while (HasChildren())
-       {
-               DIFFITEM *p = static_cast<DIFFITEM *>(children.Flink);
-               p->RemoveSelf();
-               delete p;
-       }
+       delete children;
+       children = nullptr;
 }
 
 void DIFFITEM::Swap(int idx1, int idx2)
@@ -72,7 +87,79 @@ void DIFFITEM::Swap(int idx1, int idx2)
        diffcode.swap(idx1, idx2);
        if (HasChildren())
        {
-               for (ListEntry *p = children.IsSibling(children.Flink); p != nullptr; p = children.IsSibling(p->Flink))
-                       static_cast<DIFFITEM *>(p)->Swap(idx1, idx2);
+               for (DIFFITEM *p = children; p != nullptr; p = p->Flink)
+                       p->Swap(idx1, idx2);
        }
 }
+
+
+/* static */
+DIFFITEM *DIFFITEM::GetEmptyItem()  
+{ 
+       // TODO: It would be better if there were individual items
+       // (for whatever these special items are?) because here we 
+       // have to *hope* client does not modify this static (shared) item
+
+       assert(emptyitem.parent == nullptr);
+       assert(emptyitem.Flink == nullptr);
+       assert(emptyitem.Blink == nullptr);
+       assert(emptyitem.children == nullptr);
+
+       return &emptyitem; 
+}
+
+/**
+* @brief Add Sibling item
+* @param [in] p The item to be added
+*/
+void DIFFITEM::Append(DIFFITEM *p)
+{
+       assert(parent->children == this);
+
+       // Two situations
+
+       if (Blink == nullptr)
+       {
+               // Insert first sibling (besides ourself)
+               assert(Flink == nullptr);
+               p->Flink = nullptr;
+               p->Blink = this;
+               Flink = p;
+       }
+       else
+       {
+               // Insert additional siblings
+               assert(Flink != nullptr);
+               p->Flink = nullptr;
+               p->Blink = Blink;
+               Blink->Flink = p;
+       }
+       Blink = p;
+}
+void DIFFITEM::RemoveSelf()
+{
+       if (parent != nullptr && parent->children != nullptr)
+       {
+               // If `this` is at end of Sibling linkage, fix First Child's end link
+               if (parent->children->Blink == this)
+               {
+                       assert(Flink == nullptr);
+                       parent->children->Blink = Blink;
+                       if (Blink == this)
+                               Blink = nullptr;
+               }
+               // If `this` is the First Child, link parent to next Sibling
+               if (parent->children == this)
+               {
+                       parent->children = Flink;
+                       }
+       }
+       if (Blink != nullptr)
+               Blink->Flink = Flink;
+       if (Flink != nullptr)
+               Flink->Blink = Blink;
+       Flink = Blink = nullptr;
+}
+
index e8ebc69..8f787c6 100644 (file)
@@ -5,7 +5,6 @@
  */
 #pragma once
 
-#include "ListEntry.h"
 #include "DiffFileInfo.h"
 
 /**
@@ -172,31 +171,58 @@ public:
  * both compare sides (file/folder exists in both sides) or just from one
  * side (file/folder exists only in other side).
  *
- * This class is for backend differences processing, presenting physical
+ * This class is for backend differences processing, representing physical
  * files and folders. This class is not for GUI data like selection or
  * visibility statuses. So do not include any GUI-dependent data here. 
  */
-struct DIFFITEM : ListEntry
+
+class DIFFITEM 
 {
-       DIFFITEM *parent; /**< Parent of current item */
-       ListEntry children; /**< Head of doubly linked list for chldren */
+public:
+       DIFFITEM *parent;                               /**< Parent of current item */
+       DIFFITEM *children;                             /**< Link to first child of `this` */
 
-       DiffFileInfo diffFileInfo[3]; /**< Fileinfo for left/middle/right file */
-       int     nsdiffs; /**< Amount of non-ignored differences */
-       int nidiffs; /**< Amount of ignored differences */
-       unsigned customFlags1; /**< Custom flags set 1 */
-       DIFFCODE diffcode; /**< Compare result */
+       DiffFileInfo diffFileInfo[3];   /**< Fileinfo for left/middle/right file */
+       int     nsdiffs;                                        /**< Amount of non-ignored differences */
+       int nidiffs;                                    /**< Amount of ignored differences */
+       unsigned customFlags1;                  /**< Custom flags set 1 */
+       DIFFCODE diffcode;                              /**< Compare result */
 
-       static DIFFITEM emptyitem; /**< singleton to represent a diffitem that doesn't have any data */
 
-       DIFFITEM() : parent(nullptr), nidiffs(-1), nsdiffs(-1), customFlags1(0) { }
+       DIFFITEM() : parent(nullptr), children(nullptr), nidiffs(-1), nsdiffs(-1), customFlags1(0), 
+                                       Flink(nullptr), Blink(nullptr) {}
        ~DIFFITEM();
 
-       bool isEmpty() const { return this == &emptyitem; }
        String getFilepath(int nIndex, const String &sRoot) const;
        int GetDepth() const;
        bool IsAncestor(const DIFFITEM *pdi) const;
-       bool HasChildren() const;
        void RemoveChildren();
        void Swap(int idx1, int idx2);
+
+       void Append(DIFFITEM *p);
+       void RemoveSelf();
+
+       inline DIFFITEM *GetFwdSiblingLink() const { return Flink; }
+
+       /** @brief Return whether the current DIFFITEM has children */
+       inline bool DIFFITEM::HasChildren() const
+       {
+               return (children != nullptr);
+       }
+
+       static DIFFITEM *GetEmptyItem();
+       bool isEmpty() const { return this == GetEmptyItem(); /* to invoke "emptiness" checking */ }
+
+
+protected:
+       void RemoveSiblings();
+
+       DIFFITEM *Flink;                                /**< Forward "sibling" link.  The forward linkage ends with 
+                                                                               a `nullptr` in the final (newest) item. */
+       DIFFITEM *Blink;                                /**< Backward "sibling" link.  The backward linkage is circular,
+                                                                               with the first (oldest) item (pointed to by `this->parent->children`)
+                                                                               pointing to the last (newest) item. */
+
+       static DIFFITEM emptyitem;              /**< singleton to represent a DIFFITEM that doesn't have any data */
 };
\ No newline at end of file
index 8f5e7f9..4280316 100644 (file)
@@ -4,13 +4,18 @@
  *  @brief Implementation of DiffItemList
  */ 
 
+#include "stdafx.h"
 #include "DiffItemList.h"
 #include <cassert>
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 /**
  * @brief Constructor
  */
-DiffItemList::DiffItemList()
+DiffItemList::DiffItemList() : m_pRoot(nullptr)
 {
 }
 
@@ -24,120 +29,120 @@ DiffItemList::~DiffItemList()
 
 /**
  * @brief Add new diffitem to structured DIFFITEM tree.
- * @param [in] parent Parent item, or `nullptr` if no parent.
+ * @param [in] par Parent item, or `nullptr` if no parent.
  * @return Pointer to the added item.
  */
-DIFFITEM* DiffItemList::AddDiff(DIFFITEM *parent)
+DIFFITEM *DiffItemList::AddNewDiff(DIFFITEM *par)
 {
+       if (par == nullptr)
+       {
+               // if there is no `parent`, this item becomes a child of m_pRoot
+               assert(m_pRoot != nullptr);
+               par = m_pRoot;
+       }
+
        DIFFITEM *p = new DIFFITEM;
-       if (parent != nullptr)
-               parent->children.Append(p);
+       // if there is a `parent`, this item becomes a child of that parent
+       p->parent = par;
+       if (par->children == nullptr)
+               par->children = p;
        else
-               m_root.Append(p);
-       p->parent = parent;
+               par->children->Append(p);
+
        return p;
 }
 
 /**
- * @brief Remove diffitem from structured DIFFITEM tree
- * @param diffpos position of item to remove
+ * @brief Empty structured DIFFITEM tree
  */
-void DiffItemList::RemoveDiff(uintptr_t diffpos)
+void DiffItemList::RemoveAll()
 {
-       DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
-       p->RemoveSelf();
-       delete p;
+       delete m_pRoot;
+       m_pRoot = nullptr;
 }
 
-/**
- * @brief Empty structured DIFFITEM tree
- */
-void DiffItemList::RemoveAll()
+void DiffItemList::InitDiffItemList()
 {
-       while (m_root.IsSibling(m_root.Flink))
-               RemoveDiff((uintptr_t)m_root.Flink);
+       assert(m_pRoot == nullptr);
+       m_pRoot = new DIFFITEM;
 }
 
 /**
  * @brief Get position of first item in structured DIFFITEM tree
  */
-uintptr_t DiffItemList::GetFirstDiffPosition() const
+DIFFITEM *DiffItemList::GetFirstDiffPosition() const
 {
-       return (uintptr_t)m_root.IsSibling(m_root.Flink);
+       return m_pRoot->children;
 }
 
 /**
  * @brief Get position of first child item in structured DIFFITEM tree
- * @param  parentdiffpos [in] Position of parent diff item 
- * @return Position of first child item
+ * @param  [in] par Position of parent diff item (maybe `nullptr`)
+ * @return Position of first child item (or `nullptr` if no children)
  */
-uintptr_t DiffItemList::GetFirstChildDiffPosition(uintptr_t parentdiffpos) const
+DIFFITEM *DiffItemList::GetFirstChildDiffPosition(const DIFFITEM *par) const
 {
-       DIFFITEM *parent = reinterpret_cast<DIFFITEM *>(parentdiffpos);
-       if (parent != nullptr)
-               return (uintptr_t)parent->children.IsSibling(parent->children.Flink);
+       if (par != nullptr)
+               return par->children;
        else
-               return (uintptr_t)m_root.IsSibling(m_root.Flink);
+               return m_pRoot->children;
 }
 
 /**
  * @brief Get position of next item in structured DIFFITEM tree
- * @param diffpos position of current item, updated to next item position
- * @return Diff Item in current position
+ * @param [in,out] diffpos Position of current item, updated to next item position
+ * @return Diff Item (by reference) in current position
  */
-const DIFFITEM &DiffItemList::GetNextDiffPosition(uintptr_t & diffpos) const
+const DIFFITEM &DiffItemList::GetNextDiffPosition(DIFFITEM *&diffpos) const
 {
-       DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
-       if (p->HasChildren())
+       DIFFITEM *p = diffpos;
+       if (diffpos->HasChildren())
        {
                diffpos = GetFirstChildDiffPosition(diffpos);
        }
        else
        {
-               DIFFITEM *cur = p;
+               DIFFITEM *cur = diffpos;
                do
                {
-                       if (cur->parent != nullptr)
-                               diffpos = (uintptr_t)cur->parent->children.IsSibling(cur->Flink);
-                       else
-                               diffpos = (uintptr_t)m_root.IsSibling(cur->Flink);
+                       diffpos = cur->GetFwdSiblingLink();
                        cur = cur->parent;
-               } while (!diffpos && cur != nullptr);
+                       assert(cur != nullptr);
+               } while (diffpos == nullptr && cur->parent != nullptr);
        }
        return *p;
 }
 
 /**
  * @brief Get position of next item in structured DIFFITEM tree
- * @param diffpos position of current item, updated to next item position
+ * @param [in,out] diffpos Position of current item, updated to next item position
  * @return Diff Item (by reference) in current position
  */
-DIFFITEM &DiffItemList::GetNextDiffRefPosition(uintptr_t & diffpos)
+DIFFITEM &DiffItemList::GetNextDiffRefPosition(DIFFITEM *&diffpos)
 {
        return (DIFFITEM &)GetNextDiffPosition(diffpos);
 }
 
 /**
  * @brief Get position of next sibling item in structured DIFFITEM tree
- * @param diffpos position of current item, updated to next sibling item position
- * @return Diff Item in current position
+ * @param [in,out] diffpos Position of current item, updated to next sibling item position
+ * @return Diff Item (by reference) in current position
  */
-const DIFFITEM &DiffItemList::GetNextSiblingDiffPosition(uintptr_t & diffpos) const
+const DIFFITEM &DiffItemList::GetNextSiblingDiffPosition(DIFFITEM *&diffpos) const
 {
-       DIFFITEM *p = reinterpret_cast<DIFFITEM *>(diffpos);
-       if (p->parent != nullptr)
-               diffpos = (uintptr_t)p->parent->children.IsSibling(p->Flink);
-       else
-               diffpos = (uintptr_t)m_root.IsSibling(p->Flink);
+       DIFFITEM *p = diffpos;
+       diffpos = p->GetFwdSiblingLink();
+       assert(p==nullptr || diffpos==nullptr || p->parent == diffpos->parent);
+       assert(p->parent != nullptr);
        return *p;
 }
 
 /**
  * @brief Get position of next sibling item in structured DIFFITEM tree
- * @param diffpos position of current item, updated to next sibling item position
+ * @param [in,out] diffpos Position of current item, updated to next sibling item position
  * @return Diff Item (by reference) in current position
  */
-DIFFITEM &DiffItemList::GetNextSiblingDiffRefPosition(uintptr_t & diffpos)
+DIFFITEM &DiffItemList::GetNextSiblingDiffRefPosition(DIFFITEM *&diffpos)
 {
        return (DIFFITEM &)GetNextSiblingDiffPosition(diffpos);
 }
@@ -155,10 +160,10 @@ DIFFITEM &DiffItemList::GetNextSiblingDiffRefPosition(uintptr_t & diffpos)
  * SetDiffStatusCode(pos, DIFFCODE::SAME+DIFFCODE::BOTH, DIFFCODE::COMPAREFLAGS+DIFFCODE::SIDEFLAG);
  *  changes the comparison result to be the same and the side status to be both
  */
-void DiffItemList::SetDiffStatusCode(uintptr_t diffpos, unsigned diffcode, unsigned mask)
+void DiffItemList::SetDiffStatusCode(DIFFITEM *diffpos, unsigned diffcode, unsigned mask)
 {
-       assert(diffpos != NULL);
-       DIFFITEM & di = GetDiffRefAt(diffpos);
+       assert(diffpos != nullptr);
+       DIFFITEM &di = GetDiffRefAt(diffpos);
        assert( ((~mask) & diffcode) == 0 ); // make sure they only set flags in their mask
        di.diffcode.diffcode &= (~mask); // remove current data
        di.diffcode.diffcode |= diffcode; // add new data
@@ -167,10 +172,10 @@ void DiffItemList::SetDiffStatusCode(uintptr_t diffpos, unsigned diffcode, unsig
 /**
  * @brief Update difference counts.
  */
-void DiffItemList::SetDiffCounts(uintptr_t diffpos, unsigned diffs, unsigned ignored)
+void DiffItemList::SetDiffCounts(DIFFITEM *diffpos, unsigned diffs, unsigned ignored)
 {
-       assert(diffpos != NULL);
-       DIFFITEM & di = GetDiffRefAt(diffpos);
+       assert(diffpos != nullptr);
+       DIFFITEM &di = GetDiffRefAt(diffpos);
        di.nidiffs = ignored; // see StoreDiffResult() in DirScan.cpp
        di.nsdiffs = diffs;
 }
@@ -180,10 +185,10 @@ void DiffItemList::SetDiffCounts(uintptr_t diffpos, unsigned diffs, unsigned ign
  * @param [in] diffpos Position of item.
  * @return Custom flags from item.
  */
-unsigned DiffItemList::GetCustomFlags1(uintptr_t diffpos) const
+unsigned DiffItemList::GetCustomFlags1(DIFFITEM *diffpos) const
 {
-       assert(diffpos != NULL);
-       const DIFFITEM & di = GetDiffAt(diffpos);
+       assert(diffpos != nullptr);
+       const DIFFITEM &di = GetDiffAt(diffpos);
        return di.customFlags1;
 }
 
@@ -192,15 +197,16 @@ unsigned DiffItemList::GetCustomFlags1(uintptr_t diffpos) const
  * @param [in] diffpos Position of item.
  * @param [in] flag Value of flag to set.
  */
-void DiffItemList::SetCustomFlags1(uintptr_t diffpos, unsigned flag)
+void DiffItemList::SetCustomFlags1(DIFFITEM *diffpos, unsigned flag)
 {
-       assert(diffpos != NULL);
-       DIFFITEM & di = GetDiffRefAt(diffpos);
+       assert(diffpos != nullptr);
+       DIFFITEM &di = GetDiffRefAt(diffpos);
        di.customFlags1 = flag;
 }
 
 void DiffItemList::Swap(int idx1, int idx2)
 {
-       for (ListEntry *p = m_root.IsSibling(m_root.Flink); p != nullptr; p = m_root.IsSibling(p->Flink))
-               static_cast<DIFFITEM *>(p)->Swap(idx1, idx2);
+       assert(m_pRoot != nullptr);
+       for (DIFFITEM *p = m_pRoot->children; p != nullptr; p = p->GetFwdSiblingLink())
+               p->Swap(idx1, idx2);
 }
index d93628e..0b0c1b1 100644 (file)
@@ -20,45 +20,45 @@ public:
        DiffItemList();
        ~DiffItemList();
        // add & remove differences
-       DIFFITEM *AddDiff(DIFFITEM *parent);
-       void RemoveDiff(uintptr_t diffpos);
+       DIFFITEM *AddNewDiff(DIFFITEM *parent);
        void RemoveAll();
+       void InitDiffItemList();
 
        // to iterate over all differences on list
-       uintptr_t GetFirstDiffPosition() const;
-       uintptr_t GetFirstChildDiffPosition(uintptr_t parentdiffpos) const;
-       const DIFFITEM & GetNextDiffPosition(uintptr_t & diffpos) const;
-       DIFFITEM & GetNextDiffRefPosition(uintptr_t & diffpos);
-       const DIFFITEM & GetNextSiblingDiffPosition(uintptr_t & diffpos) const;
-       DIFFITEM &GetNextSiblingDiffRefPosition(uintptr_t & diffpos);
-       const DIFFITEM & GetDiffAt(uintptr_t diffpos) const;
-       DIFFITEM & GetDiffRefAt(uintptr_t diffpos);
+       DIFFITEM *GetFirstDiffPosition() const;
+       DIFFITEM *GetFirstChildDiffPosition(const DIFFITEM *par) const;
+       const DIFFITEM &GetNextDiffPosition(DIFFITEM *&diffpos) const;
+       DIFFITEM &GetNextDiffRefPosition(DIFFITEM *&diffpos);
+       const DIFFITEM &GetNextSiblingDiffPosition(DIFFITEM *&diffpos) const;
+       DIFFITEM &GetNextSiblingDiffRefPosition(DIFFITEM *&diffpos);
+       const DIFFITEM &GetDiffAt(DIFFITEM *diffpos) const;
+       DIFFITEM &GetDiffRefAt(DIFFITEM *diffpos);
 
-       void SetDiffStatusCode(uintptr_t diffpos, unsigned diffcode, unsigned mask);
-       void SetDiffCounts(uintptr_t diffpos, unsigned diffs, unsigned ignored);
-       unsigned GetCustomFlags1(uintptr_t diffpos) const;
-       void SetCustomFlags1(uintptr_t diffpos, unsigned flag);
+       void SetDiffStatusCode(DIFFITEM *diffpos, unsigned diffcode, unsigned mask);
+       void SetDiffCounts(DIFFITEM *diffpos, unsigned diffs, unsigned ignored);
+       unsigned GetCustomFlags1(DIFFITEM *diffpos) const;
+       void SetCustomFlags1(DIFFITEM *diffpos, unsigned flag);
 
        void Swap(int idx1, int idx2);
 
 protected:
-       ListEntry m_root; /**< Root of list of diffitems */
+       DIFFITEM* m_pRoot; /**< Root of list of diffitems; initially `nullptr`. */
 };
 
 /**
  * @brief Get copy of Diff Item at given position in difflist.
  * @param diffpos position of item to return
  */
-inline const DIFFITEM & DiffItemList::GetDiffAt(uintptr_t diffpos) const
+inline const DIFFITEM &DiffItemList::GetDiffAt(DIFFITEM *diffpos) const
 {
-       return *reinterpret_cast<DIFFITEM *>(diffpos);
+       return *diffpos;
 }
 
 /**
  * @brief Get Diff Item (by reference) at given position in difflist.
  * @param diffpos position of item to return
  */
-inline DIFFITEM & DiffItemList::GetDiffRefAt(uintptr_t diffpos)
+inline DIFFITEM &DiffItemList::GetDiffRefAt(DIFFITEM *diffpos)
 {
-       return *reinterpret_cast<DIFFITEM *>(diffpos);
+       return *diffpos;
 }
index c7750a2..fa39a82 100644 (file)
@@ -20,6 +20,7 @@
  * @brief Code for DiffThread class
  */
 
+#include "stdafx.h"
 #include "DiffThread.h"
 #include <cassert>
 #include <climits>
 #include "CompareStats.h"
 #include "IAbortable.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 using Poco::Thread;
 using Poco::Semaphore;
 
@@ -117,7 +122,7 @@ unsigned CDiffThread::CompareDirectories()
                m_threads[0].start(DiffThreadCollect, m_pDiffParm.get());
        else
        {
-               int nItems = DirScan_UpdateMarkedItems(m_pDiffParm.get(), 0);
+               int nItems = DirScan_UpdateMarkedItems(m_pDiffParm.get(), nullptr);
                // Send message to UI to update
                int event = CDiffThread::EVENT_COLLECT_COMPLETED;
                m_pDiffParm->m_listeners.notify(m_pDiffParm.get(), event);
@@ -174,7 +179,7 @@ static void DiffThreadCollect(void *pParam)
        DirScan_GetItems(paths, subdir, myStruct,
                        casesensitive, depth, nullptr, myStruct->context->m_bWalkUniques);
 
-       // ReleaseSemaphore() once again to signal that collect phase is ready
+       // Release Semaphore() once again to signal that collect phase is ready
        myStruct->pSemaphore->set();
 
        // Send message to UI to update
@@ -201,9 +206,9 @@ static void DiffThreadCompare(void *pParam)
 
        // Now do all pending file comparisons
        if (myStruct->bOnlyRequested)
-               DirScan_CompareRequestedItems(myStruct, 0);
+               DirScan_CompareRequestedItems(myStruct, nullptr);
        else
-               DirScan_CompareItems(myStruct, 0);
+               DirScan_CompareItems(myStruct, nullptr);
 
        myStruct->context->m_pCompareStats->SetCompareState(CompareStats::STATE_IDLE);
 
index 0338741..76c9bc4 100644 (file)
@@ -13,6 +13,7 @@
 // One idea would be to provide an iterator over them.
 //
 
+#include "stdafx.h"
 #include "DirActions.h"
 #include "MergeApp.h"
 #include "UnicodeString.h"
 #include "locality.h"
 #include "FileFilterHelper.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 static void ThrowConfirmCopy(const CDiffContext& ctxt, int origin, int destination, int count,
                const String& src, const String& dest, bool destIsSide);
 static void ThrowConfirmMove(const CDiffContext& ctxt, int origin, int destination, int count,
@@ -272,9 +277,9 @@ UPDATEITEM_TYPE UpdateDiffAfterOperation(const FileActionItem & act, CDiffContex
        }
 
        if (bUpdateSrc)
-               ctxt.UpdateStatusFromDisk(reinterpret_cast<uintptr_t>(&di), act.UIOrigin);
+               ctxt.UpdateStatusFromDisk(&di, act.UIOrigin);
        if (bUpdateDest)
-               ctxt.UpdateStatusFromDisk(reinterpret_cast<uintptr_t>(&di), act.UIDestination);
+               ctxt.UpdateStatusFromDisk(&di, act.UIDestination);
 
        if (bRemoveItem)
                return UPDATEITEM_REMOVE;
@@ -288,7 +293,7 @@ UPDATEITEM_TYPE UpdateDiffAfterOperation(const FileActionItem & act, CDiffContex
  * @return POSITION to item, `nullptr` if not found.
  * @note Filenames must be same, if they differ `nullptr` is returned.
  */
-uintptr_t FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths)
+DIFFITEM *FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths)
 {
        int nBuffer;
        String file[3], path[3], base;
@@ -313,10 +318,10 @@ uintptr_t FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths)
        if (static_cast<size_t>(std::count(file, file + paths.size(), file[0])) < paths.size())
                return 0;
 
-       uintptr_t pos = ctxt.GetFirstDiffPosition();
+       DIFFITEM *pos = ctxt.GetFirstDiffPosition();
        if (paths.size() == 2)
        {
-               while (uintptr_t currentPos = pos) // Save our current pos before getting next
+               while (DIFFITEM *currentPos = pos) // Save our current pos before getting next
                {
                        const DIFFITEM &di = ctxt.GetNextDiffPosition(pos);
                        if (di.diffFileInfo[0].path == path[0] &&
@@ -330,7 +335,7 @@ uintptr_t FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths)
        }
        else
        {
-               while (uintptr_t currentPos = pos) // Save our current pos before getting next
+               while (DIFFITEM *currentPos = pos) // Save our current pos before getting next
                {
                        const DIFFITEM &di = ctxt.GetNextDiffPosition(pos);
                        if (di.diffFileInfo[0].path == path[0] &&
@@ -348,7 +353,7 @@ uintptr_t FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths)
 }
 
 /// is it possible to copy item to left ?
-bool IsItemCopyable(const DIFFITEM & di, int index)
+bool IsItemCopyable(const DIFFITEM &di, int index)
 {
        // don't let them mess with error items
        if (di.diffcode.isResultError()) return false;
@@ -361,7 +366,7 @@ bool IsItemCopyable(const DIFFITEM & di, int index)
 }
 
 /// is it possible to delete item ?
-bool IsItemDeletable(const DIFFITEM & di, int index)
+bool IsItemDeletable(const DIFFITEM &di, int index)
 {
        // don't let them mess with error items
        if (di.diffcode.isResultError()) return false;
@@ -372,7 +377,7 @@ bool IsItemDeletable(const DIFFITEM & di, int index)
 }
 
 /// is it possible to delete both items ?
-bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM & di)
+bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM &di)
 {
        // don't let them mess with error items
        if (di.diffcode.isResultError()) return false;
@@ -385,7 +390,7 @@ bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM & di)
 }
 
 /// is it possible to compare these two items?
-bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM & di1, const DIFFITEM & di2)
+bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM &di1, const DIFFITEM &di2)
 {
        String sLeftBasePath = ctxt.GetPath(0);
        String sRightBasePath = ctxt.GetPath(1);
@@ -434,7 +439,7 @@ bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, con
        return false;
 }
 /// is it possible to compare these three items?
-bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM & di1, const DIFFITEM & di2, const DIFFITEM & di3)
+bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFITEM &di2, const DIFFITEM &di3)
 {
        String sLeftBasePath = ctxt.GetPath(0);
        String sMiddleBasePath = ctxt.GetPath(1);
@@ -492,7 +497,7 @@ bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM & di1, const DIFF
        return false;
 }
 /// is it possible to open item ?
-bool IsItemOpenableOn(const DIFFITEM & di, int index)
+bool IsItemOpenableOn(const DIFFITEM &di, int index)
 {
        // impossible if not existing
        if (!di.diffcode.exists(index)) return false;
@@ -502,12 +507,12 @@ bool IsItemOpenableOn(const DIFFITEM & di, int index)
 }
 
 /// is it possible to open left ... item ?
-bool IsItemOpenableOnWith(const DIFFITEM & di, int index)
+bool IsItemOpenableOnWith(const DIFFITEM &di, int index)
 {
        return (!di.diffcode.isDirectory() && IsItemOpenableOn(di, index));
 }
 /// is it possible to copy to... left item?
-bool IsItemCopyableToOn(const DIFFITEM & di, int index)
+bool IsItemCopyableToOn(const DIFFITEM &di, int index)
 {
        // impossible if only on right
        if (!di.diffcode.exists(index)) return false;
@@ -517,7 +522,7 @@ bool IsItemCopyableToOn(const DIFFITEM & di, int index)
 }
 
 // When navigating differences, do we stop at this one ?
-bool IsItemNavigableDiff(const CDiffContext& ctxt, const DIFFITEM & di)
+bool IsItemNavigableDiff(const CDiffContext& ctxt, const DIFFITEM &di)
 {
        // Not a valid diffitem, one of special items (e.g "..")
        if (di.diffcode.diffcode == 0)
@@ -529,7 +534,7 @@ bool IsItemNavigableDiff(const CDiffContext& ctxt, const DIFFITEM & di)
        return true;
 }
 
-bool IsItemExistAll(const CDiffContext& ctxt, const DIFFITEM & di)
+bool IsItemExistAll(const CDiffContext& ctxt, const DIFFITEM &di)
 {
        // Not a valid diffitem, one of special items (e.g "..")
        if (di.diffcode.diffcode == 0)
@@ -550,7 +555,7 @@ bool IsItemExistAll(const CDiffContext& ctxt, const DIFFITEM & di)
  * @return true if item should be shown, false if not.
  * @sa CDirDoc::Redisplay()
  */
-bool IsShowable(const CDiffContext& ctxt, const DIFFITEM & di, const DirViewFilterSettings& filter)
+bool IsShowable(const CDiffContext& ctxt, const DIFFITEM &di, const DirViewFilterSettings& filter)
 {
        if (di.customFlags1 & ViewCustomFlags::HIDDEN)
                return false;
@@ -621,8 +626,8 @@ bool IsShowable(const CDiffContext& ctxt, const DIFFITEM & di, const DirViewFilt
                                        return false;
                                if (di.diffcode.isResultDiff() && !filter.show_different)
                                {
-                                       uintptr_t diffpos = ctxt.GetFirstChildDiffPosition(reinterpret_cast<uintptr_t>(&di));
-                                       while (diffpos)
+                                       DIFFITEM *diffpos = ctxt.GetFirstChildDiffPosition(&di);
+                                       while (diffpos != nullptr)
                                        {
                                                const DIFFITEM &dic = ctxt.GetNextSiblingDiffPosition(diffpos);
                                                if (IsShowable(ctxt, dic, filter))
@@ -676,7 +681,7 @@ bool IsShowable(const CDiffContext& ctxt, const DIFFITEM & di, const DirViewFilt
  * @param [in,out] isDir Is item folder?
  * return false if there was error or item was completely processed.
  */
-bool GetOpenOneItem(const CDiffContext& ctxt, uintptr_t pos1, const DIFFITEM *pdi[3],
+bool GetOpenOneItem(const CDiffContext& ctxt, DIFFITEM *pos1, const DIFFITEM *pdi[3],
                PathContext & paths, int & sel1, bool & isdir, int nPane[3], String& errmsg)
 {
        pdi[0] = &ctxt.GetDiffAt(pos1);
@@ -723,7 +728,7 @@ bool GetOpenOneItem(const CDiffContext& ctxt, uintptr_t pos1, const DIFFITEM *pd
  * @param [in,out] isDir Is item folder?
  * return false if there was error or item was completely processed.
  */
-bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, uintptr_t pos1, uintptr_t pos2, const DIFFITEM *pdi[3],
+bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, DIFFITEM *pos1, DIFFITEM *pos2, const DIFFITEM *pdi[3],
                PathContext & paths, int & sel1, int & sel2, bool & isDir, int nPane[3], String& errmsg)
 {
        // Two items selected, get their info
@@ -797,7 +802,7 @@ bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, uint
  * @param [in,out] isDir Is item folder?
  * return false if there was error or item was completely processed.
  */
-bool GetOpenThreeItems(const CDiffContext& ctxt, uintptr_t pos1, uintptr_t pos2, uintptr_t pos3, const DIFFITEM *pdi[3],
+bool GetOpenThreeItems(const CDiffContext& ctxt, DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3, const DIFFITEM *pdi[3],
        PathContext & paths, int & sel1, int & sel2, int & sel3, bool & isDir, int nPane[3], String& errmsg)
 {
        String pathLeft, pathMiddle, pathRight;
@@ -935,7 +940,7 @@ bool GetOpenThreeItems(const CDiffContext& ctxt, uintptr_t pos1, uintptr_t pos2,
  * @brief Get the file names on both sides for specified item.
  * @note Return empty strings if item is special item.
  */
-void GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM & di, String& strLeft, String& strRight)
+void GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM &di, String& strLeft, String& strRight)
 {
        const String leftrelpath = paths::ConcatPath(di.diffFileInfo[0].path, di.diffFileInfo[0].filename);
        const String rightrelpath = paths::ConcatPath(di.diffFileInfo[1].path, di.diffFileInfo[1].filename);
@@ -945,12 +950,12 @@ void GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM & di, String& str
        strRight = paths::ConcatPath(rightpath, rightrelpath);
 }
 
-String GetItemFileName(const CDiffContext& ctxt, const DIFFITEM & di, int index)
+String GetItemFileName(const CDiffContext& ctxt, const DIFFITEM &di, int index)
 {
        return paths::ConcatPath(ctxt.GetPath(index), paths::ConcatPath(di.diffFileInfo[index].path, di.diffFileInfo[index].filename));
 }
 
-PathContext GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM & di)
+PathContext GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM &di)
 {
        PathContext paths;
        for (int nIndex = 0; nIndex < ctxt.GetCompareDirs(); nIndex++)
@@ -965,7 +970,7 @@ PathContext GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM & di)
 /**
  * @brief Return image index appropriate for this row
  */
-int GetColImage(const DIFFITEM & di)
+int GetColImage(const DIFFITEM &di)
 {
        // Must return an image index into image list created above in OnInitDialog
        if (di.diffcode.isResultError())
@@ -1089,9 +1094,9 @@ void SetItemViewFlag(DIFFITEM& di, unsigned flag, unsigned mask)
  */
 void SetItemViewFlag(CDiffContext& ctxt, unsigned flag, unsigned mask)
 {
-       uintptr_t pos = ctxt.GetFirstDiffPosition();
+       DIFFITEM *pos = ctxt.GetFirstDiffPosition();
 
-       while (pos != NULL)
+       while (pos != nullptr)
        {
                unsigned curFlags = ctxt.GetCustomFlags1(pos);
                curFlags &= ~mask; // Zero bits masked
@@ -1276,8 +1281,8 @@ String NumToStr(int n)
 void ExpandSubdirs(CDiffContext& ctxt, DIFFITEM& dip)
 {
        dip.customFlags1 |= ViewCustomFlags::EXPANDED;
-       uintptr_t diffpos = ctxt.GetFirstChildDiffPosition(reinterpret_cast<uintptr_t>(&dip));
-       while (diffpos)
+       DIFFITEM *diffpos = ctxt.GetFirstChildDiffPosition(&dip);
+       while (diffpos != nullptr)
        {
                DIFFITEM &di = ctxt.GetNextDiffRefPosition(diffpos);
                if (!di.IsAncestor(&dip))
@@ -1289,8 +1294,8 @@ void ExpandSubdirs(CDiffContext& ctxt, DIFFITEM& dip)
 
 void ExpandAllSubdirs(CDiffContext& ctxt)
 {
-       uintptr_t diffpos = ctxt.GetFirstDiffPosition();
-       while (diffpos)
+       DIFFITEM *diffpos = ctxt.GetFirstDiffPosition();
+       while (diffpos != nullptr)
        {
                DIFFITEM &di = ctxt.GetNextDiffRefPosition(diffpos);
                di.customFlags1 |= ViewCustomFlags::EXPANDED;
@@ -1299,8 +1304,8 @@ void ExpandAllSubdirs(CDiffContext& ctxt)
 
 void CollapseAllSubdirs(CDiffContext& ctxt)
 {
-       uintptr_t diffpos = ctxt.GetFirstDiffPosition();
-       while (diffpos)
+       DIFFITEM *diffpos = ctxt.GetFirstDiffPosition();
+       while (diffpos != nullptr)
        {
                DIFFITEM &di = ctxt.GetNextDiffRefPosition(diffpos);
                di.customFlags1 &= ~ViewCustomFlags::EXPANDED;
@@ -1310,8 +1315,8 @@ void CollapseAllSubdirs(CDiffContext& ctxt)
 DirViewTreeState *SaveTreeState(const CDiffContext& ctxt)
 {
        DirViewTreeState *pTreeState = new DirViewTreeState();
-       uintptr_t diffpos = ctxt.GetFirstDiffPosition();
-       while (diffpos)
+       DIFFITEM *diffpos = ctxt.GetFirstDiffPosition();
+       while (diffpos != nullptr)
        {
                const DIFFITEM &di = ctxt.GetNextDiffPosition(diffpos);
                if (di.HasChildren())
@@ -1325,8 +1330,8 @@ DirViewTreeState *SaveTreeState(const CDiffContext& ctxt)
 
 void RestoreTreeState(CDiffContext& ctxt, DirViewTreeState *pTreeState)
 {
-       uintptr_t diffpos = ctxt.GetFirstDiffPosition();
-       while (diffpos)
+       DIFFITEM *diffpos = ctxt.GetFirstDiffPosition();
+       while (diffpos != nullptr)
        {
                DIFFITEM &di = ctxt.GetNextDiffRefPosition(diffpos);
                if (di.HasChildren())
index 032ec0e..fd9d0d1 100644 (file)
@@ -8,7 +8,6 @@
 #include <algorithm>
 #include "FileTransform.h"
 
-struct DIFFITEM;
 class CDiffContext;
 class PathContext;
 class PluginManager;
@@ -143,31 +142,31 @@ String FormatMenuItemStringDifferencesTo(int count, int total);
 void ConfirmActionList(const CDiffContext& ctxt, const FileActionScript & actionList);
 UPDATEITEM_TYPE UpdateDiffAfterOperation(const FileActionItem & act, CDiffContext& ctxt, DIFFITEM &di);
 
-uintptr_t FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths);
-
-bool IsItemCopyable(const DIFFITEM & di, int index);
-bool IsItemDeletable(const DIFFITEM & di, int index);
-bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM & di);
-bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM & di1, const DIFFITEM & di2);
-bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM & di1, const DIFFITEM & di2, const DIFFITEM & di3);
-bool IsItemOpenableOn(const DIFFITEM & di, int index);
-bool IsItemOpenableOnWith(const DIFFITEM & di, int index);
-bool IsItemCopyableToOn(const DIFFITEM & di, int index);
-bool IsItemNavigableDiff(const CDiffContext& ctxt, const DIFFITEM & di);
-bool IsItemExistAll(const CDiffContext& ctxt, const DIFFITEM & di);
-bool IsShowable(const CDiffContext& ctxt, const DIFFITEM & di, const DirViewFilterSettings& filter);
-
-bool GetOpenOneItem(const CDiffContext& ctxt, uintptr_t pos1, const DIFFITEM *pdi[3],
+DIFFITEM *FindItemFromPaths(const CDiffContext& ctxt, const PathContext& paths);
+
+bool IsItemCopyable(const DIFFITEM &di, int index);
+bool IsItemDeletable(const DIFFITEM &di, int index);
+bool IsItemDeletableOnBoth(const CDiffContext& ctxt, const DIFFITEM &di);
+bool AreItemsOpenable(const CDiffContext& ctxt, SELECTIONTYPE selectionType, const DIFFITEM &di1, const DIFFITEM &di2);
+bool AreItemsOpenable(const CDiffContext& ctxt, const DIFFITEM &di1, const DIFFITEM &di2, const DIFFITEM &di3);
+bool IsItemOpenableOn(const DIFFITEM &di, int index);
+bool IsItemOpenableOnWith(const DIFFITEM &di, int index);
+bool IsItemCopyableToOn(const DIFFITEM &di, int index);
+bool IsItemNavigableDiff(const CDiffContext& ctxt, const DIFFITEM &di);
+bool IsItemExistAll(const CDiffContext& ctxt, const DIFFITEM &di);
+bool IsShowable(const CDiffContext& ctxt, const DIFFITEM &di, const DirViewFilterSettings& filter);
+
+bool GetOpenOneItem(const CDiffContext& ctxt, DIFFITEM *pos1, const DIFFITEM *pdi[3],
                PathContext &paths, int & sel1, bool & isDir, int nPane[3], String& errmsg);
-bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, uintptr_t pos1, uintptr_t pos2, const DIFFITEM *pdi[3],
+bool GetOpenTwoItems(const CDiffContext& ctxt, SELECTIONTYPE selectionType, DIFFITEM *pos1, DIFFITEM *pos2, const DIFFITEM *pdi[3],
                PathContext &paths, int & sel1, int & sel2, bool & isDir, int nPane[3], String& errmsg);
-bool GetOpenThreeItems(const CDiffContext& ctxt, uintptr_t pos1, uintptr_t pos2, uintptr_t pos3, const DIFFITEM *pdi[3],
+bool GetOpenThreeItems(const CDiffContext& ctxt, DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3, const DIFFITEM *pdi[3],
                PathContext &paths, int & sel1, int & sel2, int & sel3, bool & isDir, int nPane[3], String& errmsg);
 
 void GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM& di, String& strLeft, String& strRight);
 PathContext GetItemFileNames(const CDiffContext& ctxt, const DIFFITEM& di);
-String GetItemFileName(const CDiffContext& ctx, const DIFFITEM & di, int index);
-int GetColImage(const DIFFITEM & di);
+String GetItemFileName(const CDiffContext& ctx, const DIFFITEM &di, int index);
+int GetColImage(const DIFFITEM &di);
 
 void SetDiffStatus(DIFFITEM& di, unsigned  diffcode, unsigned mask);
 void SetDiffCompare(DIFFITEM& di, unsigned diffcode);
@@ -485,7 +484,7 @@ struct DirActions
                return ((*this).*m_cur_method)(pscript, it);
        }
 
-       bool operator()(const DIFFITEM & di) const
+       bool operator()(const DIFFITEM &di) const
        {
                return ((*this).*m_cur_method2)(di);
        }
index dfae5f1..787ff29 100644 (file)
@@ -235,7 +235,10 @@ void CDirDoc::Rescan()
        m_pDirView->DeleteAllDisplayItems();
        // Don't clear if only scanning selected items
        if (!m_bMarkedRescan)
+       {
                m_pCtxt->RemoveAll();
+               m_pCtxt->InitDiffItemList();
+       }
 
        LoadLineFilterList();
 
@@ -331,7 +334,7 @@ CDirView * CDirDoc::GetMainView() const
  * calls slow DirView functions to get item position and to update GUI.
  * Use UpdateStatusFromDisk() function instead.
  */
-void CDirDoc::ReloadItemStatus(uintptr_t diffPos, int idx)
+void CDirDoc::ReloadItemStatus(DIFFITEM *diffPos, int idx)
 {
        // in case just copied (into existence) or modified
        m_pCtxt->UpdateStatusFromDisk(diffPos, idx);
@@ -432,7 +435,7 @@ bool CDirDoc::CloseMergeDocs()
 void CDirDoc::UpdateChangedItem(PathContext &paths,
        UINT nDiffs, UINT nTrivialDiffs, bool bIdentical)
 {
-       uintptr_t pos = FindItemFromPaths(*m_pCtxt, paths);
+       DIFFITEM *pos = FindItemFromPaths(*m_pCtxt, paths);
        // If we failed files could have been swapped so lets try again
        if (!pos)
        {
index c7a9cb1..03c44ce 100644 (file)
@@ -94,7 +94,7 @@ public:
                UINT nDiffs, UINT nTrivialDiffs, bool bIdentical);
        void UpdateResources();
        void InitStatusStrings();
-       void ReloadItemStatus(uintptr_t diffPos, int idx);
+       void ReloadItemStatus(DIFFITEM *diffPos, int idx);
        void Redisplay();
        virtual ~CDirDoc();
        void SetDirView( CDirView *newView ); // TODO Perry
index c1546a2..3ba7ff7 100644 (file)
  * @brief Implementation for DirItem routines
  */
 
+#include "stdafx.h"
 #include "DirItem.h"
 #include <windows.h>
 #include "UnicodeString.h"
 #include "paths.h"
 #include "TFile.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 /**
        * @brief Convert file flags to string presentation.
        * This function converts file flags to a string presentation that can be
index f9a3ad9..a173eb2 100644 (file)
@@ -12,7 +12,7 @@
 #include <utility>
 #include "IListCtrl.h"
 
-struct DIFFITEM;
+class DIFFITEM;
 
 class DirItemWithIndexIterator : public std::iterator<std::forward_iterator_tag, std::pair<int, DIFFITEM *> >
 {
index 05fe16c..3ea8e43 100644 (file)
@@ -4,6 +4,7 @@
  *  @brief Implementation of DirScan (q.v.) and helper functions
  */ 
 
+#include "stdafx.h"
 #include "DirScan.h"
 #include <cassert>
 #include <memory>
 #include "OptionsDef.h"
 #include "OptionsMgr.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 using Poco::NotificationQueue;
 using Poco::Notification;
 using Poco::AutoPtr;
@@ -45,15 +50,15 @@ using Poco::Environment;
 using Poco::Stopwatch;
 
 // Static functions (ie, functions only used locally)
-void CompareDiffItem(DIFFITEM &di, CDiffContext * pCtxt);
-static void StoreDiffData(DIFFITEM &di, CDiffContext * pCtxt,
-               const FolderCmp * pCmpData);
-static DIFFITEM *AddToList(const String& sLeftDir, const String& sRightDir, const DirItem * lent, const DirItem * rent,
+void CompareDiffItem(DIFFITEM &di, CDiffContext *pCtxt);
+static void StoreDiffData(DIFFITEM &di, CDiffContext *pCtxt,
+               const FolderCmp *pCmpData);
+static DIFFITEM *AddToList(const String &sLeftDir, const String &sRightDir, const DirItem *lent, const DirItem *rent,
        unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent);
-static DIFFITEM *AddToList(const String& sDir1, const String& sDir2, const String& sDir3, const DirItem * ent1, const DirItem * ent2, const DirItem * ent3,
+static DIFFITEM *AddToList(const String &sDir1, const String &sDir2, const String &sDir3, const DirItem *ent1, const DirItem *ent2, const DirItem *ent3,
        unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent, int nItems = 3);
-static void UpdateDiffItem(DIFFITEM & di, bool & bExists, CDiffContext *pCtxt);
-static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uintptr_t parentdiffpos);
+static void UpdateDiffItem(DIFFITEM &di, bool &bExists, CDiffContext *pCtxt);
+static int CompareItems(NotificationQueue &queue, DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos);
 
 class WorkNotification: public Poco::Notification
 {
@@ -113,7 +118,7 @@ typedef std::shared_ptr<DiffWorker> DiffWorkerPtr;
  * @brief Collect file- and folder-names to list.
  * This function walks given folders and adds found subfolders and files into
  * lists. There are two modes, determined by the @p depth:
- * - in non-recursive mode we walk only given folders, and add files.
+ * - in non-recursive mode we walk only given folders, and add files
  *   contained. Subfolders are added as folder items, not walked into.
  * - in recursive mode we walk all subfolders and add the files they
  *   contain into list.
@@ -126,7 +131,7 @@ typedef std::shared_ptr<DiffWorker> DiffWorkerPtr;
  * @param [in] rightsubdir Right side subdirectory under root path
  * @param [in] bRightUniq Is right-side folder unique folder?
  * @param [in] myStruct Compare-related data, like context etc.
- * @param [in] casesensitive Is filename compare casesensitive?
+ * @param [in] casesensitive Is filename compare case sensitive?
  * @param [in] depth Levels of subdirectories to scan, -1 scans all
  * @param [in] parent Folder diff item to be scanned
  * @param [in] bUniques If true, walk into unique folders.
@@ -449,7 +454,7 @@ int DirScan_GetItems(const PathContext &paths, const String subdir[],
  * @param parentdiffpos [in] Position of parent diff item 
  * @return >= 0 number of diff items, -1 if compare was aborted
  */
-int DirScan_CompareItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
+int DirScan_CompareItems(DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos)
 {
        const int compareMethod = myStruct->context->GetCompareMethod();
        int nworkers = 1;
@@ -484,7 +489,7 @@ int DirScan_CompareItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
        return res;
 }
 
-static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
+static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos)
 {
        NotificationQueue queueResult;
        Stopwatch stopwatch;
@@ -492,11 +497,11 @@ static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uint
        int res = 0;
        int count = 0;
        bool bCompareFailure = false;
-       if (parentdiffpos == 0)
+       if (parentdiffpos == nullptr)
                myStruct->pSemaphore->wait();
        stopwatch.start();
-       uintptr_t pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
-       while (pos != 0)
+       DIFFITEM *pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
+       while (pos != nullptr)
        {
                if (pCtxt->ShouldAbort())
                        break;
@@ -508,7 +513,7 @@ static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uint
                        stopwatch.restart();
                }
                myStruct->pSemaphore->wait();
-               uintptr_t curpos = pos;
+               DIFFITEM *curpos = pos;
                DIFFITEM &di = pCtxt->GetNextSiblingDiffRefPosition(pos);
                bool existsalldirs = di.diffcode.existAll();
                if (di.diffcode.isDirectory() && pCtxt->m_bRecursive)
@@ -557,6 +562,7 @@ static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uint
                        DIFFITEM &di = pWorkCompletedNf->data();
                        if (di.diffcode.isResultError()) { 
                                DIFFITEM *diParent = di.parent;
+                               assert(di.parent != nullptr);
                                if (diParent != nullptr)
                                {
                                        diParent->diffcode.diffcode |= DIFFCODE::CMPERR;
@@ -581,14 +587,14 @@ static int CompareItems(NotificationQueue& queue, DiffFuncStruct *myStruct, uint
  * @param parentdiffpos [in] Position of parent diff item 
  * @return >= 0 number of diff items, -1 if compare was aborted
  */
-static int CompareRequestedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
+static int CompareRequestedItems(DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos)
 {
        CDiffContext *pCtxt = myStruct->context;
        int res = 0;
        bool bCompareFailure = false;
-       uintptr_t pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
+       DIFFITEM *pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
        
-       while (pos != NULL)
+       while (pos != nullptr)
        {
                if (pCtxt->ShouldAbort())
                {
@@ -596,7 +602,7 @@ static int CompareRequestedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffp
                        break;
                }
 
-               uintptr_t curpos = pos;
+               DIFFITEM *curpos = pos;
                DIFFITEM &di = pCtxt->GetNextSiblingDiffRefPosition(pos);
                bool existsalldirs = di.diffcode.existAll();
                if (di.diffcode.isDirectory())
@@ -632,6 +638,7 @@ static int CompareRequestedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffp
                                CompareDiffItem(di, pCtxt); 
                                if (di.diffcode.isResultError()) { 
                                        DIFFITEM *diParent = di.parent;
+                                       assert(di.parent != nullptr);
                                        if (diParent != nullptr)
                                        {
                                                diParent->diffcode.diffcode |= DIFFCODE::CMPERR;
@@ -648,19 +655,19 @@ static int CompareRequestedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffp
        return bCompareFailure ? -1 : res;;
 }
 
-int DirScan_CompareRequestedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
+int DirScan_CompareRequestedItems(DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos)
 {
        CAssureScriptsForThread scriptsForRescan;
        return CompareRequestedItems(myStruct, parentdiffpos);
 }
 
-static int markChildrenForRescan(CDiffContext *pCtxt, uintptr_t parentdiffpos)
+static int markChildrenForRescan(CDiffContext *pCtxt, DIFFITEM *parentdiffpos)
 {
        int ncount = 0;
-       uintptr_t pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
-       while (pos != NULL)
+       DIFFITEM *pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
+       while (pos != nullptr)
        {
-               uintptr_t curpos = pos;
+               DIFFITEM *curpos = pos;
                DIFFITEM &di = pCtxt->GetNextSiblingDiffRefPosition(pos);
                if (di.diffcode.isDirectory())
                        ncount += markChildrenForRescan(pCtxt, curpos);
@@ -673,17 +680,17 @@ static int markChildrenForRescan(CDiffContext *pCtxt, uintptr_t parentdiffpos)
        return ncount;
 }
 
-int DirScan_UpdateMarkedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
+int DirScan_UpdateMarkedItems(DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos)
 {
        CDiffContext *pCtxt = myStruct->context;
-       uintptr_t pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
+       DIFFITEM *pos = pCtxt->GetFirstChildDiffPosition(parentdiffpos);
        int ncount = 0;
        
-       while (pos != NULL)
+       while (pos != nullptr)
        {
                if (pCtxt->ShouldAbort())
                        break;
-               uintptr_t curpos = pos;
+               DIFFITEM *curpos = pos;
                DIFFITEM &di = pCtxt->GetNextSiblingDiffRefPosition(pos);
                if (di.diffcode.isScanNeeded())
                {
@@ -737,7 +744,7 @@ int DirScan_UpdateMarkedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos)
  *  - false if items were deleted, so diffitem is not valid
  * @param [in] pCtxt Compare context
  */
-static void UpdateDiffItem(DIFFITEM & di, bool & bExists, CDiffContext *pCtxt)
+static void UpdateDiffItem(DIFFITEM &di, bool & bExists, CDiffContext *pCtxt)
 {
        bExists = false;
        di.diffcode.setSideNone();
@@ -757,9 +764,9 @@ static void UpdateDiffItem(DIFFITEM & di, bool & bExists, CDiffContext *pCtxt)
  *
  * This function does the actual compare for previously gathered list of
  * items. Basically we:
- * - ignore items matching filefilters
+ * - ignore items matching file filters
  * - add non-ignored directories (no compare for directory items)
- * - add  unique files
+ * - add unique files
  * - compare files
  *
  * @param [in] di DiffItem to compare
@@ -849,15 +856,14 @@ static DIFFITEM *AddToList(const String& sLeftDir, const String& sRightDir,
  * @brief Add one compare item to list.
  */
 static DIFFITEM *AddToList(const String& sDir1, const String& sDir2, const String& sDir3,
-       const DirItem * ent1, const DirItem * ent2, const DirItem * ent3,
-       unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent, int nItems)
+       const DirItem *ent1, const DirItem *ent2, const DirItem *ent3,
+       unsigned code, DiffFuncStruct *myStruct, DIFFITEM *parent, int nItems /*= 3*/)
 {
        // We must store both paths - we cannot get paths later
        // and we need unique item paths for example when items
        // change to identical
-       DIFFITEM *di = myStruct->context->AddDiff(parent);
+       DIFFITEM *di = myStruct->context->AddNewDiff(parent);
 
-       di->parent = parent;
        di->diffFileInfo[0].path = sDir1;
        di->diffFileInfo[1].path = sDir2;
        di->diffFileInfo[2].path = sDir3;
index e8c2301..fddf7ba 100644 (file)
@@ -11,12 +11,12 @@ class CDiffContext;
 class DiffItemList;
 class PathContext;
 class IAbortable;
-struct DIFFITEM;
+class DIFFITEM;
 struct DiffFuncStruct;
 
 int DirScan_GetItems(const PathContext &paths, const String subdir[], DiffFuncStruct *myStruct,
                bool casesensitive, int depth, DIFFITEM *parent, bool bUniques);
-int DirScan_UpdateMarkedItems(DiffFuncStruct *myStruct, uintptr_t parentdiffpos);
+int DirScan_UpdateMarkedItems(DiffFuncStruct *myStruct, DIFFITEM *parentdiffpos);
 
-int DirScan_CompareItems(DiffFuncStruct *, uintptr_t parentdiffpos);
-int DirScan_CompareRequestedItems(DiffFuncStruct *, uintptr_t parentdiffpos);
+int DirScan_CompareItems(DiffFuncStruct *, DIFFITEM *parentdiffpos);
+int DirScan_CompareRequestedItems(DiffFuncStruct *, DIFFITEM *parentdiffpos);
index ec97b59..7533783 100644 (file)
@@ -5,6 +5,7 @@
  *
  */
 
+#include "stdafx.h"
 #include "DirTravel.h"
 #include <algorithm>
 #include <Poco/DirectoryIterator.h>
 #include "paths.h"
 #include "Win_VersionHelper.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 using Poco::DirectoryIterator;
 using Poco::Timestamp;
 
@@ -35,16 +40,16 @@ void LoadAndSortFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi
 }
 
 /**
- * @brief Find files and subfolders from given folder.
- * This function saves all files and subfolders in given folder to arrays.
+ * @brief Find file and sub-folder names from given folder.
+ * This function saves all file and sub-folder names in given folder to arrays.
  * We use 64-bit version of stat() to get times since find doesn't return
  * valid times for very old files (around year 1970). Even stat() seems to
  * give negative time values but we can live with that. Those around 1970
- * times can happen when file is created so that it  doesn't get valid
- * creation or modificatio dates.
+ * times can happen when file is created so that it doesn't get valid
+ * creation or modification dates.
  * @param [in] sDir Base folder for files and subfolders.
- * @param [in, out] dirs Array where subfolders are stored.
- * @param [in, out] files Array where files are stored.
+ * @param [in, out] dirs Array where subfolder names are stored.
+ * @param [in, out] files Array where file names are stored.
  */
 static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * files)
 {
index ca96943..10ebf24 100644 (file)
@@ -506,13 +506,13 @@ void CDirView::ReloadColumns()
  * @param [in,out] index Index of the item to be inserted.
  * @param [in,out] alldiffs Number of different items
  */
-void CDirView::RedisplayChildren(uintptr_t diffpos, int level, UINT &index, int &alldiffs)
+void CDirView::RedisplayChildren(DIFFITEM *diffpos, int level, UINT &index, int &alldiffs)
 {
        CDirDoc *pDoc = GetDocument();
        const CDiffContext &ctxt = GetDiffContext();
-       while (diffpos)
+       while (diffpos != nullptr)
        {
-               uintptr_t curdiffpos = diffpos;
+               DIFFITEM *curdiffpos = diffpos;
                const DIFFITEM &di = ctxt.GetNextSiblingDiffPosition(diffpos);
 
                if (di.diffcode.isResultDiff() || (!di.diffcode.existAll() && !di.diffcode.isResultFiltered()))
@@ -576,7 +576,7 @@ void CDirView::Redisplay()
        }
 
        int alldiffs = 0;
-       uintptr_t diffpos = ctxt.GetFirstDiffPosition();
+       DIFFITEM *diffpos = ctxt.GetFirstDiffPosition();
        RedisplayChildren(diffpos, 0, cnt, alldiffs);
        if (pDoc->m_diffThread.GetThreadState() == CDiffThread::THREAD_COMPLETED)
                GetParentFrame()->SetLastCompareResult(alldiffs);
@@ -1205,7 +1205,7 @@ void CDirView::ExpandSubdir(int sel, bool bRecursive)
        if (bRecursive)
                ExpandSubdirs(ctxt, dip);
 
-       uintptr_t diffpos = ctxt.GetFirstChildDiffPosition(GetItemKey(sel));
+       DIFFITEM *diffpos = ctxt.GetFirstChildDiffPosition(GetItemKey(sel));
        UINT indext = sel + 1;
        int alldiffs;
        RedisplayChildren(diffpos, dip.GetDepth() + 1, indext, alldiffs);
@@ -1270,9 +1270,9 @@ bool CDirView::GetSelectedItems(int * sel1, int * sel2, int * sel3)
  * @param [in] pos1 First item position.
  * @param [in] pos2 Second item position.
  */
-void CDirView::OpenSpecialItems(uintptr_t pos1, uintptr_t pos2, uintptr_t pos3)
+void CDirView::OpenSpecialItems(DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3)
 {
-       if (!pos2 && !pos3)
+       if (pos2==nullptr && pos3==nullptr)
        {
                // Browse to parent folder(s) selected
                // SPECIAL_ITEM_POS is position for
@@ -1330,7 +1330,7 @@ void CDirView::OpenSelection(SELECTIONTYPE selectionType /*= SELECTIONTYPE_NORMA
        const CDiffContext& ctxt = GetDiffContext();
 
        // First, figure out what was selected (store into pos1 & pos2)
-       uintptr_t pos1 = NULL, pos2 = NULL, pos3 = NULL;
+       DIFFITEM *pos1 = nullptr, *pos2 = nullptr, *pos3 = nullptr;
        int sel1 = -1, sel2 = -1, sel3 = -1;
        if (!GetSelectedItems(&sel1, &sel2, &sel3))
        {
@@ -1340,18 +1340,18 @@ void CDirView::OpenSelection(SELECTIONTYPE selectionType /*= SELECTIONTYPE_NORMA
        }
 
        pos1 = GetItemKey(sel1);
-       ASSERT(pos1);
+       ASSERT(pos1 != nullptr);
        if (sel2 != -1)
        {
                pos2 = GetItemKey(sel2);
-               ASSERT(pos2);
+               ASSERT(pos2 != nullptr);
                if (sel3 != -1)
                        pos3 = GetItemKey(sel3);
        }
 
        // Now handle the various cases of what was selected
 
-       if (pos1 == SPECIAL_ITEM_POS)
+       if (pos1 == (DIFFITEM *)SPECIAL_ITEM_POS)
        {
                OpenSpecialItems(pos1, pos2, pos3);
                return;
@@ -1459,7 +1459,7 @@ void CDirView::OpenSelectionAs(UINT id)
        const CDiffContext& ctxt = GetDiffContext();
 
        // First, figure out what was selected (store into pos1 & pos2)
-       uintptr_t pos1 = NULL, pos2 = NULL;
+       DIFFITEM *pos1 = nullptr, *pos2 = nullptr;
        int sel1 = -1, sel2 = -1, sel3 = -1;
        if (!GetSelectedItems(&sel1, &sel2, &sel3))
        {
@@ -1475,7 +1475,7 @@ void CDirView::OpenSelectionAs(UINT id)
 
        // Now handle the various cases of what was selected
 
-       if (pos1 == SPECIAL_ITEM_POS)
+       if (pos1 == (DIFFITEM *)SPECIAL_ITEM_POS)
        {
                ASSERT(false);
                return;
@@ -1578,9 +1578,9 @@ void CDirView::OnUpdateCtxtDirCopyBothDiffsOnlyTo(CCmdUI* pCmdUI)
  * @param [in] idx Item's index to list in UI.
  * @return Key for item in given index.
  */
-uintptr_t CDirView::GetItemKey(int idx) const
+DIFFITEM *CDirView::GetItemKey(int idx) const
 {
-       return (uintptr_t) m_pList->GetItemData(idx);
+       return (DIFFITEM *) m_pList->GetItemData(idx);
 }
 
 // SetItemKey & GetItemKey encapsulate how the display list items
@@ -1601,18 +1601,14 @@ const DIFFITEM &CDirView::GetDiffItem(int sel) const
 /**
  * Given index in list control, get modifiable reference to its DIFFITEM data
  */
-DIFFITEM & CDirView::GetDiffItem(int sel)
+DIFFITEM &CDirView::GetDiffItem(int sel)
 {
-       uintptr_t diffpos = GetItemKey(sel);
+       DIFFITEM *diffpos = GetItemKey(sel);
 
        // If it is special item, return empty DIFFITEM
-       if (diffpos == SPECIAL_ITEM_POS)
+       if (diffpos == (DIFFITEM *)SPECIAL_ITEM_POS)
        {
-               // TODO: It would be better if there were individual items
-               // for whatever these special items are
-               // because here we have to hope client does not modify this
-               // static (shared) item
-               return DIFFITEM::emptyitem;
+               return *DIFFITEM::GetEmptyItem();
        }
        return GetDiffContext().GetDiffRefAt(diffpos);
 }
@@ -1635,7 +1631,7 @@ void CDirView::DeleteAllDisplayItems()
  * @brief Given key, get index of item which has it stored.
  * This function searches from list in UI.
  */
-int CDirView::GetItemIndex(uintptr_t key)
+int CDirView::GetItemIndex(DIFFITEM *key)
 {
        LVFINDINFO findInfo;
 
@@ -1650,8 +1646,8 @@ int CDirView::GetItemIndex(uintptr_t key)
  */
 void CDirView::GetItemFileNames(int sel, String& strLeft, String& strRight) const
 {
-       UINT_PTR diffpos = GetItemKey(sel);
-       if (diffpos == (UINT_PTR)SPECIAL_ITEM_POS)
+       DIFFITEM *diffpos = GetItemKey(sel);
+       if (diffpos == (DIFFITEM *)SPECIAL_ITEM_POS)
        {
                strLeft.erase();
                strRight.erase();
@@ -1669,8 +1665,8 @@ void CDirView::GetItemFileNames(int sel, String& strLeft, String& strRight) cons
  */
 void CDirView::GetItemFileNames(int sel, PathContext * paths) const
 {
-       UINT_PTR diffpos = GetItemKey(sel);
-       if (diffpos == SPECIAL_ITEM_POS)
+       DIFFITEM *diffpos = GetItemKey(sel);
+       if (diffpos == (DIFFITEM *)SPECIAL_ITEM_POS)
        {
                for (int nIndex = 0; nIndex < GetDocument()->m_nDirs; nIndex++)
                        paths->SetPath(nIndex, _T(""));
@@ -2149,9 +2145,10 @@ BOOL CDirView::PreTranslateMessage(MSG* pMsg)
                                else if (m_bTreeMode && sel >= 0)
                                {
                                        const DIFFITEM& di = GetDiffItem(sel);
+                                       assert(di.parent != nullptr);
                                        if (di.parent != nullptr)
                                        {
-                                               int i = GetItemIndex((uintptr_t)di.parent);
+                                               int i = GetItemIndex(di.parent);
                                                if (i >= 0)
                                                        MoveFocus(sel, i, GetSelectedCount());
                                        }
@@ -2739,7 +2736,7 @@ int CDirView::AddSpecialItems()
  */
 void CDirView::AddParentFolderItem(bool bEnable)
 {
-       AddNewItem(0, SPECIAL_ITEM_POS, bEnable ? DIFFIMG_DIRUP : DIFFIMG_DIRUP_DISABLE, 0);
+       AddNewItem(0, (DIFFITEM *)SPECIAL_ITEM_POS, bEnable ? DIFFIMG_DIRUP : DIFFIMG_DIRUP_DISABLE, 0);
 }
 
 template <int flag>
@@ -2819,8 +2816,8 @@ void CDirView::OnSelectAll()
                for (int i = 0; i < selCount; i++)
                {
                        // Don't select special items (SPECIAL_ITEM_POS)
-                       uintptr_t diffpos = GetItemKey(i);
-                       if (diffpos != SPECIAL_ITEM_POS)
+                       DIFFITEM *diffpos = GetItemKey(i);
+                       if (diffpos != (DIFFITEM *)SPECIAL_ITEM_POS)
                                m_pList->SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
                }
        }
@@ -3152,8 +3149,8 @@ void CDirView::OnUpdateStatusNum(CCmdUI* pCmdUI)
        else
        {
                // Don't show number to special items
-               uintptr_t pos = GetItemKey(focusItem);
-               if (pos != SPECIAL_ITEM_POS)
+               DIFFITEM *pos = GetItemKey(focusItem);
+               if (pos != (DIFFITEM *)SPECIAL_ITEM_POS)
                {
                        // If compare is non-recursive reduce special items count
                        bool bRecursive = GetDiffContext().m_bRecursive;
@@ -3746,12 +3743,12 @@ void CDirView::OnSearch()
        int nRows = m_pList->GetItemCount();
        for (int currRow = nRows - 1; currRow >= 0; currRow--)
        {
-               uintptr_t pos = GetItemKey(currRow);
-               if (pos == SPECIAL_ITEM_POS)
+               DIFFITEM *pos = GetItemKey(currRow);
+               if (pos == (DIFFITEM *)SPECIAL_ITEM_POS)
                        continue;
 
                bool bFound = false;
-               DIFFITEM & di = GetDiffItem(currRow);
+               DIFFITEM &di = GetDiffItem(currRow);
                PathContext paths;
                for (int i = 0; i < pDoc->m_nDirs; i++)
                {
@@ -3885,8 +3882,8 @@ int CALLBACK CDirView::CompareState::CompareFunc(LPARAM lParam1, LPARAM lParam2,
        if (lParam2 == -1)
                return 1;
 
-       uintptr_t diffposl = (uintptr_t)lParam1;
-       uintptr_t diffposr = (uintptr_t)lParam2;
+       DIFFITEM *diffposl = (DIFFITEM *)lParam1;
+       DIFFITEM *diffposr = (DIFFITEM *)lParam2;
        const DIFFITEM &ldi = pThis->pCtxt->GetDiffAt(diffposl);
        const DIFFITEM &rdi = pThis->pCtxt->GetDiffAt(diffposr);
        // compare 'left' and 'right' parameters as appropriate
@@ -3896,7 +3893,7 @@ int CALLBACK CDirView::CompareState::CompareFunc(LPARAM lParam1, LPARAM lParam2,
 }
 
 /// Add new item to list view
-int CDirView::AddNewItem(int i, uintptr_t diffpos, int iImage, int iIndent)
+int CDirView::AddNewItem(int i, DIFFITEM *diffpos, int iImage, int iIndent)
 {
        LV_ITEM lvItem;
        lvItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE | LVIF_INDENT;
@@ -3944,8 +3941,8 @@ void CDirView::ReflectGetdispinfo(NMLVDISPINFO *pParam)
 {
        int nIdx = pParam->item.iItem;
        int i = m_pColItems->ColPhysToLog(pParam->item.iSubItem);
-       uintptr_t key = GetItemKey(nIdx);
-       if (key == SPECIAL_ITEM_POS)
+       DIFFITEM *key = GetItemKey(nIdx);
+       if (key == (DIFFITEM *)SPECIAL_ITEM_POS)
        {
                if (m_pColItems->IsColName(i))
                {
index 543de32..e682072 100644 (file)
@@ -36,8 +36,6 @@
 
 class FileActionScript;
 
-struct DIFFITEM;
-
 typedef enum { eMain, eContext } eMenuType;
 
 class CDirDoc;
@@ -58,7 +56,7 @@ struct IListCtrl;
 /**
  * @brief Position value for special items (..) in directory compare view.
  */
-const uintptr_t SPECIAL_ITEM_POS = (uintptr_t) - 1L;
+const uintptr_t SPECIAL_ITEM_POS = (uintptr_t)(reinterpret_cast<DIFFITEM *>( - 1L));
 
 /** Default column width in directory compare */
 const UINT DefColumnWidth = 150;
@@ -96,11 +94,11 @@ public:
 
        void StartCompare(CompareStats *pCompareStats);
        void Redisplay();
-       void RedisplayChildren(uintptr_t diffpos, int level, UINT &index, int &alldiffs);
+       void RedisplayChildren(DIFFITEM *diffpos, int level, UINT &index, int &alldiffs);
        void UpdateResources();
        void LoadColumnHeaderItems();
-       uintptr_t GetItemKey(int idx) const;
-       int GetItemIndex(uintptr_t key);
+       DIFFITEM *GetItemKey(int idx) const;
+       int GetItemIndex(DIFFITEM *key);
        // for populating list
        void DeleteItem(int sel);
        void DeleteAllDisplayItems();
@@ -168,7 +166,7 @@ public:
 private:
        void InitiateSort();
        void NameColumn(const char* idname, int subitem);
-       int AddNewItem(int i, uintptr_t diffpos, int iImage, int iIndent);
+       int AddNewItem(int i, DIFFITEM *diffpos, int iImage, int iIndent);
 // End DirViewCols.cpp
 
 private:
@@ -193,7 +191,7 @@ protected:
        int GetLastDifferentItem();
        int AddSpecialItems();
        void GetCurrentColRegKeys(std::vector<String>& colKeys);
-       void OpenSpecialItems(uintptr_t pos1, uintptr_t pos2, uintptr_t pos3);
+       void OpenSpecialItems(DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3);
 
 // Implementation data
 protected:
@@ -393,8 +391,8 @@ private:
        void OpenParentDirectory();
        template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
        void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
-       const DIFFITEM & GetDiffItem(int sel) const;
-       DIFFITEM & GetDiffItem(int sel);
+       const DIFFITEM &GetDiffItem(int sel) const;
+       DIFFITEM &GetDiffItem(int sel);
        int GetSingleSelectedItem() const;
        void MoveFocus(int currentInd, int i, int selCount);
 
index dcfefd3..47c9ce8 100644 (file)
@@ -5,6 +5,8 @@
  *
  * @date  Created: 2003-08-19
  */
+
+#include "stdafx.h"
 #include "DirViewColItems.h"
 #include <Poco/Timestamp.h>
 #include <Shlwapi.h>
 #include "paths.h"
 #include "MergeApp.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
 using Poco::Timestamp;
 
 #ifndef countof
@@ -490,9 +496,9 @@ static String ColNewerGet(const CDiffContext *pCtxt, const void *p)
  * @param [in] bLeft Is the item left-size item?
  * @return String proper to show in the GUI.
  */
-static String GetVersion(const CDiffContext * pCtxt, const DIFFITEM * pdi, int nIndex)
+static String GetVersion(const CDiffContext * pCtxt, const DIFFITEM *pdi, int nIndex)
 {
-       DIFFITEM & di = const_cast<DIFFITEM &>(*pdi);
+       DIFFITEM &di = const_cast<DIFFITEM &>(*pdi);
        DiffFileInfo & dfi = di.diffFileInfo[nIndex];
        if (dfi.version.IsCleared())
        {
@@ -501,9 +507,9 @@ static String GetVersion(const CDiffContext * pCtxt, const DIFFITEM * pdi, int n
        return dfi.version.GetFileVersionString();
 }
 
-static uint64_t GetVersionQWORD(const CDiffContext * pCtxt, const DIFFITEM * pdi, int nIndex)
+static uint64_t GetVersionQWORD(const CDiffContext * pCtxt, const DIFFITEM *pdi, int nIndex)
 {
-       DIFFITEM & di = const_cast<DIFFITEM &>(*pdi);
+       DIFFITEM &di = const_cast<DIFFITEM &>(*pdi);
        DiffFileInfo & dfi = di.diffFileInfo[nIndex];
        if (dfi.version.IsCleared())
        {
@@ -1231,7 +1237,7 @@ DirViewColItems::GetColCount() const
  */
 String
 DirViewColItems::ColGetTextToDisplay(const CDiffContext *pCtxt, int col,
-               const DIFFITEM & di) const
+               const DIFFITEM &di) const
 {
        // Custom properties have custom get functions
        const DirColInfo * pColInfo = GetDirColInfo(col);
@@ -1309,8 +1315,8 @@ DirViewColItems::ColGetTextToDisplay(const CDiffContext *pCtxt, int col,
  * @return Order of items.
  */
 int
-DirViewColItems::ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM & ldi,
-               const DIFFITEM & rdi, bool bTreeMode) const
+DirViewColItems::ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM &ldi,
+               const DIFFITEM &rdi, bool bTreeMode) const
 {
        // Custom properties have custom sort functions
        const DirColInfo * pColInfo = GetDirColInfo(col);
index 8a70587..188c343 100644 (file)
@@ -11,7 +11,7 @@
 #include <vector>
 #include <sstream>
 
-struct DIFFITEM;
+class DIFFITEM;
 class CDiffContext;
 
 // DirViewColItems typedefs
@@ -65,8 +65,8 @@ public:
        String GetColDescription(int col) const;
        int     GetColCount() const;
        int GetDispColCount() const { return m_dispcols; }
-       String ColGetTextToDisplay(const CDiffContext *pCtxt, int col, const DIFFITEM & di) const;
-       int ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM & ldi, const DIFFITEM &rdi, bool bTreeMode) const;
+       String ColGetTextToDisplay(const CDiffContext *pCtxt, int col, const DIFFITEM &di) const;
+       int ColSort(const CDiffContext *pCtxt, int col, const DIFFITEM &ldi, const DIFFITEM &rdi, bool bTreeMode) const;
 
        int ColPhysToLog(int i) const { return m_invcolorder[i]; }
        int ColLogToPhys(int i) const { return m_colorder[i]; } /**< -1 if not displayed */
index 5649136..cb8ca15 100644 (file)
@@ -4,6 +4,7 @@
  * @brief Implementation file for FolderCmp
  */
 
+#include "stdafx.h"
 #include "diff.h"
 #include "FolderCmp.h"
 #include <cassert>
@@ -20,6 +21,9 @@
 #include "TimeSizeCompare.h"
 #include "TFile.h"
 
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
 using CompareEngines::ByteCompare;
 using CompareEngines::BinaryCompare;
 using CompareEngines::TimeSizeCompare;
index 7b9e645..b0268cc 100644 (file)
@@ -164,7 +164,7 @@ int CHexMergeDoc::UpdateDiffItem(CDirDoc *pDirDoc)
        if (pDirDoc != nullptr && pDirDoc->HasDiffs())
        {
                CDiffContext &ctxt = pDirDoc->GetDiffContext();
-               if (UINT_PTR pos = FindItemFromPaths(ctxt, m_filePaths))
+               if (DIFFITEM *pos = FindItemFromPaths(ctxt, m_filePaths))
                {
                        DIFFITEM &di = ctxt.GetDiffRefAt(pos);
                        ::UpdateDiffItem(m_nBuffers, di, &ctxt);
diff --git a/Src/ListEntry.h b/Src/ListEntry.h
deleted file mode 100644 (file)
index eec376e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- *  @file ListEntry.h
- *
- *  @brief Declaration of ListEntry
- */
-#pragma once
-
-/**
- * @brief Simple LIST_ENTRY wrapper
- */
-class ListEntry
-{
-public:
-       ListEntry()
-       {
-               Flink = Blink = this;
-       }
-       void Append(ListEntry *p)
-       {
-               p->Flink = Blink->Flink;
-               p->Blink = Blink;
-               Blink->Flink = p;
-               Blink = p;
-       }
-       void RemoveSelf()
-       {
-               Blink->Flink = Flink;
-               Flink->Blink = Blink;
-               Flink = Blink = this;
-       }
-       ListEntry *IsSibling(ListEntry *p) const
-       {
-               return p != this ? p : 0;
-       }
-       ListEntry *Flink;
-       ListEntry *Blink;
-private:
-       ListEntry(const ListEntry &); // disallow copy construction
-       void operator=(const ListEntry &); // disallow assignment
-};
index 7eaac73..c9ade44 100644 (file)
@@ -313,8 +313,8 @@ TEST(FolderCompare, IgnoreEOL)
                do { Sleep(100); } while (!pStats->IsCompareDone());\r
                EXPECT_EQ(10, pStats->GetTotalItems());\r
                EXPECT_EQ(10, pStats->GetCount(CompareStats::RESULT::RESULT_SAME));\r
-               uintptr_t pos = ctxt.GetFirstDiffPosition();\r
-               while (pos)\r
+               DIFFITEM *pos = ctxt.GetFirstDiffPosition();\r
+               while (pos != nullptr)\r
                {\r
                        const DIFFITEM& di = ctxt.GetNextDiffPosition(pos);\r
                        for (int i = 0; i < 2; ++i)\r