Index: src/ch/CustomCopyDlg.cpp =================================================================== diff -u -r9ddf8fdd5f641491dd30c49eb90f8f740314b6af -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision 9ddf8fdd5f641491dd30c49eb90f8f740314b6af) +++ src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -371,11 +371,10 @@ // refresh the entries in filters' list const chengine::TFileFiltersArray& afFilters = m_tTaskDefinition.GetFilters(); m_ctlFilters.DeleteAllItems(); - for(size_t stIndex = 0; stIndex < afFilters.GetSize(); ++stIndex) + for(size_t stIndex = 0; stIndex < afFilters.GetCount(); ++stIndex) { - const chengine::TFileFilter* pFilter = afFilters.GetAt(stIndex); - if(pFilter) - AddFilter(*pFilter, boost::numeric_cast(stIndex)); + const chengine::TFileFilter& rFilter = afFilters.GetAt(stIndex); + AddFilter(rFilter, boost::numeric_cast(stIndex)); } } @@ -539,17 +538,13 @@ CFilterDlg dlg; chengine::TFileFiltersArray& afFilters = m_tTaskDefinition.GetFilters(); - for (size_t i = 0; i < afFilters.GetSize(); i++) + for (size_t i = 0; i < afFilters.GetCount(); i++) { - const chengine::TFileFilter* pFilter = afFilters.GetAt(i); - BOOST_ASSERT(pFilter); - if(pFilter) - { - if(pFilter->GetUseMask()) - dlg.m_astrAddMask.Add(pFilter->GetCombinedMask().c_str()); - if(pFilter->GetUseExcludeMask()) - dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask().c_str()); - } + const chengine::TFileFilter& rFilter = afFilters.GetAt(i); + if(rFilter.GetUseMask()) + dlg.m_astrAddMask.Add(rFilter.GetCombinedMask().c_str()); + if(rFilter.GetUseExcludeMask()) + dlg.m_astrAddExcludeMask.Add(rFilter.GetCombinedExcludeMask().c_str()); } if(dlg.DoModal() == IDOK) @@ -759,22 +754,16 @@ int iItem = m_ctlFilters.GetNextSelectedItem(pos); CFilterDlg dlg; - const chengine::TFileFilter* pFilter = afFilters.GetAt(iItem); - BOOST_ASSERT(pFilter); - if(pFilter) - dlg.m_ffFilter = *pFilter; + const chengine::TFileFilter& rFilter = afFilters.GetAt(iItem); + dlg.m_ffFilter = rFilter; - for(size_t stIndex = 0; stIndex < afFilters.GetSize(); ++stIndex) + for(size_t stIndex = 0; stIndex < afFilters.GetCount(); ++stIndex) { - pFilter = afFilters.GetAt(stIndex); - BOOST_ASSERT(pFilter); - if(pFilter) - { - if(pFilter->GetUseMask() && boost::numeric_cast(stIndex) != iItem) - dlg.m_astrAddMask.Add(pFilter->GetCombinedMask().c_str()); - if (pFilter->GetUseExcludeMask() && boost::numeric_cast(stIndex) != iItem) - dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask().c_str()); - } + const chengine::TFileFilter& rFilter = afFilters.GetAt(stIndex); + if(rFilter.GetUseMask() && boost::numeric_cast(stIndex) != iItem) + dlg.m_astrAddMask.Add(rFilter.GetCombinedMask().c_str()); + if (rFilter.GetUseExcludeMask() && boost::numeric_cast(stIndex) != iItem) + dlg.m_astrAddExcludeMask.Add(rFilter.GetCombinedExcludeMask().c_str()); } if (dlg.DoModal() == IDOK) Index: src/common/GenericTemplates/RandomAccessContainerWrapper.h =================================================================== diff -u --- src/common/GenericTemplates/RandomAccessContainerWrapper.h (revision 0) +++ src/common/GenericTemplates/RandomAccessContainerWrapper.h (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -0,0 +1,203 @@ +// ============================================================================ +// Copyright (C) 2001-2011 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 __RANDOMACCESSCONTAINERWRAPPER_H__ +#define __RANDOMACCESSCONTAINERWRAPPER_H__ + +#include "RandomAccessIterators.h" + +template +class RandomAccessContainerWrapper +{ +public: + using iterator = RandomAccessIteratorWrapper; + using const_iterator = RandomAccessConstIteratorWrapper; + +public: + virtual ~RandomAccessContainerWrapper(); + + bool operator==(const RandomAccessContainerWrapper& rSrc) const; + bool operator!=(const RandomAccessContainerWrapper& rSrc) const; + + 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; + + bool IsEmpty() const; + size_t GetCount() const; + + void Append(const RandomAccessContainerWrapper& rSrc); + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + const_iterator cbegin() const; + const_iterator cend() const; + +protected: +#pragma warning(push) +#pragma warning(disable: 4251) + std::vector m_vItems; +#pragma warning(pop) +}; + +template +RandomAccessContainerWrapper::~RandomAccessContainerWrapper() +{ +} + +template +void RandomAccessContainerWrapper::Add(const T& str) +{ + m_vItems.push_back(str); +} + +template +void RandomAccessContainerWrapper::InsertAt(size_t stIndex, const T& str) +{ + if (stIndex > m_vItems.size()) + throw std::out_of_range("stIndex out of bounds"); + + m_vItems.insert(m_vItems.begin() + stIndex, str); +} + +template +void RandomAccessContainerWrapper::SetAt(size_t stIndex, const T& str) +{ + if (stIndex >= m_vItems.size()) + throw std::out_of_range("stIndex out of bounds"); + + m_vItems[stIndex] = str; +} + +template +void RandomAccessContainerWrapper::RemoveAt(size_t stIndex) +{ + if (stIndex >= m_vItems.size()) + throw std::out_of_range("stIndex out of bounds"); + + m_vItems.erase(m_vItems.begin() + stIndex); +} + +template +void RandomAccessContainerWrapper::Clear() +{ + m_vItems.clear(); +} + +template +const T& RandomAccessContainerWrapper::GetAt(size_t stIndex) const +{ + 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(); +} + +template +size_t RandomAccessContainerWrapper::GetCount() const +{ + return m_vItems.size(); +} + +template +void RandomAccessContainerWrapper::Append(const RandomAccessContainerWrapper& rSrc) +{ + m_vItems.insert(m_vItems.end(), rSrc.m_vItems.begin(), rSrc.m_vItems.end()); +} + +template +typename RandomAccessContainerWrapper::iterator RandomAccessContainerWrapper::begin() +{ + return iterator(m_vItems.begin()); +} + +template +typename RandomAccessContainerWrapper::iterator RandomAccessContainerWrapper::end() +{ + return iterator(m_vItems.end()); +} + +template +typename RandomAccessContainerWrapper::const_iterator RandomAccessContainerWrapper::begin() const +{ + return const_iterator(m_vItems.begin()); +} + +template +typename RandomAccessContainerWrapper::const_iterator RandomAccessContainerWrapper::end() const +{ + return const_iterator(m_vItems.end()); +} + +template +typename RandomAccessContainerWrapper::const_iterator RandomAccessContainerWrapper::cbegin() const +{ + return const_iterator(m_vItems.cbegin()); +} + +template +typename RandomAccessContainerWrapper::const_iterator RandomAccessContainerWrapper::cend() const +{ + 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/common/GenericTemplates/RandomAccessIterators.h =================================================================== diff -u --- src/common/GenericTemplates/RandomAccessIterators.h (revision 0) +++ src/common/GenericTemplates/RandomAccessIterators.h (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -0,0 +1,362 @@ +// ============================================================================ +// Copyright (C) 2001-2016 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 __RANDOMACCESSITERATORS_H__ +#define __RANDOMACCESSITERATORS_H__ + +template +class RandomAccessIteratorWrapper : public std::iterator +{ +protected: + explicit RandomAccessIteratorWrapper(typename std::vector::iterator iterArray); + +public: + RandomAccessIteratorWrapper(); + ~RandomAccessIteratorWrapper(); + + RandomAccessIteratorWrapper& operator+=(const int& rhs); + RandomAccessIteratorWrapper& operator-=(const int& rhs); + T& operator*(); + T* operator->(); + T& operator[](const int& rhs) const; + + RandomAccessIteratorWrapper& operator++(); + RandomAccessIteratorWrapper& operator--(); + RandomAccessIteratorWrapper operator++(int); + RandomAccessIteratorWrapper operator--(int); + RandomAccessIteratorWrapper operator+(const int& rhs) const; + RandomAccessIteratorWrapper operator-(const int& rhs) const; + + bool operator==(const RandomAccessIteratorWrapper& rhs) const; + bool operator!=(const RandomAccessIteratorWrapper& rhs) const; + bool operator>(const RandomAccessIteratorWrapper& rhs) const; + bool operator<(const RandomAccessIteratorWrapper& rhs) const; + bool operator>=(const RandomAccessIteratorWrapper& rhs) const; + bool operator<=(const RandomAccessIteratorWrapper& rhs) const; + +private: +#pragma warning(push) +#pragma warning(disable: 4251) + typename std::vector::iterator m_iterArray; +#pragma warning(pop) + + template + friend class RandomAccessConstIteratorWrapper; + template + friend class RandomAccessContainerWrapper; +}; + +template +class RandomAccessConstIteratorWrapper : public std::iterator +{ +protected: + explicit RandomAccessConstIteratorWrapper(typename std::vector::const_iterator iterArray); + +public: + RandomAccessConstIteratorWrapper(); + RandomAccessConstIteratorWrapper(const RandomAccessIteratorWrapper& rIterator); + ~RandomAccessConstIteratorWrapper(); + + RandomAccessConstIteratorWrapper& operator=(const RandomAccessIteratorWrapper& rIterator); + + RandomAccessConstIteratorWrapper& operator+=(const int& rhs); + RandomAccessConstIteratorWrapper& operator-=(const int& rhs); + const T& operator*(); + const T* operator->(); + const T& operator[](const int& rhs) const; + + RandomAccessConstIteratorWrapper& operator++(); + RandomAccessConstIteratorWrapper& operator--(); + RandomAccessConstIteratorWrapper operator++(int); + RandomAccessConstIteratorWrapper operator--(int); + RandomAccessConstIteratorWrapper operator+(const int& rhs) const; + RandomAccessConstIteratorWrapper operator-(const int& rhs) const; + + bool operator==(const RandomAccessConstIteratorWrapper& rhs) const; + bool operator!=(const RandomAccessConstIteratorWrapper& rhs) const; + bool operator>(const RandomAccessConstIteratorWrapper& rhs) const; + bool operator<(const RandomAccessConstIteratorWrapper& rhs) const; + bool operator>=(const RandomAccessConstIteratorWrapper& rhs) const; + bool operator<=(const RandomAccessConstIteratorWrapper& rhs) const; + +private: +#pragma warning(push) +#pragma warning(disable: 4251) + typename std::vector::const_iterator m_iterArray; +#pragma warning(pop) + + template + friend class RandomAccessContainerWrapper; +}; + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +// class RandomAccessIteratorWrapper + +template +RandomAccessIteratorWrapper::RandomAccessIteratorWrapper(typename std::vector::iterator iterArray) : + m_iterArray(iterArray) +{ +} + +template +RandomAccessIteratorWrapper::RandomAccessIteratorWrapper() +{ +} + +template +RandomAccessIteratorWrapper::~RandomAccessIteratorWrapper() +{ +} + +template +RandomAccessIteratorWrapper& RandomAccessIteratorWrapper::operator+=(const int& rhs) +{ + m_iterArray += rhs; return *this; +} + +template +bool RandomAccessIteratorWrapper::operator<=(const RandomAccessIteratorWrapper& rhs) const +{ + return m_iterArray <= rhs.m_iterArray; +} + +template +bool RandomAccessIteratorWrapper::operator<(const RandomAccessIteratorWrapper& rhs) const +{ + return m_iterArray < rhs.m_iterArray; +} + +template +bool RandomAccessIteratorWrapper::operator!=(const RandomAccessIteratorWrapper& rhs) const +{ + return m_iterArray != rhs.m_iterArray; +} + +template +bool RandomAccessIteratorWrapper::operator==(const RandomAccessIteratorWrapper& rhs) const +{ + return m_iterArray == rhs.m_iterArray; +} + +template +RandomAccessIteratorWrapper RandomAccessIteratorWrapper::operator--(int) +{ + RandomAccessIteratorWrapper tmp(*this); --m_iterArray; return tmp; +} + +template +RandomAccessIteratorWrapper& RandomAccessIteratorWrapper::operator--() +{ + --m_iterArray; return *this; +} + +template +RandomAccessIteratorWrapper& RandomAccessIteratorWrapper::operator-=(const int& rhs) +{ + m_iterArray -= rhs; return *this; +} + +template +T& RandomAccessIteratorWrapper::operator*() +{ + return *m_iterArray; +} + +template +T* RandomAccessIteratorWrapper::operator->() +{ + return &(*m_iterArray); +} + +template +T& RandomAccessIteratorWrapper::operator[](const int& rhs) const +{ + return m_iterArray[rhs]; +} + +template +RandomAccessIteratorWrapper RandomAccessIteratorWrapper::operator++(int) +{ + RandomAccessIteratorWrapper tmp(*this); ++m_iterArray; return tmp; +} + +template +RandomAccessIteratorWrapper& RandomAccessIteratorWrapper::operator++() +{ + ++m_iterArray; return *this; +} + +template +RandomAccessIteratorWrapper RandomAccessIteratorWrapper::operator+(const int& rhs) const +{ + return RandomAccessIteratorWrapper(m_iterArray + rhs); +} + +template +RandomAccessIteratorWrapper RandomAccessIteratorWrapper::operator-(const int& rhs) const +{ + return RandomAccessIteratorWrapper(m_iterArray - rhs); +} + +template +bool RandomAccessIteratorWrapper::operator>=(const RandomAccessIteratorWrapper& rhs) const +{ + return m_iterArray >= rhs.m_iterArray; +} + +template +bool RandomAccessIteratorWrapper::operator>(const RandomAccessIteratorWrapper& rhs) const +{ + return m_iterArray > rhs.m_iterArray; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////// +// class RandomAccessConstIteratorWrapper + +template +RandomAccessConstIteratorWrapper::RandomAccessConstIteratorWrapper(typename std::vector::const_iterator iterArray) : + m_iterArray(iterArray) +{ +} + +template +RandomAccessConstIteratorWrapper::RandomAccessConstIteratorWrapper() +{ +} + +template +RandomAccessConstIteratorWrapper::RandomAccessConstIteratorWrapper(const RandomAccessIteratorWrapper& rIterator) : + m_iterArray(rIterator.m_iterArray) +{ +} + +template +RandomAccessConstIteratorWrapper::~RandomAccessConstIteratorWrapper() +{ +} + +template +RandomAccessConstIteratorWrapper& RandomAccessConstIteratorWrapper::operator=(const RandomAccessIteratorWrapper& rIterator) +{ + m_iterArray = rIterator.m_iterArray; + return *this; +} + +template +RandomAccessConstIteratorWrapper& RandomAccessConstIteratorWrapper::operator+=(const int& rhs) +{ + m_iterArray += rhs; return *this; +} + +template +bool RandomAccessConstIteratorWrapper::operator<=(const RandomAccessConstIteratorWrapper& rhs) const +{ + return m_iterArray <= rhs.m_iterArray; +} + +template +bool RandomAccessConstIteratorWrapper::operator<(const RandomAccessConstIteratorWrapper& rhs) const +{ + return m_iterArray < rhs.m_iterArray; +} + +template +bool RandomAccessConstIteratorWrapper::operator!=(const RandomAccessConstIteratorWrapper& rhs) const +{ + return m_iterArray != rhs.m_iterArray; +} + +template +bool RandomAccessConstIteratorWrapper::operator==(const RandomAccessConstIteratorWrapper& rhs) const +{ + return m_iterArray == rhs.m_iterArray; +} + +template +RandomAccessConstIteratorWrapper RandomAccessConstIteratorWrapper::operator--(int) +{ + RandomAccessConstIteratorWrapper tmp(*this); --m_iterArray; return tmp; +} + +template +RandomAccessConstIteratorWrapper& RandomAccessConstIteratorWrapper::operator--() +{ + --m_iterArray; return *this; +} + +template +RandomAccessConstIteratorWrapper& RandomAccessConstIteratorWrapper::operator-=(const int& rhs) +{ + m_iterArray -= rhs; return *this; +} + +template +const T& RandomAccessConstIteratorWrapper::operator*() +{ + return *m_iterArray; +} + +template +const T* RandomAccessConstIteratorWrapper::operator->() +{ + return &(*m_iterArray); +} + +template +const T& RandomAccessConstIteratorWrapper::operator[](const int& rhs) const +{ + return m_iterArray[rhs]; +} + +template +RandomAccessConstIteratorWrapper RandomAccessConstIteratorWrapper::operator++(int) +{ + RandomAccessConstIteratorWrapper tmp(*this); ++m_iterArray; return tmp; +} + +template +RandomAccessConstIteratorWrapper& RandomAccessConstIteratorWrapper::operator++() +{ + ++m_iterArray; return *this; +} + +template +RandomAccessConstIteratorWrapper RandomAccessConstIteratorWrapper::operator+(const int& rhs) const +{ + return RandomAccessConstIteratorWrapper(m_iterArray + rhs); +} + +template +RandomAccessConstIteratorWrapper RandomAccessConstIteratorWrapper::operator-(const int& rhs) const +{ + return RandomAccessConstIteratorWrapper(m_iterArray - rhs); +} + +template +bool RandomAccessConstIteratorWrapper::operator>=(const RandomAccessConstIteratorWrapper& rhs) const +{ + return m_iterArray >= rhs.m_iterArray; +} + +template +bool RandomAccessConstIteratorWrapper::operator>(const RandomAccessConstIteratorWrapper& rhs) const +{ + return m_iterArray > rhs.m_iterArray; +} + +#endif Index: src/libchcore/TPath.cpp =================================================================== diff -u -r9ddf8fdd5f641491dd30c49eb90f8f740314b6af -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchcore/TPath.cpp (.../TPath.cpp) (revision 9ddf8fdd5f641491dd30c49eb90f8f740314b6af) +++ src/libchcore/TPath.cpp (.../TPath.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -28,40 +28,12 @@ #include "TPathContainer.h" #include "../libstring/TStringArray.h" +#define DEFAULT_PATH_SEPARATOR _T("\\") + using namespace string; namespace chcore { -#define DEFAULT_PATH_SEPARATOR _T("\\") - - // ============================================================================ - /// TSmartPath::TSmartPath - /// @date 2009/11/29 - /// - /// @brief Constructs an empty path. - // ============================================================================ - TSmartPath::TSmartPath() : - m_strPath() - { - } - - // ============================================================================ - /// TSmartPath::~TSmartPath - /// @date 2009/11/29 - /// - /// @brief - /// @return - // ============================================================================ - TSmartPath::~TSmartPath() - { - } - - // ============================================================================ - /// TSmartPath::Clear - /// @date 2009/11/29 - /// - /// @brief Clears this object. - // ============================================================================ void TSmartPath::Clear() throw() { m_strPath.Clear(); Index: src/libchcore/TPath.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchcore/TPath.h (.../TPath.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchcore/TPath.h (.../TPath.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -32,10 +32,6 @@ static const bool DefaultCaseSensitivity = false; public: - // Construction/destruction - TSmartPath(); - ~TSmartPath(); - bool operator==(const TSmartPath& rPath) const; bool operator!=(const TSmartPath& rPath) const; bool operator<(const TSmartPath& rPath) const; Index: src/libchcore/TPathContainer.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchcore/TPathContainer.cpp (.../TPathContainer.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchcore/TPathContainer.cpp (.../TPathContainer.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -24,139 +24,4 @@ namespace chcore { - // ============================================================================ - /// TPathContainer::TPathContainer - /// @date 2009/11/30 - /// - /// @brief Constructs an empty path container object. - // ============================================================================ - TPathContainer::TPathContainer() : - m_vPaths() - { - } - - // ============================================================================ - /// TPathContainer::~TPathContainer - /// @date 2009/11/30 - /// - /// @brief Destructs this path container object. - // ============================================================================ - TPathContainer::~TPathContainer() - { - } - - // ============================================================================ - /// 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 TCoreException(eErr_BoundsExceeded, L"stIndex", LOCATION); - - 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 TCoreException(eErr_BoundsExceeded, L"stIndex", LOCATION); - - return m_vPaths.at(stIndex); - } - - // ============================================================================ - /// 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 TCoreException(eErr_BoundsExceeded, L"stIndex", LOCATION); - - m_vPaths[stIndex] = spPath; - } - - // ============================================================================ - /// 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 TCoreException(eErr_BoundsExceeded, L"stIndex", LOCATION); - - m_vPaths.erase(m_vPaths.begin() + stIndex); - } - - // ============================================================================ - /// TPathContainer::Clear - /// @date 2009/11/30 - /// - /// @brief Removes all paths from this container. - // ============================================================================ - void TPathContainer::Clear() - { - m_vPaths.clear(); - } - - // ============================================================================ - /// 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(); - } - - // ============================================================================ - /// 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(); - } } Index: src/libchcore/TPathContainer.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchcore/TPathContainer.h (.../TPathContainer.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchcore/TPathContainer.h (.../TPathContainer.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -20,34 +20,24 @@ #define __TPATHCONTAINER_H__ #include "TPath.h" +#include "../common/GenericTemplates/RandomAccessIterators.h" +#include "../common/GenericTemplates/RandomAccessContainerWrapper.h" namespace chcore { - class LIBCHCORE_API TPathContainer + template class LIBCHCORE_API RandomAccessIteratorWrapper; + class LIBCHCORE_API TPathArrayIterator : public RandomAccessIteratorWrapper { - public: - TPathContainer(); - ~TPathContainer(); + }; - void Add(const TSmartPath& spPath); - void Append(const TPathContainer& vPaths); + template class LIBCHCORE_API RandomAccessConstIteratorWrapper; + class LIBCHCORE_API TPathArrayConstIterator : public RandomAccessConstIteratorWrapper + { + }; - 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; - - private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector m_vPaths; -#pragma warning(pop) + template class LIBCHCORE_API RandomAccessContainerWrapper; + class LIBCHCORE_API TPathContainer : public RandomAccessContainerWrapper + { }; } Index: src/libchcore/Tests/TestsTPathContainer.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsTPathContainer.cpp (revision 0) +++ src/libchcore/Tests/TestsTPathContainer.cpp (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -0,0 +1,245 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TPathContainer.h" + +using namespace chcore; +using namespace string; + +TEST(TestsTPathContainer, DefaultConstruction) +{ + TPathContainer arrStrings; + + EXPECT_EQ(0, arrStrings.GetCount()); +} + +TEST(TestsTPathContainer, AddElements) +{ + TPathContainer arrStrings; + + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + EXPECT_EQ(2, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString1", arrStrings.GetAt(0).ToWString().c_str()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(1).ToWString().c_str()); +} + +TEST(TestsTPathContainer, SetAt) +{ + TPathContainer arrStrings; + + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + arrStrings.SetAt(0, PathFromString(L"SomeString3")); + + EXPECT_EQ(2, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString3", arrStrings.GetAt(0).ToWString().c_str()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(1).ToWString().c_str()); +} + +TEST(TestsTPathContainer, SetAt_OutOfRange) +{ + TPathContainer arrStrings; + + EXPECT_THROW(arrStrings.SetAt(0, PathFromString(L"SomeString3")), std::out_of_range); +} + +TEST(TestsTPathContainer, RemoveAt) +{ + TPathContainer arrStrings; + + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + arrStrings.RemoveAt(0); + + EXPECT_EQ(1, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(0).ToWString().c_str()); +} + +TEST(TestsTPathContainer, RemoveAt_OutOfRange) +{ + TPathContainer arrStrings; + + EXPECT_THROW(arrStrings.RemoveAt(0), std::out_of_range); +} + +TEST(TestsTPathContainer, Clear) +{ + TPathContainer arrStrings; + + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + arrStrings.Clear(); + + EXPECT_EQ(0, arrStrings.GetCount()); +} + +TEST(TestsTPathContainer, Compare_Empty) +{ + TPathContainer arrStrings1, arrStrings2; + + EXPECT_TRUE(arrStrings1 == arrStrings2); +} + +TEST(TestsTPathContainer, Compare_Full_Same) +{ + TPathContainer arrStrings1; + + arrStrings1.Add(PathFromString(L"SomeString1")); + arrStrings1.Add(PathFromString(L"SomeString2")); + + TPathContainer arrStrings2; + + arrStrings2.Add(PathFromString(L"SomeString1")); + arrStrings2.Add(PathFromString(L"SomeString2")); + + EXPECT_TRUE(arrStrings1 == arrStrings2); +} + +TEST(TestsTPathContainer, Compare_Full_NotSame) +{ + TPathContainer arrStrings1; + + arrStrings1.Add(PathFromString(L"SomeString1")); + arrStrings1.Add(PathFromString(L"SomeString2")); + + TPathContainer arrStrings2; + + arrStrings2.Add(PathFromString(L"SomeString1")); + arrStrings2.Add(PathFromString(L"SomeString3")); + + EXPECT_FALSE(arrStrings1 == arrStrings2); +} + +TEST(TestsTPathContainer, NegativeCompare_Empty) +{ + TPathContainer arrStrings1, arrStrings2; + + EXPECT_FALSE(arrStrings1 != arrStrings2); +} + +TEST(TestsTPathContainer, NegativeCompare_Full_Same) +{ + TPathContainer arrStrings1; + + arrStrings1.Add(PathFromString(L"SomeString1")); + arrStrings1.Add(PathFromString(L"SomeString2")); + + TPathContainer arrStrings2; + + arrStrings2.Add(PathFromString(L"SomeString1")); + arrStrings2.Add(PathFromString(L"SomeString2")); + + EXPECT_FALSE(arrStrings1 != arrStrings2); +} + +TEST(TestsTPathContainer, NegativeCompare_Full_Different) +{ + TPathContainer arrStrings1; + + arrStrings1.Add(PathFromString(L"SomeString1")); + arrStrings1.Add(PathFromString(L"SomeString2")); + + TPathContainer arrStrings2; + + arrStrings2.Add(PathFromString(L"SomeString1")); + arrStrings2.Add(PathFromString(L"SomeString3")); + + EXPECT_TRUE(arrStrings1 != arrStrings2); +} + +// iterators +TEST(TestsTPathContainer, Iterate_Empty) +{ + TPathContainer arrStrings; + const TPathContainer arrStrings2; + + EXPECT_EQ(arrStrings.begin(), arrStrings.end()); + EXPECT_EQ(arrStrings.cbegin(), arrStrings.cend()); + EXPECT_EQ(arrStrings2.begin(), arrStrings2.end()); + EXPECT_EQ(arrStrings2.cbegin(), arrStrings2.cend()); +} + +TEST(TestsTPathContainer, Iterate_BeginEnd) +{ + TPathContainer arrStrings; + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + TPathContainer::iterator iter = arrStrings.begin(); + + EXPECT_EQ(PathFromString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(PathFromString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, arrStrings.end()); +} + +TEST(TestsTPathContainer, Iterate_CBeginCEnd) +{ + TPathContainer arrStrings; + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + TPathContainer::const_iterator iter = arrStrings.cbegin(); + + EXPECT_EQ(PathFromString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(PathFromString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, arrStrings.cend()); +} + +TEST(TestsTPathContainer, Iterate_ConstBeginEnd) +{ + TPathContainer arrStrings; + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + const TPathContainer& rArray = arrStrings; + + TPathContainer::const_iterator iter = rArray.begin(); + + EXPECT_EQ(PathFromString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(PathFromString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, rArray.end()); +} + +TEST(TestsTPathContainer, NewFor_Empty) +{ + TPathContainer arrStrings; + + int iCount = 0; + for (const TSmartPath& strData : arrStrings) + { + strData; + ++iCount; + } + + EXPECT_EQ(0, iCount); +} + +TEST(TestsTPathContainer, NewFor_Full) +{ + TPathContainer arrStrings; + arrStrings.Add(PathFromString(L"SomeString1")); + arrStrings.Add(PathFromString(L"SomeString2")); + + int iCount = 0; + for (const TSmartPath& strData : arrStrings) + { + if (iCount == 0) + EXPECT_EQ(PathFromString(L"SomeString1"), strData); + else if (iCount == 0) + EXPECT_EQ(PathFromString(L"SomeString2"), strData); + ++iCount; + } + + EXPECT_EQ(2, iCount); +} Index: src/libchcore/libchcore.vc140.vcxproj =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -471,6 +471,8 @@ + + @@ -513,6 +515,7 @@ + true true Index: src/libchcore/libchcore.vc140.vcxproj.filters =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -27,6 +27,9 @@ {6c5d3d2d-292d-45f1-a74d-8b3047a68694} + + {1b7aada1-f6a4-45f3-821c-ac3f7e589a05} + @@ -96,6 +99,12 @@ Source Files\Tools\IPC + + Source Files\Shared + + + Source Files\Shared + @@ -155,6 +164,9 @@ Source Files\Tools\IPC + + Tests + Index: src/libchengine/TFileFilter.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchengine/TFileFilter.cpp (.../TFileFilter.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TFileFilter.cpp (.../TFileFilter.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -98,6 +98,85 @@ { } + bool TFileFilter::operator==(const TFileFilter& rSrc) const + { + // files mask + if (m_bUseMask.Get() != rSrc.m_bUseMask.Get()) + return false; + if (m_astrMask.Get() != rSrc.m_astrMask.Get()) + return false; + + // files mask- + if (m_bUseExcludeMask.Get() != m_bUseExcludeMask.Get()) + return false; + if (m_astrExcludeMask.Get() != m_astrExcludeMask.Get()) + return false; + + // size filtering + if (m_bUseSize1.Get() != m_bUseSize1.Get()) + return false; + if (m_eSizeCmpType1.Get() != m_eSizeCmpType1.Get()) + return false; + if (m_ullSize1.Get() != m_ullSize1.Get()) + return false; + + if (m_bUseSize2.Get() != m_bUseSize2.Get()) + return false; + if (m_eSizeCmpType2.Get() != m_eSizeCmpType2.Get()) + return false; + if (m_ullSize2.Get() != m_ullSize2.Get()) + return false; + + // date filtering + if (m_eDateType.Get() != m_eDateType.Get()) + return false; + + if (m_bUseDateTime1.Get() != m_bUseDateTime1.Get()) + return false; + + if (m_eDateCmpType1.Get() != m_eDateCmpType1.Get()) + return false; + if (m_bUseDate1.Get() != m_bUseDate1.Get()) + return false; + if (m_bUseTime1.Get() != m_bUseTime1.Get()) + return false; + if (m_tDateTime1.Get() != m_tDateTime1.Get()) + return false; + + if (m_bUseDateTime2.Get() != m_bUseDateTime2.Get()) + return false; + + if (m_eDateCmpType2.Get() != m_eDateCmpType2.Get()) + return false; + if (m_bUseDate2.Get() != m_bUseDate2.Get()) + return false; + if (m_bUseTime2.Get() != m_bUseTime2.Get()) + return false; + if (m_tDateTime2.Get() != m_tDateTime2.Get()) + return false; + + // attribute filtering + if (m_bUseAttributes.Get() != m_bUseAttributes.Get()) + return false; + if (m_iArchive.Get() != m_iArchive.Get()) + return false; + if (m_iReadOnly.Get() != m_iReadOnly.Get()) + return false; + if (m_iHidden.Get() != m_iHidden.Get()) + return false; + if (m_iSystem.Get() != m_iSystem.Get()) + return false; + if (m_iDirectory.Get() != m_iDirectory.Get()) + return false; + + return true; + } + + bool TFileFilter::operator!=(const TFileFilter& rSrc) const + { + return !operator==(rSrc); + } + TFileFilter& TFileFilter::operator=(const TFileFilter& rFilter) { if (this == &rFilter) Index: src/libchengine/TFileFilter.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchengine/TFileFilter.h (.../TFileFilter.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TFileFilter.h (.../TFileFilter.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -64,6 +64,9 @@ TFileFilter(const TFileFilter& rFilter); TFileFilter& operator=(const TFileFilter& rFilter); + bool operator==(const TFileFilter& rSrc) const; + bool operator!=(const TFileFilter& rSrc) const; + void SetData(const TFileFilter& rSrc); // matching Index: src/libchengine/TFileFiltersArray.cpp =================================================================== diff -u -r9ddf8fdd5f641491dd30c49eb90f8f740314b6af -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchengine/TFileFiltersArray.cpp (.../TFileFiltersArray.cpp) (revision 9ddf8fdd5f641491dd30c49eb90f8f740314b6af) +++ src/libchengine/TFileFiltersArray.cpp (.../TFileFiltersArray.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -28,21 +28,13 @@ namespace chengine { - TFileFiltersArray::TFileFiltersArray() - { - } - - TFileFiltersArray::~TFileFiltersArray() - { - } - bool TFileFiltersArray::Match(const TFileInfoPtr& spInfo) const { - if (m_vFilters.empty()) + if (m_vItems.empty()) return true; // if only one of the filters matches - return true - for (std::vector::const_iterator iterFilter = m_vFilters.begin(); iterFilter != m_vFilters.end(); ++iterFilter) + for (std::vector::const_iterator iterFilter = m_vItems.begin(); iterFilter != m_vItems.end(); ++iterFilter) { if ((*iterFilter).Match(spInfo)) return true; @@ -54,7 +46,7 @@ void TFileFiltersArray::StoreInConfig(TConfig& rConfig, PCTSTR pszNodeName) const { rConfig.DeleteNode(pszNodeName); - for(const TFileFilter& rFilter : m_vFilters) + for(const TFileFilter& rFilter : m_vItems) { TConfig cfgNode; rFilter.StoreInConfig(cfgNode); @@ -66,7 +58,7 @@ bool TFileFiltersArray::ReadFromConfig(const TConfig& rConfig, PCTSTR pszNodeName) { - m_vFilters.clear(); + m_vItems.clear(); TConfigArray vConfigs; if (!rConfig.ExtractMultiSubConfigs(pszNodeName, vConfigs)) @@ -78,80 +70,19 @@ TFileFilter tFilter; tFilter.ReadFromConfig(rCfg); - m_vFilters.push_back(tFilter); + m_vItems.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 - { - BOOST_ASSERT(stIndex < m_vFilters.size()); - if (stIndex < m_vFilters.size()) - return &m_vFilters.at(stIndex); - - return nullptr; - } - - 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::GetSize() 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_vFilters) + for(const TFileFilter& rFilter : m_vItems) { rFilter.Store(spContainer); } @@ -169,7 +100,7 @@ tFileFilter.ResetModifications(); - m_vFilters.push_back(tFileFilter); + m_vItems.push_back(tFileFilter); } } Index: src/libchengine/TFileFiltersArray.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchengine/TFileFiltersArray.h (.../TFileFiltersArray.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TFileFiltersArray.h (.../TFileFiltersArray.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -21,19 +21,30 @@ #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; - class LIBCHENGINE_API TFileFiltersArray + template class LIBCHENGINE_API RandomAccessIteratorWrapper; + class LIBCHENGINE_API TFileFiltersArrayIterator : public RandomAccessIteratorWrapper { - public: - TFileFiltersArray(); - ~TFileFiltersArray(); + }; + template class LIBCHENGINE_API RandomAccessConstIteratorWrapper; + class LIBCHENGINE_API TFileFiltersArrayConstIterator : public RandomAccessConstIteratorWrapper + { + }; + + template class LIBCHENGINE_API RandomAccessContainerWrapper; + + class LIBCHENGINE_API TFileFiltersArray : public RandomAccessContainerWrapper + { + public: bool Match(const TFileInfoPtr& spInfo) const; void StoreInConfig(TConfig& rConfig, PCTSTR pszNodeName) const; @@ -44,21 +55,7 @@ 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 GetSize() 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/TTaskConfigTracker.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libchengine/TTaskConfigTracker.cpp (.../TTaskConfigTracker.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/TTaskConfigTracker.cpp (.../TTaskConfigTracker.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -134,12 +134,9 @@ void TTaskConfigTracker::AddModified(const TStringSet& setModified) { - TStringSet::const_iterator iterBegin = setModified.Begin(); - TStringSet::const_iterator iterEnd = setModified.End(); - - for (; iterBegin != iterEnd; ++iterBegin) + for (const TString& strMod : setModified) { - AddModified(*iterBegin); + AddModified(strMod); } } Index: src/libstring/TStringArray.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringArray.cpp (.../TStringArray.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringArray.cpp (.../TStringArray.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -22,204 +22,7 @@ // ============================================================================ #include "stdafx.h" #include "TStringArray.h" -#include "TStringException.h" namespace string { - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // class TStringArrayIterator - - TStringArrayIterator::TStringArrayIterator(std::vector::iterator iterArray) : - m_iterArray(iterArray) - { - } - - TStringArrayIterator::TStringArrayIterator() - { - } - - TStringArrayIterator::~TStringArrayIterator() - { - } - - TStringArrayIterator TStringArrayIterator::operator++(int) - { - TStringArrayIterator iterCurrent = *this; - ++m_iterArray; - return iterCurrent; - } - - TStringArrayIterator& TStringArrayIterator::operator++() - { - ++m_iterArray; - return *this; - } - - bool TStringArrayIterator::operator==(const TStringArrayIterator& rSrc) const - { - return m_iterArray == rSrc.m_iterArray; - } - - bool TStringArrayIterator::operator!=(const TStringArrayIterator& rSrc) const - { - return m_iterArray != rSrc.m_iterArray; - } - - TString& TStringArrayIterator::operator*() - { - return *m_iterArray; - } - - const TString& TStringArrayIterator::operator*() const - { - return *m_iterArray; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // class TStringArrayConstIterator - - TStringArrayConstIterator::TStringArrayConstIterator(std::vector::const_iterator iterArray) : - m_iterArray(iterArray) - { - } - - TStringArrayConstIterator::TStringArrayConstIterator() - { - } - - TStringArrayConstIterator::~TStringArrayConstIterator() - { - } - - TStringArrayConstIterator TStringArrayConstIterator::operator++(int) - { - TStringArrayConstIterator iterCurrent = *this; - ++m_iterArray; - return iterCurrent; - } - - TStringArrayConstIterator& TStringArrayConstIterator::operator++() - { - ++m_iterArray; - return *this; - } - - bool TStringArrayConstIterator::operator==(const TStringArrayConstIterator& rSrc) const - { - return m_iterArray == rSrc.m_iterArray; - } - - bool TStringArrayConstIterator::operator!=(const TStringArrayConstIterator& rSrc) const - { - return m_iterArray != rSrc.m_iterArray; - } - - const TString& TStringArrayConstIterator::operator*() - { - return *m_iterArray; - } - - const TString& TStringArrayConstIterator::operator*() const - { - return *m_iterArray; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////// - // class TStringArray - void TStringArray::Add(const TString& str) - { - m_vItems.push_back(str); - } - - void TStringArray::InsertAt(size_t stIndex, const TString& str) - { - if (stIndex >= m_vItems.size()) - throw TStringException("stIndex out of bounds"); - - m_vItems.insert(m_vItems.begin() + stIndex, str); - } - - void TStringArray::SetAt(size_t stIndex, const TString& str) - { - if (stIndex >= m_vItems.size()) - throw TStringException("stIndex out of bounds"); - - m_vItems[stIndex] = str; - } - - void TStringArray::RemoveAt(size_t stIndex) - { - if (stIndex >= m_vItems.size()) - throw TStringException("stIndex out of bounds"); - - m_vItems.erase(m_vItems.begin() + stIndex); - } - - void TStringArray::Clear() - { - m_vItems.clear(); - } - - const TString& TStringArray::GetAt(size_t stIndex) const - { - if (stIndex >= m_vItems.size()) - throw TStringException("stIndex out of bounds"); - - return m_vItems.at(stIndex); - } - - size_t TStringArray::GetCount() const - { - return m_vItems.size(); - } - - TStringArrayIterator TStringArray::Begin() - { - return TStringArrayIterator(m_vItems.begin()); - } - - TStringArrayIterator TStringArray::End() - { - return TStringArrayIterator(m_vItems.end()); - } - - TStringArrayConstIterator TStringArray::Begin() const - { - return TStringArrayConstIterator(m_vItems.begin()); - } - - TStringArrayConstIterator TStringArray::End() const - { - return TStringArrayConstIterator(m_vItems.end()); - } - - bool TStringArray::operator==(const TStringArray& 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; - } - - bool TStringArray::operator!=(const TStringArray& 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; - } } Index: src/libstring/TStringArray.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringArray.h (.../TStringArray.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringArray.h (.../TStringArray.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -26,92 +26,24 @@ #include "TString.h" #include "libstring.h" #include +#include "../common/GenericTemplates/RandomAccessIterators.h" +#include "../common/GenericTemplates/RandomAccessContainerWrapper.h" namespace string { - class LIBSTRING_API TStringArrayIterator + template class LIBSTRING_API RandomAccessIteratorWrapper; + class LIBSTRING_API TStringArrayIterator : public RandomAccessIteratorWrapper { - protected: - explicit TStringArrayIterator(std::vector::iterator iterArray); - - public: - TStringArrayIterator(); - ~TStringArrayIterator(); - - TStringArrayIterator operator++(int); - TStringArrayIterator& operator++(); - - bool operator==(const TStringArrayIterator& rSrc) const; - bool operator!=(const TStringArrayIterator& rSrc) const; - - TString& operator*(); - const TString& operator*() const; - - private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector::iterator m_iterArray; -#pragma warning(pop) - - friend class TStringArray; }; - class LIBSTRING_API TStringArrayConstIterator + template class LIBSTRING_API RandomAccessConstIteratorWrapper; + class LIBSTRING_API TStringArrayConstIterator : public RandomAccessConstIteratorWrapper { - protected: - explicit TStringArrayConstIterator(std::vector::const_iterator iterArray); - - public: - TStringArrayConstIterator(); - ~TStringArrayConstIterator(); - - TStringArrayConstIterator operator++(int); - TStringArrayConstIterator& operator++(); - - bool operator==(const TStringArrayConstIterator& rSrc) const; - bool operator!=(const TStringArrayConstIterator& rSrc) const; - - const TString& operator*(); - const TString& operator*() const; - - private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector::const_iterator m_iterArray; -#pragma warning(pop) - - friend class TStringArray; }; - class LIBSTRING_API TStringArray + template class LIBSTRING_API RandomAccessContainerWrapper; + class LIBSTRING_API TStringArray : public RandomAccessContainerWrapper { - public: - typedef TStringArrayIterator iterator; - typedef TStringArrayConstIterator const_iterator; - - public: - bool operator==(const TStringArray& rSrc) const; - bool operator!=(const TStringArray& rSrc) const; - - void Add(const TString& str); - void InsertAt(size_t stIndex, const TString& str); - void SetAt(size_t stIndex, const TString& str); - void RemoveAt(size_t stIndex); - void Clear(); - - const TString& GetAt(size_t stIndex) const; - size_t GetCount() const; - - TStringArrayIterator Begin(); - TStringArrayIterator End(); - TStringArrayConstIterator Begin() const; - TStringArrayConstIterator End() const; - - private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector m_vItems; -#pragma warning(pop) }; } Index: src/libstring/TStringPattern.cpp =================================================================== diff -u -r9ddf8fdd5f641491dd30c49eb90f8f740314b6af -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringPattern.cpp (.../TStringPattern.cpp) (revision 9ddf8fdd5f641491dd30c49eb90f8f740314b6af) +++ src/libstring/TStringPattern.cpp (.../TStringPattern.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -59,6 +59,16 @@ return TString(strPrefix + m_strPattern); } + bool TStringPattern::operator!=(const TStringPattern& rSrc) const + { + return m_ePatternType != rSrc.m_ePatternType || m_strPattern != rSrc.m_strPattern; + } + + bool TStringPattern::operator==(const TStringPattern& rSrc) const + { + return m_ePatternType == rSrc.m_ePatternType && m_strPattern == rSrc.m_strPattern; + } + bool TStringPattern::MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const { bool bMatch = true; Index: src/libstring/TStringPattern.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringPattern.h (.../TStringPattern.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringPattern.h (.../TStringPattern.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -47,6 +47,9 @@ void FromString(const TString& strPattern, EPatternType eDefaultPatternType = EPatternType::eType_Wildcard); TString ToString() const; + bool operator==(const TStringPattern& rSrc) const; + bool operator!=(const TStringPattern& rSrc) const; + private: bool MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const; bool Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const; Index: src/libstring/TStringPatternArray.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringPatternArray.cpp (.../TStringPatternArray.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringPatternArray.cpp (.../TStringPatternArray.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -23,56 +23,9 @@ namespace string { - void TStringPatternArray::Add(const TStringPattern& strPattern) - { - m_vPatterns.push_back(strPattern); - } - - void TStringPatternArray::InsertAt(size_t stIndex, const TStringPattern& strPattern) - { - if (stIndex > m_vPatterns.size()) - throw TStringException("stIndex out of bounds"); - - m_vPatterns.insert(m_vPatterns.begin() + stIndex, strPattern); - } - - void TStringPatternArray::SetAt(size_t stIndex, const TStringPattern& strPattern) - { - if (stIndex >= m_vPatterns.size()) - throw TStringException("stIndex out of bounds"); - - m_vPatterns[stIndex] = strPattern; - } - - void TStringPatternArray::RemoveAt(size_t stIndex) - { - if (stIndex >= m_vPatterns.size()) - throw TStringException("stIndex out of bounds"); - - m_vPatterns.erase(m_vPatterns.begin() + stIndex); - } - - void TStringPatternArray::Clear() - { - m_vPatterns.clear(); - } - - const TStringPattern& TStringPatternArray::GetAt(size_t stIndex) const - { - if (stIndex >= m_vPatterns.size()) - throw TStringException("stIndex out of bounds"); - - return m_vPatterns[stIndex]; - } - - size_t TStringPatternArray::GetCount() const - { - return m_vPatterns.size(); - } - bool TStringPatternArray::MatchesAny(const TString& strTextToMatch) const { - for (const TStringPattern& pattern : m_vPatterns) + for (const TStringPattern& pattern : m_vItems) { if (pattern.Matches(strTextToMatch)) return true; @@ -83,7 +36,7 @@ bool TStringPatternArray::MatchesAll(const TString& strTextToMatch) const { - for (const TStringPattern& pattern : m_vPatterns) + for (const TStringPattern& pattern : m_vItems) { if (!pattern.Matches(strTextToMatch)) return false; @@ -101,11 +54,11 @@ void TStringPatternArray::FromSerializedStringArray(const TStringArray& arrSerializedPatterns) { - m_vPatterns.clear(); + m_vItems.clear(); for (size_t stIndex = 0; stIndex < arrSerializedPatterns.GetCount(); ++stIndex) { - m_vPatterns.push_back(TStringPattern::CreateFromString(arrSerializedPatterns.GetAt(stIndex))); + m_vItems.push_back(TStringPattern::CreateFromString(arrSerializedPatterns.GetAt(stIndex))); } } @@ -136,7 +89,7 @@ TStringArray TStringPatternArray::ToSerializedStringArray() const { TStringArray arrSerialized; - for (const TStringPattern& pattern : m_vPatterns) + for (const TStringPattern& pattern : m_vItems) { arrSerialized.Add(pattern.ToString()); } Index: src/libstring/TStringPatternArray.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringPatternArray.h (.../TStringPatternArray.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringPatternArray.h (.../TStringPatternArray.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -20,22 +20,26 @@ #define __TSTRINGPATTERNARRAY_H__ #include "TStringPattern.h" +#include "../common/GenericTemplates/RandomAccessIterators.h" +#include "../common/GenericTemplates/RandomAccessContainerWrapper.h" namespace string { - class LIBSTRING_API TStringPatternArray + template class LIBSTRING_API RandomAccessIteratorWrapper; + class LIBSTRING_API TStringPatternArrayIterator : public RandomAccessIteratorWrapper { - public: - // general api - void Add(const TStringPattern& strPattern); - void InsertAt(size_t stIndex, const TStringPattern& strPattern); - void SetAt(size_t stIndex, const TStringPattern& strPattern); - void RemoveAt(size_t stIndex); - void Clear(); + }; - const TStringPattern& GetAt(size_t stIndex) const; - size_t GetCount() const; + template class LIBSTRING_API RandomAccessConstIteratorWrapper; + class LIBSTRING_API TStringPatternArrayConstIterator : public RandomAccessConstIteratorWrapper + { + }; + template class LIBSTRING_API RandomAccessContainerWrapper; + + class LIBSTRING_API TStringPatternArray : public RandomAccessContainerWrapper + { + public: // pattern api bool MatchesAny(const TString& strTextToMatch) const; bool MatchesAll(const TString& strTextToMatch) const; @@ -48,12 +52,6 @@ // serialization void FromSerializedStringArray(const TStringArray& arrSerializedPatterns); TStringArray ToSerializedStringArray() const; - - private: -#pragma warning(push) -#pragma warning(disable: 4251) - std::vector m_vPatterns; -#pragma warning(pop) }; } Index: src/libstring/TStringSet.cpp =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringSet.cpp (.../TStringSet.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringSet.cpp (.../TStringSet.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -157,23 +157,33 @@ return m_setItems.empty(); } - TStringSetIterator TStringSet::Begin() + TStringSet::iterator TStringSet::begin() { return TStringSetIterator(m_setItems.begin()); } - TStringSetIterator TStringSet::End() + TStringSet::iterator TStringSet::end() { return TStringSetIterator(m_setItems.end()); } - TStringSetConstIterator TStringSet::Begin() const + TStringSet::const_iterator TStringSet::begin() const { return TStringSetConstIterator(m_setItems.begin()); } - TStringSetConstIterator TStringSet::End() const + TStringSet::const_iterator TStringSet::end() const { return TStringSetConstIterator(m_setItems.end()); } + + TStringSet::const_iterator TStringSet::cbegin() const + { + return TStringSetConstIterator(m_setItems.begin()); + } + + TStringSet::const_iterator TStringSet::cend() const + { + return TStringSetConstIterator(m_setItems.end()); + } } Index: src/libstring/TStringSet.h =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/TStringSet.h (.../TStringSet.h) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/TStringSet.h (.../TStringSet.h) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -96,10 +96,12 @@ size_t GetCount() const; bool IsEmpty() const; - TStringSetIterator Begin(); - TStringSetIterator End(); - TStringSetConstIterator Begin() const; - TStringSetConstIterator End() const; + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + const_iterator cbegin() const; + const_iterator cend() const; private: #pragma warning(push) Index: src/libstring/Tests/TestsTString.cpp =================================================================== diff -u -r1019bc9df4e044491b7102c37c8cac33cf56fb4a -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/Tests/TestsTString.cpp (.../TestsTString.cpp) (revision 1019bc9df4e044491b7102c37c8cac33cf56fb4a) +++ src/libstring/Tests/TestsTString.cpp (.../TestsTString.cpp) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -425,7 +425,7 @@ EXPECT_EQ(arrSplitted.GetAt(6), _T("")); EXPECT_EQ(arrSplitted.GetAt(7), _T("")); EXPECT_EQ(arrSplitted.GetAt(8), _T("")); - EXPECT_THROW(arrSplitted.GetAt(9), TStringException); + EXPECT_THROW(arrSplitted.GetAt(9), std::out_of_range); } TEST(TStringTests, Split_NormalStringMultipleSeparators) @@ -442,7 +442,7 @@ EXPECT_EQ(arrSplitted.GetAt(6), _T("")); EXPECT_EQ(arrSplitted.GetAt(7), _T("")); EXPECT_EQ(arrSplitted.GetAt(8), _T("")); - EXPECT_THROW(arrSplitted.GetAt(9), TStringException); + EXPECT_THROW(arrSplitted.GetAt(9), std::out_of_range); } TEST(TStringTests, CompareCaseSensitive_WithPtrToString) Index: src/libstring/Tests/TestsTStringArray.cpp =================================================================== diff -u --- src/libstring/Tests/TestsTStringArray.cpp (revision 0) +++ src/libstring/Tests/TestsTStringArray.cpp (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -0,0 +1,264 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TStringArray.h" +#include "../TStringException.h" + +using namespace string; + +TEST(TestsTStringArray, DefaultConstruction) +{ + TStringArray arrStrings; + + EXPECT_EQ(0, arrStrings.GetCount()); +} + +TEST(TestsTStringArray, AddElements) +{ + TStringArray arrStrings; + + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + EXPECT_EQ(2, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString1", arrStrings.GetAt(0).c_str()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(1).c_str()); +} + +TEST(TestsTStringArray, InsertAt) +{ + TStringArray arrStrings; + + arrStrings.InsertAt(0, TString(L"SomeString1")); + arrStrings.InsertAt(0, TString(L"SomeString2")); + + EXPECT_EQ(2, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString1", arrStrings.GetAt(1).c_str()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(0).c_str()); +} + +TEST(TestsTStringArray, InsertAt_OutOfRange) +{ + TStringArray arrStrings; + + EXPECT_THROW(arrStrings.InsertAt(1, TString(L"SomeString1")), std::out_of_range); +} + +TEST(TestsTStringArray, SetAt) +{ + TStringArray arrStrings; + + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + arrStrings.SetAt(0, TString(L"SomeString3")); + + EXPECT_EQ(2, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString3", arrStrings.GetAt(0).c_str()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(1).c_str()); +} + +TEST(TestsTStringArray, SetAt_OutOfRange) +{ + TStringArray arrStrings; + + EXPECT_THROW(arrStrings.SetAt(0, TString(L"SomeString3")), std::out_of_range); +} + +TEST(TestsTStringArray, RemoveAt) +{ + TStringArray arrStrings; + + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + arrStrings.RemoveAt(0); + + EXPECT_EQ(1, arrStrings.GetCount()); + EXPECT_STREQ(L"SomeString2", arrStrings.GetAt(0).c_str()); +} + +TEST(TestsTStringArray, RemoveAt_OutOfRange) +{ + TStringArray arrStrings; + + EXPECT_THROW(arrStrings.RemoveAt(0), std::out_of_range); +} + +TEST(TestsTStringArray, Clear) +{ + TStringArray arrStrings; + + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + arrStrings.Clear(); + + EXPECT_EQ(0, arrStrings.GetCount()); +} + +TEST(TestsTStringArray, Compare_Empty) +{ + TStringArray arrStrings1, arrStrings2; + + EXPECT_TRUE(arrStrings1 == arrStrings2); +} + +TEST(TestsTStringArray, Compare_Full_Same) +{ + TStringArray arrStrings1; + + arrStrings1.Add(TString(L"SomeString1")); + arrStrings1.Add(TString(L"SomeString2")); + + TStringArray arrStrings2; + + arrStrings2.Add(TString(L"SomeString1")); + arrStrings2.Add(TString(L"SomeString2")); + + EXPECT_TRUE(arrStrings1 == arrStrings2); +} + +TEST(TestsTStringArray, Compare_Full_NotSame) +{ + TStringArray arrStrings1; + + arrStrings1.Add(TString(L"SomeString1")); + arrStrings1.Add(TString(L"SomeString2")); + + TStringArray arrStrings2; + + arrStrings2.Add(TString(L"SomeString1")); + arrStrings2.Add(TString(L"SomeString3")); + + EXPECT_FALSE(arrStrings1 == arrStrings2); +} + +TEST(TestsTStringArray, NegativeCompare_Empty) +{ + TStringArray arrStrings1, arrStrings2; + + EXPECT_FALSE(arrStrings1 != arrStrings2); +} + +TEST(TestsTStringArray, NegativeCompare_Full_Same) +{ + TStringArray arrStrings1; + + arrStrings1.Add(TString(L"SomeString1")); + arrStrings1.Add(TString(L"SomeString2")); + + TStringArray arrStrings2; + + arrStrings2.Add(TString(L"SomeString1")); + arrStrings2.Add(TString(L"SomeString2")); + + EXPECT_FALSE(arrStrings1 != arrStrings2); +} + +TEST(TestsTStringArray, NegativeCompare_Full_Different) +{ + TStringArray arrStrings1; + + arrStrings1.Add(TString(L"SomeString1")); + arrStrings1.Add(TString(L"SomeString2")); + + TStringArray arrStrings2; + + arrStrings2.Add(TString(L"SomeString1")); + arrStrings2.Add(TString(L"SomeString3")); + + EXPECT_TRUE(arrStrings1 != arrStrings2); +} + +// iterators +TEST(TestsTStringArray, Iterate_Empty) +{ + TStringArray arrStrings; + const TStringArray arrStrings2; + + EXPECT_EQ(arrStrings.begin(), arrStrings.end()); + EXPECT_EQ(arrStrings.cbegin(), arrStrings.cend()); + EXPECT_EQ(arrStrings2.begin(), arrStrings2.end()); + EXPECT_EQ(arrStrings2.cbegin(), arrStrings2.cend()); +} + +TEST(TestsTStringArray, Iterate_BeginEnd) +{ + TStringArray arrStrings; + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + TStringArray::iterator iter = arrStrings.begin(); + + EXPECT_EQ(TString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(TString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, arrStrings.end()); +} + +TEST(TestsTStringArray, Iterate_CBeginCEnd) +{ + TStringArray arrStrings; + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + TStringArray::const_iterator iter = arrStrings.cbegin(); + + EXPECT_EQ(TString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(TString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, arrStrings.cend()); +} + +TEST(TestsTStringArray, Iterate_ConstBeginEnd) +{ + TStringArray arrStrings; + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + const TStringArray& rArray = arrStrings; + + TStringArray::const_iterator iter = rArray.begin(); + + EXPECT_EQ(TString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(TString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, rArray.end()); +} + +TEST(TestsTStringArray, NewFor_Empty) +{ + TStringArray arrStrings; + + int iCount = 0; + for (const TString& strData : arrStrings) + { + strData; + ++iCount; + } + + EXPECT_EQ(0, iCount); +} + +TEST(TestsTStringArray, NewFor_Full) +{ + TStringArray arrStrings; + arrStrings.Add(TString(L"SomeString1")); + arrStrings.Add(TString(L"SomeString2")); + + int iCount = 0; + for (const TString& strData : arrStrings) + { + if (iCount == 0) + EXPECT_EQ(TString(L"SomeString1"), strData); + else if (iCount == 0) + EXPECT_EQ(TString(L"SomeString2"), strData); + ++iCount; + } + + EXPECT_EQ(2, iCount); +} Index: src/libstring/Tests/TestsTStringSet.cpp =================================================================== diff -u --- src/libstring/Tests/TestsTStringSet.cpp (revision 0) +++ src/libstring/Tests/TestsTStringSet.cpp (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -0,0 +1,181 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TStringSet.h" + +using namespace string; + +TEST(TestsTStringSet, DefaultConstruction) +{ + TStringSet setStrings; + + EXPECT_EQ(0, setStrings.GetCount()); +} + +TEST(TestsTStringSet, InsertElements) +{ + TStringSet setStrings; + + setStrings.Insert(TString(L"SomeString1")); + setStrings.Insert(TString(L"SomeString2")); + + EXPECT_EQ(2, setStrings.GetCount()); + EXPECT_TRUE(setStrings.HasValue(L"SomeString1")); + EXPECT_TRUE(setStrings.HasValue(L"SomeString2")); + EXPECT_FALSE(setStrings.HasValue(TString())); +} + +TEST(TestsTStringSet, InsertCollection) +{ + TStringSet setStrings; + + setStrings.Insert(TString(L"SomeString1")); + setStrings.Insert(TString(L"SomeString2")); + + TStringSet arrPatterns2; + + arrPatterns2.Insert(TString(L"SomeString3")); + + setStrings.Insert(arrPatterns2); + + EXPECT_EQ(3, setStrings.GetCount()); + EXPECT_TRUE(setStrings.HasValue(L"SomeString1")); + EXPECT_TRUE(setStrings.HasValue(L"SomeString2")); + EXPECT_TRUE(setStrings.HasValue(L"SomeString3")); +} + +TEST(TestsTStringSet, Remove) +{ + TStringSet setStrings; + + setStrings.Insert(TString(L"SomeString1")); + setStrings.Insert(TString(L"SomeString2")); + + setStrings.Remove(L"SomeString1"); + + EXPECT_EQ(1, setStrings.GetCount()); + EXPECT_FALSE(setStrings.HasValue(L"SomeString1")); + EXPECT_TRUE(setStrings.HasValue(L"SomeString2")); + EXPECT_FALSE(setStrings.HasValue(TString())); +} + +TEST(TestsTStringSet, Clear) +{ + TStringSet setStrings; + + setStrings.Insert(TString(L"SomeString1")); + setStrings.Insert(TString(L"SomeString2")); + + setStrings.Clear(); + + EXPECT_EQ(0, setStrings.GetCount()); +} + +TEST(TestsTStringSet, IsEmpty_Empty) +{ + TStringSet setStrings; + + EXPECT_TRUE(setStrings.IsEmpty()); +} + +TEST(TestsTStringSet, IsEmpty_Full) +{ + TStringSet setStrings; + setStrings.Insert(TString(L"SomeString1")); + + EXPECT_FALSE(setStrings.IsEmpty()); + setStrings.Clear(); + EXPECT_TRUE(setStrings.IsEmpty()); +} + +// iterators +TEST(TestsTStringSet, Iterate_Empty) +{ + TStringSet arrStrings; + const TStringSet arrStrings2; + + EXPECT_EQ(arrStrings.begin(), arrStrings.end()); + EXPECT_EQ(arrStrings.cbegin(), arrStrings.cend()); + EXPECT_EQ(arrStrings2.begin(), arrStrings2.end()); + EXPECT_EQ(arrStrings2.cbegin(), arrStrings2.cend()); +} + +TEST(TestsTStringSet, Iterate_BeginEnd) +{ + TStringSet arrStrings; + arrStrings.Insert(TString(L"SomeString1")); + arrStrings.Insert(TString(L"SomeString2")); + + TStringSet::iterator iter = arrStrings.begin(); + + EXPECT_EQ(TString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(TString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, arrStrings.end()); +} + +TEST(TestsTStringSet, Iterate_CBeginCEnd) +{ + TStringSet arrStrings; + arrStrings.Insert(TString(L"SomeString1")); + arrStrings.Insert(TString(L"SomeString2")); + + TStringSet::const_iterator iter = arrStrings.cbegin(); + + EXPECT_EQ(TString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(TString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, arrStrings.cend()); +} + +TEST(TestsTStringSet, Iterate_ConstBeginEnd) +{ + TStringSet arrStrings; + arrStrings.Insert(TString(L"SomeString1")); + arrStrings.Insert(TString(L"SomeString2")); + + const TStringSet& rArray = arrStrings; + + TStringSet::const_iterator iter = rArray.begin(); + + EXPECT_EQ(TString(L"SomeString1"), *iter); + ++iter; + EXPECT_EQ(TString(L"SomeString2"), *iter); + ++iter; + EXPECT_EQ(iter, rArray.end()); +} + +TEST(TestsTStringSet, NewFor_Empty) +{ + TStringSet arrStrings; + + int iCount = 0; + for (const TString& strData : arrStrings) + { + strData; + ++iCount; + } + + EXPECT_EQ(0, iCount); +} + +TEST(TestsTStringSet, NewFor_Full) +{ + TStringSet arrStrings; + arrStrings.Insert(TString(L"SomeString1")); + arrStrings.Insert(TString(L"SomeString2")); + + int iCount = 0; + for (const TString& strData : arrStrings) + { + if (iCount == 0) + EXPECT_EQ(TString(L"SomeString1"), strData); + else if (iCount == 0) + EXPECT_EQ(TString(L"SomeString2"), strData); + ++iCount; + } + + EXPECT_EQ(2, iCount); +} Index: src/libstring/libstring.vcxproj =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/libstring.vcxproj (.../libstring.vcxproj) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/libstring.vcxproj (.../libstring.vcxproj) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -502,6 +502,12 @@ true true + + true + true + true + true + true true @@ -514,6 +520,12 @@ true true + + true + true + true + true + Index: src/libstring/libstring.vcxproj.filters =================================================================== diff -u -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -rfadd6c9c628de875716d96c3a497b5bc6c8dca8a --- src/libstring/libstring.vcxproj.filters (.../libstring.vcxproj.filters) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libstring/libstring.vcxproj.filters (.../libstring.vcxproj.filters) (revision fadd6c9c628de875716d96c3a497b5bc6c8dca8a) @@ -83,6 +83,12 @@ Tests + + Tests + + + Tests +