Index: src/common/GenericTemplates/RandomAccessContainerWrapper.h =================================================================== diff -u -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/common/GenericTemplates/RandomAccessContainerWrapper.h (.../RandomAccessContainerWrapper.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) +++ src/common/GenericTemplates/RandomAccessContainerWrapper.h (.../RandomAccessContainerWrapper.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -20,6 +20,7 @@ #define __RANDOMACCESSCONTAINERWRAPPER_H__ #include "RandomAccessIterators.h" +#include template class RandomAccessContainerWrapper @@ -31,16 +32,46 @@ public: virtual ~RandomAccessContainerWrapper(); - bool operator==(const RandomAccessContainerWrapper& rSrc) const; - bool operator!=(const RandomAccessContainerWrapper& rSrc) const; + template + typename std::enable_if::value, bool>::type operator==(const RandomAccessContainerWrapper& rSrc) const + { + if(rSrc.GetCount() != GetCount()) + return false; + size_t stCount = GetCount(); + while(stCount-- > 0) + { + if(m_vItems[ stCount ] != rSrc.m_vItems[ stCount ]) + return false; + } + + return true; + } + + template + typename std::enable_if::value, bool>::type operator!=(const RandomAccessContainerWrapper& rSrc) const + { + if(rSrc.GetCount() != GetCount()) + return true; + + size_t stCount = GetCount(); + while(stCount-- > 0) + { + if(m_vItems[ stCount ] != rSrc.m_vItems[ stCount ]) + return true; + } + + return false; + } + void Add(const T& str); void InsertAt(size_t stIndex, const T& str); void SetAt(size_t stIndex, const T& str); void RemoveAt(size_t stIndex); void Clear(); const T& GetAt(size_t stIndex) const; + T& GetAt(size_t stIndex); bool IsEmpty() const; size_t GetCount() const; @@ -115,6 +146,15 @@ } template +T& RandomAccessContainerWrapper::GetAt(size_t stIndex) +{ + if (stIndex >= m_vItems.size()) + throw std::out_of_range("stIndex out of bounds"); + + return m_vItems.at(stIndex); +} + +template bool RandomAccessContainerWrapper::IsEmpty() const { return m_vItems.empty(); @@ -168,36 +208,4 @@ return const_iterator(m_vItems.cend()); } -template -bool RandomAccessContainerWrapper::operator==(const RandomAccessContainerWrapper& rSrc) const -{ - if (rSrc.GetCount() != GetCount()) - return false; - - size_t stCount = GetCount(); - while (stCount-- > 0) - { - if (m_vItems[stCount] != rSrc.m_vItems[stCount]) - return false; - } - - return true; -} - -template -bool RandomAccessContainerWrapper::operator!=(const RandomAccessContainerWrapper& rSrc) const -{ - if (rSrc.GetCount() != GetCount()) - return true; - - size_t stCount = GetCount(); - while (stCount-- > 0) - { - if (m_vItems[stCount] != rSrc.m_vItems[stCount]) - return true; - } - - return false; -} - #endif Index: src/libchengine/TBasePathData.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TBasePathData.cpp (.../TBasePathData.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TBasePathData.cpp (.../TBasePathData.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -155,169 +155,4 @@ m_oidObjectID = oidObjectID; } - ////////////////////////////////////////////////////////////////////////////// - // TBasePathDataContainer - - TBasePathDataContainer::TBasePathDataContainer() : - m_oidLastObjectID(0) - { - } - - TBasePathDataContainer::~TBasePathDataContainer() - { - // clear works with critical section to avoid destruction while item in use - Clear(); - } - - void TBasePathDataContainer::Store(const ISerializerContainerPtr& spContainer) const - { - if (!spContainer) - throw TCoreException(eErr_InvalidPointer, L"spContainer", LOCATION); - - boost::shared_lock lock(m_lock); - - InitColumns(spContainer); - - spContainer->DeleteRows(m_setRemovedObjects); - m_setRemovedObjects.Clear(); - - for(const TBasePathDataPtr& spEntry : m_vEntries) - { - spEntry->Store(spContainer); - } - } - - void TBasePathDataContainer::Load(const ISerializerContainerPtr& spContainer) - { - if (!spContainer) - throw TCoreException(eErr_InvalidPointer, L"spContainer", LOCATION); - - boost::unique_lock lock(m_lock); - m_setRemovedObjects.Clear(); - m_vEntries.clear(); - - InitColumns(spContainer); - - ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); - - while (spRowReader->Next()) - { - TBasePathDataPtr spPathData(new TBasePathData); - - spPathData->Load(spRowReader); - - m_vEntries.push_back(spPathData); - } - } - - void TBasePathDataContainer::Add(const TBasePathDataPtr& spEntry) - { - boost::unique_lock lock(m_lock); - spEntry->SetObjectID(++m_oidLastObjectID); - m_vEntries.push_back(spEntry); - } - - void TBasePathDataContainer::RemoveAt(file_count_t fcIndex) - { - boost::unique_lock lock(m_lock); - if (fcIndex >= m_vEntries.size()) - throw TCoreException(eErr_BoundsExceeded, L"fcIndex", LOCATION); - - m_setRemovedObjects.Add(m_vEntries[boost::numeric_cast(fcIndex)]->GetObjectID()); - m_vEntries.erase(m_vEntries.begin() + boost::numeric_cast(fcIndex)); - } - - TBasePathDataPtr TBasePathDataContainer::GetAt(file_count_t fcIndex) const - { - boost::shared_lock lock(m_lock); - return m_vEntries.at(boost::numeric_cast(fcIndex)); - } - - TBasePathDataPtr TBasePathDataContainer::FindByID(size_t stObjectID) const - { - boost::shared_lock lock(m_lock); - for(const TBasePathDataPtr& spItem : m_vEntries) - { - if (spItem->GetObjectID() == stObjectID) - return spItem; - } - - throw TCoreException(eErr_InvalidArgument, L"Object id does not exist", LOCATION); - } - - void TBasePathDataContainer::ClearNL() - { - for(const TBasePathDataPtr& spItem : m_vEntries) - { - m_setRemovedObjects.Add(spItem->GetObjectID()); - } - - m_vEntries.clear(); - } - - void TBasePathDataContainer::Clear() - { - boost::unique_lock lock(m_lock); - ClearNL(); - } - - bool TBasePathDataContainer::IsEmpty() const - { - boost::shared_lock lock(m_lock); - - return m_vEntries.empty(); - } - - file_count_t TBasePathDataContainer::GetCount() const - { - boost::shared_lock lock(m_lock); - return boost::numeric_cast(m_vEntries.size()); - } - - bool TBasePathDataContainer::AllMarkedAsSkipFurtherProcessing() const - { - boost::shared_lock lock(m_lock); - - for (const TBasePathDataPtr& spBasePath : m_vEntries) - { - if (!spBasePath->GetSkipFurtherProcessing()) - return false; - } - - return true; - } - - void TBasePathDataContainer::ResetProcessingFlags() - { - boost::unique_lock lock(m_lock); - - for(const TBasePathDataPtr& spBasePath : m_vEntries) - { - spBasePath->SetSkipFurtherProcessing(false); - } - } - - TBasePathDataContainer& TBasePathDataContainer::operator=(const TPathContainer& tPaths) - { - boost::unique_lock lock(m_lock); - ClearNL(); - - for (size_t stIndex = 0; stIndex < tPaths.GetCount(); ++stIndex) - { - TSmartPath path = tPaths.GetAt(stIndex); - path.StripSeparatorAtEnd(); - - TBasePathDataPtr spPathData = std::make_shared(++m_oidLastObjectID, path); - m_vEntries.push_back(spPathData); - } - - return *this; - } - - void TBasePathDataContainer::InitColumns(const ISerializerContainerPtr& spContainer) const - { - IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); - if (rColumns.IsEmpty()) - TBasePathData::InitColumns(rColumns); - } } Index: src/libchengine/TBasePathData.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TBasePathData.h (.../TBasePathData.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TBasePathData.h (.../TBasePathData.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -94,56 +94,7 @@ typedef std::shared_ptr TBasePathDataPtr; ////////////////////////////////////////////////////////////////////////// - // TBasePathDataContainer - class LIBCHENGINE_API TBasePathDataContainer - { - public: - // constructors/destructor - TBasePathDataContainer(); - TBasePathDataContainer(const TBasePathDataContainer& rSrc) = delete; - ~TBasePathDataContainer(); - - TBasePathDataContainer& operator=(const TBasePathDataContainer& rSrc) = delete; - - TBasePathDataContainer& operator=(const chcore::TPathContainer& tPaths); - - // standard access to data - void Add(const TBasePathDataPtr& spEntry); - void RemoveAt(file_count_t fcIndex); - TBasePathDataPtr GetAt(file_count_t fcIndex) const; - TBasePathDataPtr FindByID(size_t fcObjectID) const; - - void Clear(); - - bool IsEmpty() const; - file_count_t GetCount() const; - - // processing flags - bool AllMarkedAsSkipFurtherProcessing() const; - void ResetProcessingFlags(); - - void Store(const serializer::ISerializerContainerPtr& spContainer) const; - void Load(const serializer::ISerializerContainerPtr& spContainer); - - void InitColumns(const serializer::ISerializerContainerPtr& spContainer) const; - - private: - void ClearNL(); - - protected: -#pragma warning(push) -#pragma warning(disable: 4251) - typedef std::vector VecEntries; - VecEntries m_vEntries; - mutable serializer::TRemovedObjects m_setRemovedObjects; - - mutable boost::shared_mutex m_lock; -#pragma warning(pop) - serializer::object_id_t m_oidLastObjectID; - }; - - typedef std::shared_ptr TBasePathDataContainerPtr; } #endif // __TBASEPATHDATA_H__ Index: src/libchengine/TBasePathDataContainer.cpp =================================================================== diff -u --- src/libchengine/TBasePathDataContainer.cpp (revision 0) +++ src/libchengine/TBasePathDataContainer.cpp (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -0,0 +1,194 @@ +// ============================================================================ +// Copyright (C) 2001-2017 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 "TBasePathDataContainer.h" +#include "../libchcore/TCoreException.h" +#include "../libserializer/ISerializerContainer.h" +#include +#include +#include "../libchcore/TPathContainer.h" + +using namespace serializer; +using namespace chcore; + +namespace chengine +{ + TBasePathDataContainer::TBasePathDataContainer() : + m_oidLastObjectID(0) + { + } + + TBasePathDataContainer::~TBasePathDataContainer() + { + // clear works with critical section to avoid destruction while item in use + Clear(); + } + + void TBasePathDataContainer::Store(const ISerializerContainerPtr& spContainer) const + { + if(!spContainer) + throw TCoreException(eErr_InvalidPointer, L"spContainer", LOCATION); + + boost::shared_lock lock(m_lock); + + InitColumns(spContainer); + + spContainer->DeleteRows(m_setRemovedObjects); + m_setRemovedObjects.Clear(); + + for(const TBasePathDataPtr& spEntry : m_vEntries) + { + spEntry->Store(spContainer); + } + } + + void TBasePathDataContainer::Load(const ISerializerContainerPtr& spContainer) + { + if(!spContainer) + throw TCoreException(eErr_InvalidPointer, L"spContainer", LOCATION); + + boost::unique_lock lock(m_lock); + m_setRemovedObjects.Clear(); + m_vEntries.clear(); + + InitColumns(spContainer); + + ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); + + while(spRowReader->Next()) + { + TBasePathDataPtr spPathData(new TBasePathData); + + spPathData->Load(spRowReader); + + m_vEntries.push_back(spPathData); + } + } + + void TBasePathDataContainer::Add(const TBasePathDataPtr& spEntry) + { + boost::unique_lock lock(m_lock); + spEntry->SetObjectID(++m_oidLastObjectID); + m_vEntries.push_back(spEntry); + } + + void TBasePathDataContainer::RemoveAt(file_count_t fcIndex) + { + boost::unique_lock lock(m_lock); + if(fcIndex >= m_vEntries.size()) + throw TCoreException(eErr_BoundsExceeded, L"fcIndex", LOCATION); + + m_setRemovedObjects.Add(m_vEntries[ boost::numeric_cast(fcIndex) ]->GetObjectID()); + m_vEntries.erase(m_vEntries.begin() + boost::numeric_cast(fcIndex)); + } + + TBasePathDataPtr TBasePathDataContainer::GetAt(file_count_t fcIndex) const + { + boost::shared_lock lock(m_lock); + return m_vEntries.at(boost::numeric_cast(fcIndex)); + } + + TBasePathDataPtr TBasePathDataContainer::FindByID(size_t stObjectID) const + { + boost::shared_lock lock(m_lock); + for(const TBasePathDataPtr& spItem : m_vEntries) + { + if(spItem->GetObjectID() == stObjectID) + return spItem; + } + + throw TCoreException(eErr_InvalidArgument, L"Object id does not exist", LOCATION); + } + + void TBasePathDataContainer::ClearNL() + { + for(const TBasePathDataPtr& spItem : m_vEntries) + { + m_setRemovedObjects.Add(spItem->GetObjectID()); + } + + m_vEntries.clear(); + } + + void TBasePathDataContainer::Clear() + { + boost::unique_lock lock(m_lock); + ClearNL(); + } + + bool TBasePathDataContainer::IsEmpty() const + { + boost::shared_lock lock(m_lock); + + return m_vEntries.empty(); + } + + file_count_t TBasePathDataContainer::GetCount() const + { + boost::shared_lock lock(m_lock); + return boost::numeric_cast(m_vEntries.size()); + } + + bool TBasePathDataContainer::AllMarkedAsSkipFurtherProcessing() const + { + boost::shared_lock lock(m_lock); + + for(const TBasePathDataPtr& spBasePath : m_vEntries) + { + if(!spBasePath->GetSkipFurtherProcessing()) + return false; + } + + return true; + } + + void TBasePathDataContainer::ResetProcessingFlags() + { + boost::unique_lock lock(m_lock); + + for(const TBasePathDataPtr& spBasePath : m_vEntries) + { + spBasePath->SetSkipFurtherProcessing(false); + } + } + + TBasePathDataContainer& TBasePathDataContainer::operator=(const TPathContainer& tPaths) + { + boost::unique_lock lock(m_lock); + ClearNL(); + + for(size_t stIndex = 0; stIndex < tPaths.GetCount(); ++stIndex) + { + TSmartPath path = tPaths.GetAt(stIndex); + path.StripSeparatorAtEnd(); + + TBasePathDataPtr spPathData = std::make_shared(++m_oidLastObjectID, path); + m_vEntries.push_back(spPathData); + } + + return *this; + } + + void TBasePathDataContainer::InitColumns(const ISerializerContainerPtr& spContainer) const + { + IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); + if(rColumns.IsEmpty()) + TBasePathData::InitColumns(rColumns); + } +} Index: src/libchengine/TBasePathDataContainer.h =================================================================== diff -u --- src/libchengine/TBasePathDataContainer.h (revision 0) +++ src/libchengine/TBasePathDataContainer.h (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -0,0 +1,83 @@ +// ============================================================================ +// Copyright (C) 2001-2017 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 __TBASEPATHDATACONTAINER_H__ +#define __TBASEPATHDATACONTAINER_H__ + +#include "libchengine.h" +#include "TBasePathData.h" +#include +#include + +namespace chcore { + class TPathContainer; +} + +namespace chengine +{ + class LIBCHENGINE_API TBasePathDataContainer + { + public: + // constructors/destructor + TBasePathDataContainer(); + TBasePathDataContainer(const TBasePathDataContainer& rSrc) = delete; + ~TBasePathDataContainer(); + + TBasePathDataContainer& operator=(const TBasePathDataContainer& rSrc) = delete; + + TBasePathDataContainer& operator=(const chcore::TPathContainer& tPaths); + + // standard access to data + void Add(const TBasePathDataPtr& spEntry); + void RemoveAt(file_count_t fcIndex); + TBasePathDataPtr GetAt(file_count_t fcIndex) const; + TBasePathDataPtr FindByID(size_t fcObjectID) const; + + void Clear(); + + bool IsEmpty() const; + file_count_t GetCount() const; + + // processing flags + bool AllMarkedAsSkipFurtherProcessing() const; + void ResetProcessingFlags(); + + void Store(const serializer::ISerializerContainerPtr& spContainer) const; + void Load(const serializer::ISerializerContainerPtr& spContainer); + + void InitColumns(const serializer::ISerializerContainerPtr& spContainer) const; + + private: + void ClearNL(); + + protected: +#pragma warning(push) +#pragma warning(disable: 4251) + typedef std::vector VecEntries; + VecEntries m_vEntries; + mutable serializer::TRemovedObjects m_setRemovedObjects; + + mutable boost::shared_mutex m_lock; +#pragma warning(pop) + serializer::object_id_t m_oidLastObjectID; + }; + + typedef std::shared_ptr TBasePathDataContainerPtr; +} + +#endif Index: src/libchengine/TConfigArray.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TConfigArray.cpp (.../TConfigArray.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TConfigArray.cpp (.../TConfigArray.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -21,64 +21,4 @@ namespace chengine { - ///////////////////////////////////////////////////////////////////////////////////////////// - // class TConfigArray - - TConfigArray::TConfigArray() - { - } - - TConfigArray::TConfigArray(const TConfigArray& rSrc) : - m_vConfigs(rSrc.m_vConfigs) - { - } - - TConfigArray::~TConfigArray() - { - } - - TConfigArray& TConfigArray::operator=(const TConfigArray& rSrc) - { - if (this != &rSrc) - { - m_vConfigs = rSrc.m_vConfigs; - } - - return *this; - } - - size_t TConfigArray::GetCount() const - { - return m_vConfigs.size(); - } - - bool TConfigArray::IsEmpty() const - { - return m_vConfigs.empty(); - } - - const TConfig& TConfigArray::GetAt(size_t stIndex) const - { - return m_vConfigs[stIndex]; - } - - TConfig& TConfigArray::GetAt(size_t stIndex) - { - return m_vConfigs[stIndex]; - } - - void TConfigArray::Add(const TConfig& rSrc) - { - m_vConfigs.push_back(rSrc); - } - - void TConfigArray::RemoveAt(size_t stIndex) - { - m_vConfigs.erase(m_vConfigs.begin() + stIndex); - } - - void TConfigArray::Clear() - { - m_vConfigs.clear(); - } } Index: src/libchengine/TConfigArray.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TConfigArray.h (.../TConfigArray.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TConfigArray.h (.../TConfigArray.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -23,31 +23,19 @@ namespace chengine { - class LIBCHENGINE_API TConfigArray + template class LIBCHENGINE_API RandomAccessIteratorWrapper; + class LIBCHENGINE_API TConfigArrayIterator : public RandomAccessIteratorWrapper { - public: - TConfigArray(); - TConfigArray(const TConfigArray& rSrc); - ~TConfigArray(); + }; - TConfigArray& operator=(const TConfigArray& rSrc); + template class LIBCHENGINE_API RandomAccessConstIteratorWrapper; + class LIBCHENGINE_API TConfigArrayConstIterator : public RandomAccessConstIteratorWrapper + { + }; - size_t GetCount() const; - bool IsEmpty() const; - - const TConfig& GetAt(size_t stIndex) const; - TConfig& GetAt(size_t stIndex); - - void Add(const TConfig& rSrc); - - void RemoveAt(size_t stIndex); - void Clear(); - - private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector m_vConfigs; -#pragma warning(pop) + template class LIBCHENGINE_API RandomAccessContainerWrapper; + class LIBCHENGINE_API TConfigArray : public RandomAccessContainerWrapper + { }; } Index: src/libchengine/TFileFiltersArray.cpp =================================================================== diff -u -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TFileFiltersArray.cpp (.../TFileFiltersArray.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) +++ src/libchengine/TFileFiltersArray.cpp (.../TFileFiltersArray.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -28,15 +28,23 @@ namespace chengine { + TFileFiltersArray::TFileFiltersArray() + { + } + + TFileFiltersArray::~TFileFiltersArray() + { + } + bool TFileFiltersArray::Match(const TFileInfoPtr& spInfo) const { - if (m_vItems.empty()) + if(m_vFilters.empty()) return true; // if only one of the filters matches - return true - for (std::vector::const_iterator iterFilter = m_vItems.begin(); iterFilter != m_vItems.end(); ++iterFilter) + for(std::vector::const_iterator iterFilter = m_vFilters.begin(); iterFilter != m_vFilters.end(); ++iterFilter) { - if ((*iterFilter).Match(spInfo)) + if((*iterFilter).Match(spInfo)) return true; } @@ -46,7 +54,7 @@ void TFileFiltersArray::StoreInConfig(TConfig& rConfig, PCTSTR pszNodeName) const { rConfig.DeleteNode(pszNodeName); - for(const TFileFilter& rFilter : m_vItems) + for(const TFileFilter& rFilter : m_vFilters) { TConfig cfgNode; rFilter.StoreInConfig(cfgNode); @@ -58,31 +66,91 @@ bool TFileFiltersArray::ReadFromConfig(const TConfig& rConfig, PCTSTR pszNodeName) { - m_vItems.clear(); + m_vFilters.clear(); TConfigArray vConfigs; - if (!rConfig.ExtractMultiSubConfigs(pszNodeName, vConfigs)) + if(!rConfig.ExtractMultiSubConfigs(pszNodeName, vConfigs)) return false; - for (size_t stIndex = 0; stIndex < vConfigs.GetCount(); ++stIndex) + for(size_t stIndex = 0; stIndex < vConfigs.GetCount(); ++stIndex) { const TConfig& rCfg = vConfigs.GetAt(stIndex); TFileFilter tFilter; tFilter.ReadFromConfig(rCfg); - m_vItems.push_back(tFilter); + m_vFilters.push_back(tFilter); } return true; } + bool TFileFiltersArray::IsEmpty() const + { + return m_vFilters.empty(); + } + + void TFileFiltersArray::Add(const TFileFilter& rFilter) + { + m_vFilters.push_back(rFilter); + } + + bool TFileFiltersArray::SetAt(size_t stIndex, const TFileFilter& rNewFilter) + { + BOOST_ASSERT(stIndex < m_vFilters.size()); + if(stIndex < m_vFilters.size()) + { + TFileFilter& rFilter = m_vFilters.at(stIndex); + + rFilter.SetData(rNewFilter); + return true; + } + + return false; + } + + const TFileFilter& TFileFiltersArray::GetAt(size_t stIndex) const + { + if(stIndex >= m_vFilters.size()) + throw std::out_of_range("stIndex is out of range"); + + return m_vFilters.at(stIndex); + } + + bool TFileFiltersArray::RemoveAt(size_t stIndex) + { + BOOST_ASSERT(stIndex < m_vFilters.size()); + if(stIndex < m_vFilters.size()) + { + m_setRemovedObjects.Add(m_vFilters[ stIndex ].GetObjectID()); + + m_vFilters.erase(m_vFilters.begin() + stIndex); + return true; + } + + return false; + } + + size_t TFileFiltersArray::GetCount() const + { + return m_vFilters.size(); + } + + void TFileFiltersArray::Clear() + { + for(const TFileFilter& rFilter : m_vFilters) + { + m_setRemovedObjects.Add(rFilter.GetObjectID()); + } + m_vFilters.clear(); + } + void TFileFiltersArray::Store(const ISerializerContainerPtr& spContainer) const { InitColumns(spContainer); spContainer->DeleteRows(m_setRemovedObjects); m_setRemovedObjects.Clear(); - for(const TFileFilter& rFilter : m_vItems) + for(const TFileFilter& rFilter : m_vFilters) { rFilter.Store(spContainer); } @@ -93,21 +161,21 @@ InitColumns(spContainer); ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); - while (spRowReader->Next()) + while(spRowReader->Next()) { TFileFilter tFileFilter; tFileFilter.Load(spRowReader); tFileFilter.ResetModifications(); - m_vItems.push_back(tFileFilter); + m_vFilters.push_back(tFileFilter); } } void TFileFiltersArray::InitColumns(const ISerializerContainerPtr& spContainer) const { IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); - if (rColumns.IsEmpty()) + if(rColumns.IsEmpty()) TFileFilter::InitColumns(rColumns); } } Index: src/libchengine/TFileFiltersArray.h =================================================================== diff -u -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TFileFiltersArray.h (.../TFileFiltersArray.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) +++ src/libchengine/TFileFiltersArray.h (.../TFileFiltersArray.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -1,50 +1,39 @@ /*************************************************************************** - * Copyright (C) 2001-2008 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. * - ***************************************************************************/ +* Copyright (C) 2001-2008 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 __TFILEFILTERSARRAY_H__ #define __TFILEFILTERSARRAY_H__ #include "TFileFilter.h" #include "../libserializer/TRemovedObjects.h" -#include "../common/GenericTemplates/RandomAccessIterators.h" -#include "../common/GenericTemplates/RandomAccessContainerWrapper.h" namespace chengine { class TConfig; class TFileInfo; typedef std::shared_ptr TFileInfoPtr; - template class LIBCHENGINE_API RandomAccessIteratorWrapper; - class LIBCHENGINE_API TFileFiltersArrayIterator : public RandomAccessIteratorWrapper + class LIBCHENGINE_API TFileFiltersArray { - }; - - template class LIBCHENGINE_API RandomAccessConstIteratorWrapper; - class LIBCHENGINE_API TFileFiltersArrayConstIterator : public RandomAccessConstIteratorWrapper - { - }; - - template class LIBCHENGINE_API RandomAccessContainerWrapper; - - class LIBCHENGINE_API TFileFiltersArray : public RandomAccessContainerWrapper - { public: + TFileFiltersArray(); + ~TFileFiltersArray(); + bool Match(const TFileInfoPtr& spInfo) const; void StoreInConfig(TConfig& rConfig, PCTSTR pszNodeName) const; @@ -55,7 +44,21 @@ void InitColumns(const serializer::ISerializerContainerPtr& spContainer) const; + bool IsEmpty() const; + + void Add(const TFileFilter& rFilter); + bool SetAt(size_t stIndex, const TFileFilter& rNewFilter); + const TFileFilter& GetAt(size_t stIndex) const; + bool RemoveAt(size_t stIndex); + size_t GetCount() const; + + void Clear(); + private: +#pragma warning(push) +#pragma warning(disable: 4251) + std::vector m_vFilters; +#pragma warning(pop) mutable serializer::TRemovedObjects m_setRemovedObjects; }; } Index: src/libchengine/TFileInfo.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TFileInfo.h (.../TFileInfo.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TFileInfo.h (.../TFileInfo.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -26,6 +26,7 @@ #include "TBasePathData.h" #include #include "../libchcore/TFileTime.h" +#include "TBasePathDataContainer.h" namespace chengine { Index: src/libchengine/TFileInfoArray.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TFileInfoArray.cpp (.../TFileInfoArray.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TFileInfoArray.cpp (.../TFileInfoArray.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -43,14 +43,14 @@ { } - void TFileInfoArray::AddFileInfo(const TFileInfoPtr& spFileInfo) + void TFileInfoArray::Add(const TFileInfoPtr& spFileInfo) { boost::unique_lock lock(m_lock); spFileInfo->SetObjectID(++m_oidLastObjectID); m_vFiles.push_back(spFileInfo); } - file_count_t TFileInfoArray::GetSize() const + file_count_t TFileInfoArray::GetCount() const { boost::shared_lock lock(m_lock); return boost::numeric_cast(m_vFiles.size()); Index: src/libchengine/TFileInfoArray.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TFileInfoArray.h (.../TFileInfoArray.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TFileInfoArray.h (.../TFileInfoArray.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -24,6 +24,7 @@ #include "TBasePathData.h" #include "CommonDataTypes.h" +#include "TBasePathDataContainer.h" namespace chengine { @@ -37,10 +38,10 @@ ~TFileInfoArray(); // Adds a new object info to this container - void AddFileInfo(const TFileInfoPtr& spFileInfo); + void Add(const TFileInfoPtr& spFileInfo); /// Retrieves count of elements in this object - file_count_t GetSize() const; + file_count_t GetCount() const; /// Retrieves an element at the specified index TFileInfoPtr GetAt(file_count_t stIndex) const; Index: src/libchengine/TSubTaskCopyMove.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -83,7 +83,7 @@ { TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - file_count_t fcCount = rFilesCache.GetSize(); + file_count_t fcCount = rFilesCache.GetCount(); if(fcCount == 0) { m_spSubTaskStats->SetCurrentPath(TString()); @@ -119,11 +119,11 @@ // initialize stats if not resuming (when resuming we have already initialized // the stats once - it is being restored in Load() too). if (!m_spSubTaskStats->IsInitialized()) - m_spSubTaskStats->Init(TBufferSizes::eBuffer_Default, rFilesCache.GetSize(), 0, rFilesCache.CalculateTotalSize(), rFilesCache.CalculatePartialSize(m_spSubTaskStats->GetCurrentIndex()), TString()); + m_spSubTaskStats->Init(TBufferSizes::eBuffer_Default, rFilesCache.GetCount(), 0, rFilesCache.CalculateTotalSize(), rFilesCache.CalculatePartialSize(m_spSubTaskStats->GetCurrentIndex()), TString()); else { - _ASSERTE(rFilesCache.GetSize() == m_spSubTaskStats->GetTotalCount()); - if (rFilesCache.GetSize() != m_spSubTaskStats->GetTotalCount()) + _ASSERTE(rFilesCache.GetCount() == m_spSubTaskStats->GetTotalCount()); + if (rFilesCache.GetCount() != m_spSubTaskStats->GetTotalCount()) throw TCoreException(eErr_InternalProblem, L"Size of files' cache differs from stats information", LOCATION); } @@ -135,7 +135,7 @@ return eResult; // begin at index which wasn't processed previously - file_count_t fcSize = rFilesCache.GetSize(); + file_count_t fcSize = rFilesCache.GetCount(); file_count_t fcIndex = m_spSubTaskStats->GetCurrentIndex(); unsigned long long ullCurrentItemProcessedSize = m_spSubTaskStats->GetCurrentItemProcessedSize(); bool bCurrentFileSilentResume = m_spSubTaskStats->CanCurrentItemSilentResume(); @@ -301,7 +301,7 @@ if(!spStats->IsRunning() && spStats->GetTotalCount() == 0 && spStats->GetTotalSize() == 0) { const auto& rCache = GetContext().GetFilesCache(); - spStats->SetTotalCount(rCache.GetSize()); + spStats->SetTotalCount(rCache.GetCount()); spStats->SetTotalSize(rCache.CalculateTotalSize()); } } Index: src/libchengine/TSubTaskDelete.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -60,7 +60,7 @@ { TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - file_count_t fcCount = rFilesCache.GetSize(); + file_count_t fcCount = rFilesCache.GetCount(); if(fcCount == 0) { m_tSubTaskStats.SetCurrentPath(TString()); @@ -92,7 +92,7 @@ // new stats m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); - m_tSubTaskStats.SetTotalCount(rFilesCache.GetSize()); + m_tSubTaskStats.SetTotalCount(rFilesCache.GetCount()); m_tSubTaskStats.SetProcessedCount(0); m_tSubTaskStats.SetTotalSize(0); m_tSubTaskStats.SetProcessedSize(0); @@ -104,9 +104,9 @@ // index points to 0 or next item to process file_count_t fcIndex = m_tSubTaskStats.GetCurrentIndex(); - while (fcIndex < rFilesCache.GetSize()) + while (fcIndex < rFilesCache.GetCount()) { - spFileInfo = rFilesCache.GetAt(rFilesCache.GetSize() - fcIndex - 1); + spFileInfo = rFilesCache.GetAt(rFilesCache.GetCount() - fcIndex - 1); m_tSubTaskStats.SetCurrentIndex(fcIndex); @@ -156,7 +156,7 @@ // if this subtask is not started yet, try to get the most fresh information for processing if (!spStats->IsRunning() && spStats->GetTotalCount() == 0 && spStats->GetTotalSize() == 0) { - spStats->SetTotalCount(GetContext().GetFilesCache().GetSize()); + spStats->SetTotalCount(GetContext().GetFilesCache().GetCount()); spStats->SetTotalSize(0); } } Index: src/libchengine/TSubTaskScanDirectory.cpp =================================================================== diff -u -r9ddf8fdd5f641491dd30c49eb90f8f740314b6af -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 9ddf8fdd5f641491dd30c49eb90f8f740314b6af) +++ src/libchengine/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -154,7 +154,7 @@ if (!bIgnoreDirs && !bForceDirectories) { // add directory info; it is not to be filtered with afFilters - rFilesCache.AddFileInfo(spFileInfo); + rFilesCache.Add(spFileInfo); // log strFormat = _T("Added folder %path"); @@ -183,7 +183,7 @@ { // add file info if passes filters if (rafFilters.Match(spFileInfo)) - rFilesCache.AddFileInfo(spFileInfo); + rFilesCache.Add(spFileInfo); // log strFormat = _T("Added file %path"); @@ -231,7 +231,7 @@ if (afFilters.Match(spFileInfo)) { spFileInfo->SetParentObject(spBasePathData); - rFilesCache.AddFileInfo(spFileInfo); + rFilesCache.Add(spFileInfo); spFileInfo = std::make_shared(); } } @@ -241,7 +241,7 @@ if (bIncludeDirs) { spFileInfo->SetParentObject(spBasePathData); - rFilesCache.AddFileInfo(spFileInfo); + rFilesCache.Add(spFileInfo); spFileInfo = std::make_shared(); } Index: src/libchengine/libchengine.vcxproj =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/libchengine.vcxproj (.../libchengine.vcxproj) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/libchengine.vcxproj (.../libchengine.vcxproj) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -490,6 +490,7 @@ + @@ -595,6 +596,7 @@ + Index: src/libchengine/libchengine.vcxproj.filters =================================================================== diff -u -r1019bc9df4e044491b7102c37c8cac33cf56fb4a -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libchengine/libchengine.vcxproj.filters (.../libchengine.vcxproj.filters) (revision 1019bc9df4e044491b7102c37c8cac33cf56fb4a) +++ src/libchengine/libchengine.vcxproj.filters (.../libchengine.vcxproj.filters) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -396,6 +396,9 @@ Source Files\Tools\Threading + + Source Files\Tools + @@ -680,6 +683,9 @@ Source Files\Tools\Threading + + Source Files\Tools + Index: src/libstring/TStringArray.h =================================================================== diff -u -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a -r85b07e753393f661f7d8f528e4238ebb6e9e1204 --- src/libstring/TStringArray.h (.../TStringArray.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) +++ src/libstring/TStringArray.h (.../TStringArray.h) (revision 85b07e753393f661f7d8f528e4238ebb6e9e1204) @@ -25,7 +25,6 @@ #include "TString.h" #include "libstring.h" -#include #include "../common/GenericTemplates/RandomAccessIterators.h" #include "../common/GenericTemplates/RandomAccessContainerWrapper.h"