Index: src/ch/TCommandLineParser.cpp =================================================================== diff -u -r358a488269fd82d5d2566c407b95c4d519c5065e -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/ch/TCommandLineParser.cpp (.../TCommandLineParser.cpp) (revision 358a488269fd82d5d2566c407b95c4d519c5065e) +++ src/ch/TCommandLineParser.cpp (.../TCommandLineParser.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -24,6 +24,7 @@ #include "TCommandLineParser.h" #include #include "../libchcore/TPath.h" +#include "../libchcore/TPathContainer.h" TCommandLineParser::TCommandLineParser() { Index: src/chext/ShellPathsHelpers.cpp =================================================================== diff -u -r2d7bee54f998ae8f5d4145a2cf3f4a589253016f -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/chext/ShellPathsHelpers.cpp (.../ShellPathsHelpers.cpp) (revision 2d7bee54f998ae8f5d4145a2cf3f4a589253016f) +++ src/chext/ShellPathsHelpers.cpp (.../ShellPathsHelpers.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -24,6 +24,7 @@ #include "ShellPathsHelpers.h" #include #include "../libchcore/TPath.h" +#include "../libchcore/TPathContainer.h" namespace ShellPathsHelpers { Index: src/chext/TShellExtData.h =================================================================== diff -u -r633a533cb6e741d44fe28aa56339e1d2709b1b27 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/chext/TShellExtData.h (.../TShellExtData.h) (revision 633a533cb6e741d44fe28aa56339e1d2709b1b27) +++ src/chext/TShellExtData.h (.../TShellExtData.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -25,6 +25,7 @@ #include "..\libchcore\TPath.h" #include "..\libchcore\EOperationTypes.h" +#include "..\libchcore\TPathContainer.h" class TShellMenuItem; Index: src/libchcore/TBasePathData.cpp =================================================================== diff -u -r548382442cbf7bed7f744b279ce3f66b54992724 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TBasePathData.cpp (.../TBasePathData.cpp) (revision 548382442cbf7bed7f744b279ce3f66b54992724) +++ src/libchcore/TBasePathData.cpp (.../TBasePathData.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -71,7 +71,7 @@ ////////////////////////////////////////////////////////////////////////////// // TBasePathDataContainer -TBasePathDataContainer::TBasePathDataContainer(const TPathContainer& tBasePaths) : +TBasePathDataContainer::TBasePathDataContainer(const TModPathContainer& tBasePaths) : m_tBasePaths(tBasePaths) { } Index: src/libchcore/TBasePathData.h =================================================================== diff -u -r9ba9390b8f79c7a3fd1f9d6d9e92038d92222621 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TBasePathData.h (.../TBasePathData.h) (revision 9ba9390b8f79c7a3fd1f9d6d9e92038d92222621) +++ src/libchcore/TBasePathData.h (.../TBasePathData.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -25,6 +25,7 @@ #include "libchcore.h" #include "TPath.h" +#include "TModPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -60,7 +61,7 @@ { public: // constructors/destructor - explicit TBasePathDataContainer(const TPathContainer& tBasePaths); + explicit TBasePathDataContainer(const TModPathContainer& tBasePaths); ~TBasePathDataContainer(); // standard access to data @@ -73,7 +74,7 @@ void RemoveAt(size_t nIndex, size_t nCount = 1); void Clear(); - const TPathContainer& GetBasePaths() const { return m_tBasePaths; } + const TModPathContainer& GetBasePaths() const { return m_tBasePaths; } // serialization void Serialize(TReadBinarySerializer& rSerializer, bool bData); @@ -84,7 +85,7 @@ TBasePathDataContainer& operator=(const TBasePathDataContainer& rSrc); protected: - const TPathContainer& m_tBasePaths; + const TModPathContainer& m_tBasePaths; #pragma warning(push) #pragma warning(disable: 4251) Index: src/libchcore/TFileInfo.cpp =================================================================== diff -u -r548382442cbf7bed7f744b279ce3f66b54992724 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TFileInfo.cpp (.../TFileInfo.cpp) (revision 548382442cbf7bed7f744b279ce3f66b54992724) +++ src/libchcore/TFileInfo.cpp (.../TFileInfo.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -24,6 +24,7 @@ #include "SerializationHelpers.h" #include "TCoreException.h" #include "ErrorCodes.h" +#include "TModPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -61,7 +62,7 @@ { } -void TFileInfo::Init(const TSmartPath& rpathFile, size_t stSrcIndex, const TPathContainer* pBasePaths, +void TFileInfo::Init(const TSmartPath& rpathFile, size_t stSrcIndex, const TModPathContainer* pBasePaths, DWORD dwAttributes, ULONGLONG uhFileSize, FILETIME ftCreation, FILETIME ftLastAccess, FILETIME ftLastWrite, uint_t uiFlags) { @@ -93,7 +94,7 @@ m_uiFlags = uiFlags; } -void TFileInfo::SetParentObject(size_t stIndex, const TPathContainer* pBasePaths) +void TFileInfo::SetParentObject(size_t stIndex, const TModPathContainer* pBasePaths) { // cannot set parent object if there is already one specified if(m_pBasePaths && m_stSrcIndex != std::numeric_limits::max()) Index: src/libchcore/TFileInfo.h =================================================================== diff -u -r25b3c85ea493809ee084271d5101a015d349da95 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TFileInfo.h (.../TFileInfo.h) (revision 25b3c85ea493809ee084271d5101a015d349da95) +++ src/libchcore/TFileInfo.h (.../TFileInfo.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -27,7 +27,7 @@ BEGIN_CHCORE_NAMESPACE -class TPathContainer; +class TModPathContainer; class TReadBinarySerializer; class TWriteBinarySerializer; @@ -43,7 +43,7 @@ ~TFileInfo(); // with base path - void Init(const TSmartPath& rpathFile, size_t stSrcIndex, const TPathContainer* pBasePaths, + void Init(const TSmartPath& rpathFile, size_t stSrcIndex, const TModPathContainer* pBasePaths, DWORD dwAttributes, ULONGLONG uhFileSize, FILETIME ftCreation, FILETIME ftLastAccess, FILETIME ftLastWrite, uint_t uiFlags); @@ -52,7 +52,7 @@ FILETIME ftLastAccess, FILETIME ftLastWrite, uint_t uiFlags); // setting parent object - void SetParentObject(size_t stIndex, const TPathContainer* pBasePaths); + void SetParentObject(size_t stIndex, const TModPathContainer* pBasePaths); ULONGLONG GetLength64() const { return m_uhFileSize; } void SetLength64(ULONGLONG uhSize) { m_uhFileSize=uhSize; } @@ -81,7 +81,7 @@ void SetFlags(uint_t uiFlags, uint_t uiMask = 0xffffffff) { m_uiFlags = (m_uiFlags & ~(uiFlags & uiMask)) | (uiFlags & uiMask); } // operations - void SetClipboard(const TPathContainer* pBasePaths) { m_pBasePaths = pBasePaths; } + void SetBasePaths(const TModPathContainer* pBasePaths) { m_pBasePaths = pBasePaths; } void SetSrcIndex(size_t stIndex) { m_stSrcIndex = stIndex; }; size_t GetSrcIndex() const { return m_stSrcIndex; }; @@ -96,7 +96,7 @@ TSmartPath m_pathFile; // contains relative path (first path is in CClipboardArray) size_t m_stSrcIndex; // index in CClipboardArray table (which contains the first part of the path) - const TPathContainer* m_pBasePaths; + const TModPathContainer* m_pBasePaths; DWORD m_dwAttributes; // attributes ULONGLONG m_uhFileSize; Index: src/libchcore/TFileInfoArray.cpp =================================================================== diff -u -ra5f396da5ed5ffb3fcd9fdf22afb5a7fd07e1ab8 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TFileInfoArray.cpp (.../TFileInfoArray.cpp) (revision a5f396da5ed5ffb3fcd9fdf22afb5a7fd07e1ab8) +++ src/libchcore/TFileInfoArray.cpp (.../TFileInfoArray.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -30,7 +30,7 @@ /////////////////////////////////////////////////////////////////////// // Array -TFileInfoArray::TFileInfoArray(const TPathContainer& rBasePaths) : +TFileInfoArray::TFileInfoArray(const TModPathContainer& rBasePaths) : m_rBasePaths(rBasePaths), m_bComplete(false) { @@ -138,7 +138,7 @@ else { spFileInfo.reset(new TFileInfo); - spFileInfo->SetClipboard(&m_rBasePaths); + spFileInfo->SetBasePaths(&m_rBasePaths); Serialize(rSerializer, *spFileInfo); m_vFiles.push_back(spFileInfo); } Index: src/libchcore/TFileInfoArray.h =================================================================== diff -u -ra5f396da5ed5ffb3fcd9fdf22afb5a7fd07e1ab8 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TFileInfoArray.h (.../TFileInfoArray.h) (revision a5f396da5ed5ffb3fcd9fdf22afb5a7fd07e1ab8) +++ src/libchcore/TFileInfoArray.h (.../TFileInfoArray.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -24,6 +24,7 @@ #include "libchcore.h" #include "TPath.h" +#include "TModPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -37,7 +38,7 @@ class LIBCHCORE_API TFileInfoArray { public: - TFileInfoArray(const TPathContainer& rBasePaths); + TFileInfoArray(const TModPathContainer& rBasePaths); ~TFileInfoArray(); // Adds a new object info to this container @@ -70,7 +71,7 @@ void Serialize(TWriteBinarySerializer& rSerializer, bool bOnlyFlags) const; protected: - const TPathContainer& m_rBasePaths; + const TModPathContainer& m_rBasePaths; bool m_bComplete; #pragma warning(push) Index: src/libchcore/TLocalFilesystem.cpp =================================================================== diff -u -rf18d23588f370de68d37adb285dcf5e046a8d37c -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TLocalFilesystem.cpp (.../TLocalFilesystem.cpp) (revision f18d23588f370de68d37adb285dcf5e046a8d37c) +++ src/libchcore/TLocalFilesystem.cpp (.../TLocalFilesystem.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -36,6 +36,8 @@ #include "TDataBuffer.h" #include "TCoreException.h" #include "ErrorCodes.h" +#include "TPathContainer.h" +#include "TModPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -146,7 +148,7 @@ return ::DeleteFile(PrependPathExtensionIfNeeded(pathFile).ToString()) != FALSE; } -bool TLocalFilesystem::GetFileInfo(const TSmartPath& pathFile, TFileInfoPtr& rFileInfo, size_t stSrcIndex, const TPathContainer* pBasePaths) +bool TLocalFilesystem::GetFileInfo(const TSmartPath& pathFile, TFileInfoPtr& rFileInfo, size_t stSrcIndex, const TModPathContainer* pBasePaths) { if(!rFileInfo) THROW_CORE_EXCEPTION(eErr_InvalidArgument); Index: src/libchcore/TLocalFilesystem.h =================================================================== diff -u -rfb7c498da8e94ffb9cc61e1c826287e48bbeccde -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TLocalFilesystem.h (.../TLocalFilesystem.h) (revision fb7c498da8e94ffb9cc61e1c826287e48bbeccde) +++ src/libchcore/TLocalFilesystem.h (.../TLocalFilesystem.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -35,6 +35,7 @@ class TLocalFilesystemFind; class TLocalFilesystemFile; class TSimpleDataBuffer; +class TModPathContainer; class LIBCHCORE_API TLocalFilesystem { @@ -58,7 +59,7 @@ static bool RemoveDirectory(const TSmartPath& pathFile); static bool DeleteFile(const TSmartPath& pathFile); - static bool GetFileInfo(const TSmartPath& pathFile, TFileInfoPtr& rFileInfo, size_t stSrcIndex = std::numeric_limits::max(), const TPathContainer* pBasePaths = NULL); + static bool GetFileInfo(const TSmartPath& pathFile, TFileInfoPtr& rFileInfo, size_t stSrcIndex = std::numeric_limits::max(), const TModPathContainer* pBasePaths = NULL); static bool FastMove(const TSmartPath& pathSource, const TSmartPath& pathDestination); static TLocalFilesystemFind CreateFinderObject(const TSmartPath& pathDir, const TSmartPath& pathMask); Index: src/libchcore/TModPathContainer.cpp =================================================================== diff -u --- src/libchcore/TModPathContainer.cpp (revision 0) +++ src/libchcore/TModPathContainer.cpp (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -0,0 +1,324 @@ +// ============================================================================ +// Copyright (C) 2001-2014 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TModPathContainer.h" +#include "TCoreException.h" +#include "ErrorCodes.h" +#include "TPathContainer.h" +#include "TRowData.h" +#include "ISerializerRowData.h" + +BEGIN_CHCORE_NAMESPACE + +// ============================================================================ +/// TModPathContainer::TModPathContainer +/// @date 2009/11/30 +/// +/// @brief Constructs an empty path container object. +// ============================================================================ +TModPathContainer::TModPathContainer() : + m_vPaths(), + m_stNextObjectID(1) +{ +} + +// ============================================================================ +/// TModPathContainer::TModPathContainer +/// @date 2009/11/30 +/// +/// @brief Constructs the path container object from another path container. +/// @param[in] rSrcContainer - path container to copy paths from. +// ============================================================================ +TModPathContainer::TModPathContainer(const TModPathContainer& rSrcContainer) : + m_vPaths(rSrcContainer.m_vPaths), + m_stNextObjectID(rSrcContainer.m_stNextObjectID) +{ +} + +// ============================================================================ +/// TModPathContainer::~TModPathContainer +/// @date 2009/11/30 +/// +/// @brief Destructs this path container object. +// ============================================================================ +TModPathContainer::~TModPathContainer() +{ +} + +// ============================================================================ +/// TModPathContainer::operator= +/// @date 2009/11/30 +/// +/// @brief Assigns another path container object to this one. +/// @param[in] rSrcContainer - container with paths to copy from. +/// @return Reference to this object. +// ============================================================================ +TModPathContainer& TModPathContainer::operator=(const TModPathContainer& rSrcContainer) +{ + if(this != &rSrcContainer) + { + m_vPaths = rSrcContainer.m_vPaths; + m_stNextObjectID = rSrcContainer.m_stNextObjectID; + } + + return *this; +} + +TModPathContainer& TModPathContainer::operator=(const TPathContainer& rSrcContainer) +{ + Clear(true); + + for(size_t stIndex = 0; stIndex < rSrcContainer.GetCount(); ++stIndex) + { + m_vPaths.insert(std::make_pair(m_stNextObjectID++, TModificationTracker(rSrcContainer.GetAt(stIndex), true))); + } + + return *this; +} + +// ============================================================================ +/// TModPathContainer::Add +/// @date 2009/11/30 +/// +/// @brief Adds a path to the end of list. +/// @param[in] spPath - path to be added. +// ============================================================================ +void TModPathContainer::Add(const TSmartPath& spPath) +{ + m_vPaths.insert(std::make_pair(m_stNextObjectID++, TModificationTracker(spPath, true))); +} + +// ============================================================================ +/// TModPathContainer::GetAt +/// @date 2009/11/30 +/// +/// @brief Retrieves path at specified index. +/// @param[in] stIndex - index at which to retrieve item. +/// @return Reference to the path object. +// ============================================================================ +const TSmartPath& TModPathContainer::GetAt(size_t stIndex) const +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + DataMap::const_iterator iter = m_vPaths.cbegin() + stIndex; + return iter->second; +} + +// ============================================================================ +/// TModPathContainer::GetAt +/// @date 2009/11/30 +/// +/// @brief Retrieves path at specified index. +/// @param[in] stIndex - index at which to retrieve item. +/// @return Reference to the path object. +// ============================================================================ +TSmartPath& TModPathContainer::GetAt(size_t stIndex) +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + DataMap::iterator iter = m_vPaths.begin() + stIndex; + return iter->second.Value(); +} + +// ============================================================================ +/// chcore::TModPathContainer::SetAt +/// @date 2009/11/30 +/// +/// @brief Sets a path at a specified index. +/// @param[in] stIndex - index at which to set the path. +/// @param[in] spPath - path to be set. +// ============================================================================ +void TModPathContainer::SetAt(size_t stIndex, const TSmartPath& spPath) +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + DataMap::iterator iter = m_vPaths.begin() + stIndex; + iter->second = spPath; +} + +// ============================================================================ +/// chcore::TModPathContainer::DeleteAt +/// @date 2009/11/30 +/// +/// @brief Removes a path from container at specified index. +/// @param[in] stIndex - index at which to delete. +// ============================================================================ +void TModPathContainer::DeleteAt(size_t stIndex) +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + DataMap::iterator iterDel = m_vPaths.begin() + stIndex; + m_setRemovedItems.insert(iterDel->first); + m_vPaths.erase(iterDel); +} + +// ============================================================================ +/// chcore::TModPathContainer::Clear +/// @date 2009/11/30 +/// +/// @brief Removes all paths from this container. +// ============================================================================ +void TModPathContainer::Clear(bool bClearModificationsData) +{ + if(!bClearModificationsData) + { + for(DataMap::iterator iterDel = m_vPaths.begin(); iterDel != m_vPaths.end(); ++iterDel) + { + m_setRemovedItems.insert(iterDel->first); + } + } + else + { + m_setRemovedItems.clear(); + m_stNextObjectID = 1; + } + + m_vPaths.clear(); +} + +// ============================================================================ +/// chcore::TModPathContainer::GetCount +/// @date 2009/11/30 +/// +/// @brief Retrieves count of elements in the container. +/// @return Count of elements. +// ============================================================================ +size_t TModPathContainer::GetCount() const +{ + return m_vPaths.size(); +} + +// ============================================================================ +/// chcore::TModPathContainer::GetCount +/// @date 2010/10/12 +/// +/// @brief Retrieves info if this container is empty. +/// @return True if empty, false otherwise. +// ============================================================================ +bool TModPathContainer::IsEmpty() const +{ + return m_vPaths.empty(); +} + +const TSmartPath& TModPathContainer::GetAtOid(size_t stObjectID) const +{ + return m_vPaths.at(stObjectID); +} + +TSmartPath& TModPathContainer::GetAtOid(size_t stObjectID) +{ + return m_vPaths.at(stObjectID).Value(); +} + +void TModPathContainer::SetByOid(size_t stObjectID, const TSmartPath& spPath) +{ + DataMap::iterator iterFnd = m_vPaths.find(stObjectID); + if(iterFnd != m_vPaths.end()) + iterFnd->second = spPath; + else + m_vPaths.insert(std::make_pair(stObjectID, TModificationTracker(spPath, true))); +} + +void TModPathContainer::DeleteOid(size_t stObjectID) +{ + m_vPaths.erase(stObjectID); + m_setRemovedItems.insert(stObjectID); +} + +bool TModPathContainer::HasModifications() const +{ + if(!m_setRemovedItems.empty()) + return true; + + for(DataMap::const_iterator iterDel = m_vPaths.begin(); iterDel != m_vPaths.end(); ++iterDel) + { + if(iterDel->second.IsModified() || iterDel->second.IsAdded()) + return true; + } + + return false; +} + +void TModPathContainer::ClearModifications() +{ + m_setRemovedItems.clear(); + + for(DataMap::iterator iterDel = m_vPaths.begin(); iterDel != m_vPaths.end(); ++iterDel) + { + iterDel->second.ClearModifications(); + } +} + +void TModPathContainer::Store(const ISerializerContainerPtr& spContainer) +{ + // delete items first + BOOST_FOREACH(size_t stObjectID, m_setRemovedItems) + { + spContainer->DeleteRow(stObjectID); + } + m_setRemovedItems.clear(); + + // add/modify + for(DataMap::iterator iterPath = m_vPaths.begin(); iterPath != m_vPaths.end(); ++iterPath) + { + TModificationTracker& rItem = iterPath->second; + ISerializerRowDataPtr spRow; + + if(rItem.IsAdded()) + spRow = spContainer->AddRow(iterPath->first); + else if(rItem.IsModified()) + spRow = spContainer->GetRow(iterPath->first); + else + continue; + + *spRow % TRowData(_T("path"), rItem); + + rItem.ClearModifications(); + } +} + +void TModPathContainer::Load(const ISerializerContainerPtr& spContainer) +{ + m_setRemovedItems.clear(); + m_vPaths.clear(); + m_stNextObjectID = 1; + + IColumnsDefinitionPtr spColumns = spContainer->GetColumnsDefinition(); + *spColumns % _T("id") % _T("path"); + + ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); + while(spRowReader->Next()) + { + size_t stObjectID = 0; + TSmartPath path; + + spRowReader->GetValue(_T("id"), stObjectID); + spRowReader->GetValue(_T("path"), path); + + m_vPaths.insert(std::make_pair(stObjectID, TModificationTracker(path, false))); + } + + ClearModifications(); +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TModPathContainer.h =================================================================== diff -u --- src/libchcore/TModPathContainer.h (revision 0) +++ src/libchcore/TModPathContainer.h (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -0,0 +1,88 @@ +// ============================================================================ +// Copyright (C) 2001-2014 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TMODPATHCONTAINER_H__ +#define __TMODPATHCONTAINER_H__ + +#include "libchcore.h" +#include +#include "TModificationTracker.h" +#include "TPath.h" +#include "ISerializerContainer.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TModPathContainer +{ +public: + TModPathContainer(); + TModPathContainer(const TModPathContainer& rSrcContainer); + ~TModPathContainer(); + + TModPathContainer& operator=(const TModPathContainer& rSrcContainer); + TModPathContainer& operator=(const TPathContainer& rSrcContainer); + +#pragma region Index-based interface + void Add(const TSmartPath& spPath); + + const TSmartPath& GetAt(size_t stIndex) const; + TSmartPath& GetAt(size_t stIndex); + + void SetAt(size_t stIndex, const TSmartPath& spPath); + + void DeleteAt(size_t stIndex); +#pragma endregion + +#pragma region Object id-based interface + const TSmartPath& GetAtOid(size_t stObjectID) const; + TSmartPath& GetAtOid(size_t stObjectID); + + void SetByOid(size_t stObjectID, const TSmartPath& spPath); + void DeleteOid(size_t stObjectID); +#pragma endregion + +#pragma region Generic interface + void Clear(bool bClearModificationsData); + + size_t GetCount() const; + bool IsEmpty() const; +#pragma endregion + +#pragma region Modifications management + bool HasModifications() const; + void ClearModifications(); +#pragma endregion + +#pragma region Serialization + void Store(const ISerializerContainerPtr& spContainer); + void Load(const ISerializerContainerPtr& spContainer); +#pragma endregion + +private: +#pragma warning(push) +#pragma warning(disable: 4251) + std::set m_setRemovedItems; + typedef boost::container::flat_map > DataMap; + DataMap m_vPaths; +#pragma warning(pop) + size_t m_stNextObjectID; +}; + +END_CHCORE_NAMESPACE + +#endif Fisheye: Tag 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db refers to a dead (removed) revision in file `src/libchcore/TModificationTracker.cpp'. Fisheye: No comparison available. Pass `N' to diff? Index: src/libchcore/TModificationTracker.h =================================================================== diff -u -rb7655a8f0721e5454befd29e3e067748eb0521e9 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TModificationTracker.h (.../TModificationTracker.h) (revision b7655a8f0721e5454befd29e3e067748eb0521e9) +++ src/libchcore/TModificationTracker.h (.../TModificationTracker.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -29,66 +29,36 @@ public: TModificationTracker() : m_tValue(), - m_bModified(false) + m_chModified(eMod_None) { } - template - TModificationTracker(const V& rValue) : - m_tValue(rValue), - m_bModified(true) + TModificationTracker(const TModificationTracker& rSrc) : + m_chModified(rSrc.m_chModified), + m_tValue(rSrc.m_tValue) { } template - TModificationTracker& operator=(const V& rValue) + TModificationTracker(const V& rValue, bool bAdded) : + m_tValue(rValue), + m_chModified((char)eMod_Modified | (bAdded ? (char)eMod_Added : (char)eMod_None)) { - m_tValue = rValue; - m_bModified = true; } - operator const T&() const + TModificationTracker& operator=(const TModificationTracker& rSrc) { - return m_tValue; - } + m_chModified = rSrc.m_chModified; + m_tValue = rSrc.m_tValue; - operator T&() const - { - m_bModified = true; - return m_tValue; + return *this; } - bool IsModified() const - { - return m_bModified; - } - -private: - T m_tValue; - bool m_bModified; -}; - -template -class TSharedModificationTracker -{ -private: - TSharedModificationTracker& operator=(const TSharedModificationTracker& rValue); - -public: - TSharedModificationTracker(bool& rbSharedFlag) : m_tValue(), m_rbModified(rbSharedFlag) - { - } - template - TSharedModificationTracker(const V& rValue, bool& rbSharedFlag) : m_tValue(rValue), m_rbModified(rbSharedFlag) + TModificationTracker& operator=(const V& rValue) { - } - - template - TSharedModificationTracker& operator=(const V& rValue) - { m_tValue = rValue; - m_rbModified = true; + m_chModified |= eMod_Modified; return *this; } @@ -98,9 +68,9 @@ return m_tValue; } - operator T&() + T& Value() { - m_rbModified = true; + m_chModified |= eMod_Modified; return m_tValue; } @@ -109,20 +79,31 @@ return &m_tValue; } - T* operator->() + void ClearModifications() { - m_rbModified = true; - return &m_tValue; + m_chModified = eMod_None; } bool IsModified() const { - return m_rbModified; + return (m_chModified & eMod_Modified) != 0; } + bool IsAdded() const + { + return (m_chModified & eMod_Added) != 0; + } + private: + enum EModifiedFlags + { + eMod_None = 0, + eMod_Added = 1, + eMod_Modified = 2 + }; + T m_tValue; - bool& m_rbModified; + char m_chModified; }; END_CHCORE_NAMESPACE Index: src/libchcore/TPath.cpp =================================================================== diff -u -r1342b18babc7e88850e74f46cb473a737a68f28a -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TPath.cpp (.../TPath.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) +++ src/libchcore/TPath.cpp (.../TPath.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -30,6 +30,7 @@ #include "SerializationHelpers.h" #include "TCoreException.h" #include "ErrorCodes.h" +#include "TPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -1185,198 +1186,4 @@ return spPath; } -// ============================================================================ -/// TPathContainer::TPathContainer -/// @date 2009/11/30 -/// -/// @brief Constructs an empty path container object. -// ============================================================================ -TPathContainer::TPathContainer() : -m_vPaths() -{ -} - -// ============================================================================ -/// TPathContainer::TPathContainer -/// @date 2009/11/30 -/// -/// @brief Constructs the path container object from another path container. -/// @param[in] rSrcContainer - path container to copy paths from. -// ============================================================================ -TPathContainer::TPathContainer(const TPathContainer& rSrcContainer) : -m_vPaths(rSrcContainer.m_vPaths) -{ -} - -// ============================================================================ -/// TPathContainer::~TPathContainer -/// @date 2009/11/30 -/// -/// @brief Destructs this path container object. -// ============================================================================ -TPathContainer::~TPathContainer() -{ -} - -// ============================================================================ -/// TPathContainer::operator= -/// @date 2009/11/30 -/// -/// @brief Assigns another path container object to this one. -/// @param[in] rSrcContainer - container with paths to copy from. -/// @return Reference to this object. -// ============================================================================ -TPathContainer& TPathContainer::operator=(const TPathContainer& rSrcContainer) -{ - if(this != &rSrcContainer) - m_vPaths = rSrcContainer.m_vPaths; - - return *this; -} - -// ============================================================================ -/// TPathContainer::Add -/// @date 2009/11/30 -/// -/// @brief Adds a path to the end of list. -/// @param[in] spPath - path to be added. -// ============================================================================ -void TPathContainer::Add(const TSmartPath& spPath) -{ - m_vPaths.push_back(spPath); -} - -void TPathContainer::Append(const TPathContainer& vPaths) -{ - m_vPaths.insert(m_vPaths.end(), vPaths.m_vPaths.begin(), vPaths.m_vPaths.end()); -} - -// ============================================================================ -/// TPathContainer::GetAt -/// @date 2009/11/30 -/// -/// @brief Retrieves path at specified index. -/// @param[in] stIndex - index at which to retrieve item. -/// @return Reference to the path object. -// ============================================================================ -const TSmartPath& TPathContainer::GetAt(size_t stIndex) const -{ - if(stIndex > m_vPaths.size()) - THROW_CORE_EXCEPTION(eErr_BoundsExceeded); - - return m_vPaths.at(stIndex); -} - -// ============================================================================ -/// TPathContainer::GetAt -/// @date 2009/11/30 -/// -/// @brief Retrieves path at specified index. -/// @param[in] stIndex - index at which to retrieve item. -/// @return Reference to the path object. -// ============================================================================ -TSmartPath& TPathContainer::GetAt(size_t stIndex) -{ - if(stIndex > m_vPaths.size()) - THROW_CORE_EXCEPTION(eErr_BoundsExceeded); - - return m_vPaths.at(stIndex); -} - -// ============================================================================ -/// chcore::TPathContainer::SetAt -/// @date 2009/11/30 -/// -/// @brief Sets a path at a specified index. -/// @param[in] stIndex - index at which to set the path. -/// @param[in] spPath - path to be set. -// ============================================================================ -void TPathContainer::SetAt(size_t stIndex, const TSmartPath& spPath) -{ - if(stIndex > m_vPaths.size()) - THROW_CORE_EXCEPTION(eErr_BoundsExceeded); - - m_vPaths[stIndex] = spPath; -} - -// ============================================================================ -/// chcore::TPathContainer::DeleteAt -/// @date 2009/11/30 -/// -/// @brief Removes a path from container at specified index. -/// @param[in] stIndex - index at which to delete. -// ============================================================================ -void TPathContainer::DeleteAt(size_t stIndex) -{ - if(stIndex > m_vPaths.size()) - THROW_CORE_EXCEPTION(eErr_BoundsExceeded); - - m_vPaths.erase(m_vPaths.begin() + stIndex); -} - -// ============================================================================ -/// chcore::TPathContainer::Clear -/// @date 2009/11/30 -/// -/// @brief Removes all paths from this container. -// ============================================================================ -void TPathContainer::Clear() -{ - m_vPaths.clear(); -} - -// ============================================================================ -/// chcore::TPathContainer::GetCount -/// @date 2009/11/30 -/// -/// @brief Retrieves count of elements in the container. -/// @return Count of elements. -// ============================================================================ -size_t TPathContainer::GetCount() const -{ - return m_vPaths.size(); -} - -// ============================================================================ -/// chcore::TPathContainer::GetCount -/// @date 2010/10/12 -/// -/// @brief Retrieves info if this container is empty. -/// @return True if empty, false otherwise. -// ============================================================================ -bool TPathContainer::IsEmpty() const -{ - return m_vPaths.empty(); -} - -void TPathContainer::StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const -{ - TStringArray vPaths; - - // store as vector of strings (ineffective; should be done better) - BOOST_FOREACH(const TSmartPath& spPath, m_vPaths) - { - vPaths.Add(spPath.ToWString()); - } - - rConfig.SetValue(pszPropName, vPaths); -} - -bool TPathContainer::ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName) -{ - m_vPaths.clear(); - - TStringArray vPaths; - if(rConfig.GetValue(pszPropName, vPaths)) - { - for(size_t stIndex = 0; stIndex < vPaths.GetCount(); ++stIndex) - { - m_vPaths.push_back(PathFromWString(vPaths.GetAt(stIndex))); - } - return true; - } - else - return false; -} - END_CHCORE_NAMESPACE Index: src/libchcore/TPath.h =================================================================== diff -u -r1342b18babc7e88850e74f46cb473a737a68f28a -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TPath.h (.../TPath.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) +++ src/libchcore/TPath.h (.../TPath.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -160,42 +160,8 @@ LIBCHCORE_API TSmartPath PathFromString(const wchar_t* pszPath); LIBCHCORE_API TSmartPath PathFromWString(const TString& strPath); -class LIBCHCORE_API TPathContainer -{ -public: - TPathContainer(); - TPathContainer(const TPathContainer& rSrcContainer); - ~TPathContainer(); - - TPathContainer& operator=(const TPathContainer& rSrcContainer); - - void Add(const TSmartPath& spPath); - void Append(const TPathContainer& vPaths); - - const TSmartPath& GetAt(size_t stIndex) const; - TSmartPath& GetAt(size_t stIndex); - - void SetAt(size_t stIndex, const TSmartPath& spPath); - - void DeleteAt(size_t stIndex); - void Clear(); - - size_t GetCount() const; - bool IsEmpty() const; - - void StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const; - bool ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName); - -private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector m_vPaths; -#pragma warning(pop) -}; - END_CHCORE_NAMESPACE CONFIG_MEMBER_SERIALIZATION(TSmartPath) -CONFIG_MEMBER_SERIALIZATION(TPathContainer) #endif Index: src/libchcore/TPathContainer.cpp =================================================================== diff -u --- src/libchcore/TPathContainer.cpp (revision 0) +++ src/libchcore/TPathContainer.cpp (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -0,0 +1,220 @@ +// ============================================================================ +// Copyright (C) 2001-2014 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TPathContainer.h" +#include "TCoreException.h" +#include "ErrorCodes.h" + +BEGIN_CHCORE_NAMESPACE + +// ============================================================================ +/// TPathContainer::TPathContainer +/// @date 2009/11/30 +/// +/// @brief Constructs an empty path container object. +// ============================================================================ +TPathContainer::TPathContainer() : +m_vPaths() +{ +} + +// ============================================================================ +/// TPathContainer::TPathContainer +/// @date 2009/11/30 +/// +/// @brief Constructs the path container object from another path container. +/// @param[in] rSrcContainer - path container to copy paths from. +// ============================================================================ +TPathContainer::TPathContainer(const TPathContainer& rSrcContainer) : +m_vPaths(rSrcContainer.m_vPaths) +{ +} + +// ============================================================================ +/// TPathContainer::~TPathContainer +/// @date 2009/11/30 +/// +/// @brief Destructs this path container object. +// ============================================================================ +TPathContainer::~TPathContainer() +{ +} + +// ============================================================================ +/// TPathContainer::operator= +/// @date 2009/11/30 +/// +/// @brief Assigns another path container object to this one. +/// @param[in] rSrcContainer - container with paths to copy from. +/// @return Reference to this object. +// ============================================================================ +TPathContainer& TPathContainer::operator=(const TPathContainer& rSrcContainer) +{ + if(this != &rSrcContainer) + m_vPaths = rSrcContainer.m_vPaths; + + return *this; +} + +// ============================================================================ +/// TPathContainer::Add +/// @date 2009/11/30 +/// +/// @brief Adds a path to the end of list. +/// @param[in] spPath - path to be added. +// ============================================================================ +void TPathContainer::Add(const TSmartPath& spPath) +{ + m_vPaths.push_back(spPath); +} + +void TPathContainer::Append(const TPathContainer& vPaths) +{ + m_vPaths.insert(m_vPaths.end(), vPaths.m_vPaths.begin(), vPaths.m_vPaths.end()); +} + +// ============================================================================ +/// TPathContainer::GetAt +/// @date 2009/11/30 +/// +/// @brief Retrieves path at specified index. +/// @param[in] stIndex - index at which to retrieve item. +/// @return Reference to the path object. +// ============================================================================ +const TSmartPath& TPathContainer::GetAt(size_t stIndex) const +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + return m_vPaths.at(stIndex); +} + +// ============================================================================ +/// TPathContainer::GetAt +/// @date 2009/11/30 +/// +/// @brief Retrieves path at specified index. +/// @param[in] stIndex - index at which to retrieve item. +/// @return Reference to the path object. +// ============================================================================ +TSmartPath& TPathContainer::GetAt(size_t stIndex) +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + return m_vPaths.at(stIndex); +} + +// ============================================================================ +/// chcore::TPathContainer::SetAt +/// @date 2009/11/30 +/// +/// @brief Sets a path at a specified index. +/// @param[in] stIndex - index at which to set the path. +/// @param[in] spPath - path to be set. +// ============================================================================ +void TPathContainer::SetAt(size_t stIndex, const TSmartPath& spPath) +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + m_vPaths[stIndex] = spPath; +} + +// ============================================================================ +/// chcore::TPathContainer::DeleteAt +/// @date 2009/11/30 +/// +/// @brief Removes a path from container at specified index. +/// @param[in] stIndex - index at which to delete. +// ============================================================================ +void TPathContainer::DeleteAt(size_t stIndex) +{ + if(stIndex > m_vPaths.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + m_vPaths.erase(m_vPaths.begin() + stIndex); +} + +// ============================================================================ +/// chcore::TPathContainer::Clear +/// @date 2009/11/30 +/// +/// @brief Removes all paths from this container. +// ============================================================================ +void TPathContainer::Clear() +{ + m_vPaths.clear(); +} + +// ============================================================================ +/// chcore::TPathContainer::GetCount +/// @date 2009/11/30 +/// +/// @brief Retrieves count of elements in the container. +/// @return Count of elements. +// ============================================================================ +size_t TPathContainer::GetCount() const +{ + return m_vPaths.size(); +} + +// ============================================================================ +/// chcore::TPathContainer::GetCount +/// @date 2010/10/12 +/// +/// @brief Retrieves info if this container is empty. +/// @return True if empty, false otherwise. +// ============================================================================ +bool TPathContainer::IsEmpty() const +{ + return m_vPaths.empty(); +} + +void TPathContainer::StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const +{ + TStringArray vPaths; + + // store as vector of strings (ineffective; should be done better) + BOOST_FOREACH(const TSmartPath& spPath, m_vPaths) + { + vPaths.Add(spPath.ToWString()); + } + + rConfig.SetValue(pszPropName, vPaths); +} + +bool TPathContainer::ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName) +{ + m_vPaths.clear(); + + TStringArray vPaths; + if(rConfig.GetValue(pszPropName, vPaths)) + { + for(size_t stIndex = 0; stIndex < vPaths.GetCount(); ++stIndex) + { + m_vPaths.push_back(PathFromWString(vPaths.GetAt(stIndex))); + } + return true; + } + else + return false; +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TPathContainer.h =================================================================== diff -u --- src/libchcore/TPathContainer.h (revision 0) +++ src/libchcore/TPathContainer.h (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -0,0 +1,64 @@ +// ============================================================================ +// Copyright (C) 2001-2014 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TPATHCONTAINER_H__ +#define __TPATHCONTAINER_H__ + +#include "libchcore.h" +#include "TPath.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TPathContainer +{ +public: + TPathContainer(); + TPathContainer(const TPathContainer& rSrcContainer); + ~TPathContainer(); + + TPathContainer& operator=(const TPathContainer& rSrcContainer); + + void Add(const TSmartPath& spPath); + void Append(const TPathContainer& vPaths); + + const TSmartPath& GetAt(size_t stIndex) const; + TSmartPath& GetAt(size_t stIndex); + + void SetAt(size_t stIndex, const TSmartPath& spPath); + + void DeleteAt(size_t stIndex); + void Clear(); + + size_t GetCount() const; + bool IsEmpty() const; + + void StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const; + bool ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName); + +private: +#pragma warning(push) +#pragma warning(disable: 4251) + std::vector m_vPaths; +#pragma warning(pop) +}; + +END_CHCORE_NAMESPACE + +CONFIG_MEMBER_SERIALIZATION(TPathContainer) + +#endif Index: src/libchcore/TSQLiteSerializerContainer.cpp =================================================================== diff -u -rb7655a8f0721e5454befd29e3e067748eb0521e9 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSQLiteSerializerContainer.cpp (.../TSQLiteSerializerContainer.cpp) (revision b7655a8f0721e5454befd29e3e067748eb0521e9) +++ src/libchcore/TSQLiteSerializerContainer.cpp (.../TSQLiteSerializerContainer.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -24,6 +24,7 @@ #include #include "TSQLiteStatement.h" #include "TSQLiteSerializerRowReader.h" +#include BEGIN_CHCORE_NAMESPACE @@ -116,6 +117,8 @@ TString strQuery = boost::str(boost::wformat(L"DELETE FROM %1% WHERE id IN (%2%)") % m_strName % strItemsToRemove).c_str(); tStatement.Prepare(strQuery); + + ATLTRACE(_T("Executing query: %s\n"), (PCTSTR)strQuery); tStatement.Step(); } } Index: src/libchcore/TSQLiteSerializerRowData.cpp =================================================================== diff -u -r30297d6aab17483da8e7b8323b4d17ff1a9f78d6 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSQLiteSerializerRowData.cpp (.../TSQLiteSerializerRowData.cpp) (revision 30297d6aab17483da8e7b8323b4d17ff1a9f78d6) +++ src/libchcore/TSQLiteSerializerRowData.cpp (.../TSQLiteSerializerRowData.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -20,6 +20,7 @@ #include "TSQLiteSerializerRowData.h" #include "TSQLiteStatement.h" #include +#include BEGIN_CHCORE_NAMESPACE @@ -142,7 +143,7 @@ if(m_bAdded) { // prepare insert query - TString strQuery = boost::str(boost::wformat(L"INSERT INTO %1%(") % strContainerName).c_str(); + TString strQuery = boost::str(boost::wformat(L"INSERT INTO %1%(id,") % strContainerName).c_str(); TString strParams; for(MapVariants::iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) @@ -152,7 +153,7 @@ } strQuery.TrimRightSelf(_T(",")); - strQuery += _T(") VALUES("); + strQuery += _T(") VALUES(?,"); strParams.TrimRightSelf(_T(",")); strQuery += strParams; @@ -161,11 +162,13 @@ // exec query int iColumn = 1; tStatement.Prepare(strQuery); + tStatement.BindValue(iColumn++, m_stRowID); for(MapVariants::iterator iterVariant = m_mapValues.begin(); iterVariant != m_mapValues.end(); ++iterVariant) { boost::apply_visitor(SQLiteBindValueVisitor(tStatement, iColumn), iterVariant->second); } + ATLTRACE(_T("Executing query: %s\n"), (PCTSTR)strQuery); tStatement.Step(); } else @@ -188,6 +191,8 @@ boost::apply_visitor(SQLiteBindValueVisitor(tStatement, iColumn), iterVariant->second); } tStatement.BindValue(iColumn++, m_stRowID); + + ATLTRACE(_T("Executing query: %s\n"), (PCTSTR)strQuery); tStatement.Step(); } } Index: src/libchcore/TSQLiteSerializerRowReader.cpp =================================================================== diff -u -r1875711000138ff9d4185c2e3e74d455533de8a8 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSQLiteSerializerRowReader.cpp (.../TSQLiteSerializerRowReader.cpp) (revision 1875711000138ff9d4185c2e3e74d455533de8a8) +++ src/libchcore/TSQLiteSerializerRowReader.cpp (.../TSQLiteSerializerRowReader.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -23,6 +23,7 @@ #include "ErrorCodes.h" #include #include "TSQLiteStatement.h" +#include BEGIN_CHCORE_NAMESPACE @@ -49,8 +50,9 @@ { // generate query to retrieve data from db TString strQuery; - strQuery = boost::str(boost::wformat(L"SELECT %1% FROM %2%") % (PCTSTR)m_spColumns->GetCommaSeparatedColumns() % (PCTSTR)m_strContainerName).c_str(); + strQuery = boost::str(boost::wformat(L"SELECT %1% FROM %2% ORDER BY id") % (PCTSTR)m_spColumns->GetCommaSeparatedColumns() % (PCTSTR)m_strContainerName).c_str(); + ATLTRACE(_T("Executing query: %s\n"), (PCTSTR)strQuery); m_spStatement->Prepare(strQuery); m_bInitialized = true; } Index: src/libchcore/TSQLiteTaskSchema.cpp =================================================================== diff -u -rb7655a8f0721e5454befd29e3e067748eb0521e9 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSQLiteTaskSchema.cpp (.../TSQLiteTaskSchema.cpp) (revision b7655a8f0721e5454befd29e3e067748eb0521e9) +++ src/libchcore/TSQLiteTaskSchema.cpp (.../TSQLiteTaskSchema.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -46,6 +46,9 @@ tStatement.Prepare(_T("CREATE TABLE task(id BIGINT UNIQUE, name varchar(256) NOT NULL, log_path VARCHAR(32768), current_state INT NOT NULL, destination_path varchar(32768) NOT NULL)")); tStatement.Step(); + tStatement.Prepare(_T("CREATE TABLE base_paths(id BIGINT UNIQUE, path varchar(32768) NOT NULL)")); + tStatement.Step(); + // and finally set the database version to current one tVersion.SetVersion(1); } Index: src/libchcore/TSharedModificationTracker.h =================================================================== diff -u --- src/libchcore/TSharedModificationTracker.h (revision 0) +++ src/libchcore/TSharedModificationTracker.h (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -0,0 +1,97 @@ +// ============================================================================ +// Copyright (C) 2001-2014 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TSHAREDMODIFICATIONTRACKER_H__ +#define __TSHAREDMODIFICATIONTRACKER_H__ + +#include "libchcore.h" + +BEGIN_CHCORE_NAMESPACE + +template +class TSharedModificationTracker +{ +public: + TSharedModificationTracker(bool& rbSharedFlag) : + m_tValue(), + m_rbModified(rbSharedFlag) + { + } + + TSharedModificationTracker(const TSharedModificationTracker& rSrc) : + m_tValue(rSrc.m_tValue), + m_rbModified(rSrc.m_rbModified) + { + } + + template + TSharedModificationTracker(const V& rValue, bool& rbSharedFlag) : + m_tValue(rValue), + m_rbModified(rbSharedFlag) + { + } + + TSharedModificationTracker& operator=(const TSharedModificationTracker& rValue) + { + if(this != &rValue) + { + m_rbModified = rValue.m_rbModified; + m_tValue = rValue.m_tValue; + } + + return *this; + } + + template + TSharedModificationTracker& operator=(const V& rValue) + { + m_tValue = rValue; + m_rbModified = true; + + return *this; + } + + operator const T&() const + { + return m_tValue; + } + + T& Value() + { + m_rbModified = true; + return m_tValue; + } + + const T* operator->() const + { + return &m_tValue; + } + + bool IsModified() const + { + return m_rbModified; + } + +private: + T m_tValue; + bool& m_rbModified; +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TSubTaskCopyMove.cpp =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -41,6 +41,7 @@ #include "TDataBuffer.h" #include "ErrorCodes.h" #include "TCoreException.h" +#include "TPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -1229,7 +1230,7 @@ IFeedbackHandlerPtr spFeedbackHandler = GetContext().GetFeedbackHandler(); TLocalFilesystem& rLocalFilesystem = GetContext().GetLocalFilesystem(); TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - const TPathContainer& rSrcPaths = GetContext().GetBasePathDataContainer().GetBasePaths(); + const TModPathContainer& rSrcPaths = GetContext().GetBasePathDataContainer().GetBasePaths(); TSmartPath pathDestination = GetContext().GetDestinationPath(); ull_t ullNeededSize = 0, ullAvailableSize = 0; Index: src/libchcore/TSubTaskFastMove.cpp =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSubTaskFastMove.cpp (.../TSubTaskFastMove.cpp) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/TSubTaskFastMove.cpp (.../TSubTaskFastMove.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -38,6 +38,7 @@ #include "DataBuffer.h" #include "TCoreException.h" #include "ErrorCodes.h" +#include "TPathContainer.h" BEGIN_CHCORE_NAMESPACE Index: src/libchcore/TSubTaskScanDirectory.cpp =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -38,6 +38,7 @@ #include "DataBuffer.h" #include "TCoreException.h" #include "ErrorCodes.h" +#include "TPathContainer.h" BEGIN_CHCORE_NAMESPACE @@ -120,7 +121,7 @@ IFeedbackHandlerPtr spFeedbackHandler = GetContext().GetFeedbackHandler(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); TBasePathDataContainer& rBasePathDataContainer = GetContext().GetBasePathDataContainer(); - const TPathContainer& rBasePaths = rBasePathDataContainer.GetBasePaths(); + const TModPathContainer& rBasePaths = rBasePathDataContainer.GetBasePaths(); const TConfig& rConfig = GetContext().GetConfig(); rLog.logi(_T("Searching for files...")); @@ -291,7 +292,7 @@ { TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - const TPathContainer& rBasePaths = GetContext().GetBasePathDataContainer().GetBasePaths(); + const TModPathContainer& rBasePaths = GetContext().GetBasePathDataContainer().GetBasePaths(); TLocalFilesystemFind finder = TLocalFilesystem::CreateFinderObject(pathDirName, PathFromString(_T("*"))); TFileInfoPtr spFileInfo(boost::make_shared()); Index: src/libchcore/TTask.cpp =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TTask.cpp (.../TTask.cpp) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/TTask.cpp (.../TTask.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -147,13 +147,16 @@ bool bResult = spRowReader->Next(); if(bResult) { - spRowReader->GetValue(_T("name"), m_strTaskName); - spRowReader->GetValue(_T("log_path"), m_pathLog); - spRowReader->GetValue(_T("current_state"), *(int*)(ETaskCurrentState*)&m_eCurrentState); - spRowReader->GetValue(_T("destination_path"), m_pathDestinationPath); + spRowReader->GetValue(_T("name"), m_strTaskName.Value()); + spRowReader->GetValue(_T("log_path"), m_pathLog.Value()); + spRowReader->GetValue(_T("current_state"), *(int*)(ETaskCurrentState*)&m_eCurrentState.Value()); + spRowReader->GetValue(_T("destination_path"), m_pathDestinationPath.Value()); } else THROW_CORE_EXCEPTION(eErr_SerializeLoadError); + + spContainer = m_spSerializer->GetContainer(_T("base_paths")); + m_vSourcePaths.Load(spContainer); } m_bBaseDataChanged = false; @@ -170,6 +173,7 @@ ISerializerContainerPtr spContainer = m_spSerializer->GetContainer(_T("task")); ISerializerRowDataPtr spRow; + // base data if(!m_bWasSerialized || m_bBaseDataChanged) { if(m_bWasSerialized) @@ -182,12 +186,17 @@ % TRowData(_T("log_path"), m_pathLog) % TRowData(_T("current_state"), m_eCurrentState) % TRowData(_T("destination_path"), m_pathDestinationPath); + + m_bBaseDataChanged = false; + m_bWasSerialized = true; } + + // base paths + spContainer = m_spSerializer->GetContainer(_T("base_paths")); + m_vSourcePaths.Store(spContainer); } m_spSerializer->Flush(); - m_bBaseDataChanged = false; - m_bWasSerialized = true; } void TTask::KillThread() Index: src/libchcore/TTask.h =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TTask.h (.../TTask.h) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/TTask.h (.../TTask.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -34,7 +34,8 @@ #include "TSubTaskContext.h" #include "TTaskStatsSnapshot.h" #include "ISerializer.h" -#include "TModificationTracker.h" +#include "TModPathContainer.h" +#include "TSharedModificationTracker.h" BEGIN_CHCORE_NAMESPACE @@ -150,7 +151,8 @@ #pragma endregion // basic information - TPathContainer m_vSourcePaths; + TModPathContainer m_vSourcePaths; + TBasePathDataContainer m_arrSourcePathsInfo; // Global task settings TConfig m_tConfiguration; @@ -161,7 +163,6 @@ TTaskConfigTracker m_cfgTracker; - TBasePathDataContainer m_arrSourcePathsInfo; // current task state (derivatives of the task initial information) // changing slowly or only partially Index: src/libchcore/TTaskDefinition.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TTaskDefinition.h (.../TTaskDefinition.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskDefinition.h (.../TTaskDefinition.h) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -26,6 +26,7 @@ #include "TTaskOperationPlan.h" #include "TConfig.h" #include "TPath.h" +#include "TPathContainer.h" BEGIN_CHCORE_NAMESPACE Index: src/libchcore/TTaskManager.cpp =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -436,6 +436,12 @@ { boost::shared_lock lock(m_lock); m_tTasks.Store(spContainer); + + for(size_t stIndex = 0; stIndex != m_tTasks.GetCount(); ++stIndex) + { + TTaskPtr spTask = m_tTasks.GetAt(stIndex).GetTask(); + spTask->Store(); + } } m_spSerializer->Flush(); Index: src/libchcore/libchcore.vc90.vcproj =================================================================== diff -u -r458af7bf8c35950fdeb4b906950437596324aea1 -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db --- src/libchcore/libchcore.vc90.vcproj (.../libchcore.vc90.vcproj) (revision 458af7bf8c35950fdeb4b906950437596324aea1) +++ src/libchcore/libchcore.vc90.vcproj (.../libchcore.vc90.vcproj) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) @@ -1108,14 +1108,18 @@ > + + @@ -1124,6 +1128,14 @@ > + + + + @@ -1132,6 +1144,10 @@ > + +