Index: src/libchcore/TFakeFileDescription.cpp =================================================================== diff -u -N --- src/libchcore/TFakeFileDescription.cpp (revision 0) +++ src/libchcore/TFakeFileDescription.cpp (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,26 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 "TFakeFileDescription.h" + +BEGIN_CHCORE_NAMESPACE + + + +END_CHCORE_NAMESPACE Index: src/libchcore/TFakeFileDescription.h =================================================================== diff -u -N --- src/libchcore/TFakeFileDescription.h (revision 0) +++ src/libchcore/TFakeFileDescription.h (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,39 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 __TFAKEFILEDESCRIPTION_H__ +#define __TFAKEFILEDESCRIPTION_H__ + +#include "libchcore.h" +#include "TFileInfo.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TFakeFileDescription +{ +public: + TFakeFileDescription(); + ~TFakeFileDescription(); + +private: + TFileInfo m_fiData; +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TFakeFilesystem.cpp =================================================================== diff -u -N --- src/libchcore/TFakeFilesystem.cpp (revision 0) +++ src/libchcore/TFakeFilesystem.cpp (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,32 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 "TFakeFilesystem.h" + +BEGIN_CHCORE_NAMESPACE + +TFakeFilesystem::TFakeFilesystem() +{ +} + +TFakeFilesystem::~TFakeFilesystem() +{ +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TFakeFilesystem.h =================================================================== diff -u -N --- src/libchcore/TFakeFilesystem.h (revision 0) +++ src/libchcore/TFakeFilesystem.h (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,38 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 __TFAKEFILESYSTEM_H__ +#define __TFAKEFILESYSTEM_H__ + +#include "libchcore.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TFakeFilesystem +{ +public: + TFakeFilesystem(); + ~TFakeFilesystem(); + +private: + +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TFakeFilesystemFile.cpp =================================================================== diff -u -N --- src/libchcore/TFakeFilesystemFile.cpp (revision 0) +++ src/libchcore/TFakeFilesystemFile.cpp (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,32 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 "TFakeFilesystemFile.h" + +BEGIN_CHCORE_NAMESPACE + +TFakeFilesystemFile::TFakeFilesystemFile() +{ +} + +TFakeFilesystemFile::~TFakeFilesystemFile() +{ +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TFakeFilesystemFile.h =================================================================== diff -u -N --- src/libchcore/TFakeFilesystemFile.h (revision 0) +++ src/libchcore/TFakeFilesystemFile.h (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,38 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 __TFAKEFILESYSTEMFILE_H__ +#define __TFAKEFILESYSTEMFILE_H__ + +#include "libchcore.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TFakeFilesystemFile +{ +public: + TFakeFilesystemFile(); + ~TFakeFilesystemFile(); + +private: + +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TFakeFilesystemFind.cpp =================================================================== diff -u -N --- src/libchcore/TFakeFilesystemFind.cpp (revision 0) +++ src/libchcore/TFakeFilesystemFind.cpp (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,32 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 "TFakeFilesystemFind.h" + +BEGIN_CHCORE_NAMESPACE + +TFakeFilesystemFind::TFakeFilesystemFind() +{ +} + +TFakeFilesystemFind::~TFakeFilesystemFind() +{ +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TFakeFilesystemFind.h =================================================================== diff -u -N --- src/libchcore/TFakeFilesystemFind.h (revision 0) +++ src/libchcore/TFakeFilesystemFind.h (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,38 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 __TFAKEFILESYSTEMFIND_H__ +#define __TFAKEFILESYSTEMFIND_H__ + +#include "libchcore.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TFakeFilesystemFind +{ +public: + TFakeFilesystemFind(); + ~TFakeFilesystemFind(); + +private: + +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TSparseRangeMap.cpp =================================================================== diff -u -N --- src/libchcore/TSparseRangeMap.cpp (revision 0) +++ src/libchcore/TSparseRangeMap.cpp (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,114 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 "TSparseRangeMap.h" +#include "TCoreException.h" +#include "ErrorCodes.h" + +BEGIN_CHCORE_NAMESPACE + +TSparseRangeMap::TSparseRangeMap() +{ +} + +TSparseRangeMap::~TSparseRangeMap() +{ +} + +void TSparseRangeMap::Insert(file_size_t fsRangeStart, file_size_t fsRangeEnd) +{ + if (fsRangeEnd < fsRangeStart) + std::swap(fsRangeStart, fsRangeEnd); + + std::pair pairInsert = m_mapRanges.emplace(std::make_pair(fsRangeStart, fsRangeEnd)); + RangeMap::iterator iterInsertedRange = pairInsert.first; + if (!pairInsert.second) + { + // range with fsRangeStart already exists; update it with the increased range (if bigger than the existing one) + if (fsRangeEnd > iterInsertedRange->second) + iterInsertedRange->second = fsRangeEnd; + else + return; // new range overlaps with old one and is smaller; does not change the state of internal map and no reorganization is needed + } + else + { + // element inserted successfully; since it can overlap the previous range in the map, we need to start merging ranges from this previous element + if (iterInsertedRange != m_mapRanges.begin()) + iterInsertedRange = std::prev(iterInsertedRange); + else if(m_mapRanges.size() == 1) + return; // this is the only element currently in the map; no need to process further. + } + + // merge subsequent ranges + file_size_t fsCurrentRangeEnd = iterInsertedRange->second; + + RangeMap::iterator iterRange = std::next(iterInsertedRange); + + while(iterRange != m_mapRanges.end()) + { + if (iterRange->first <= fsCurrentRangeEnd + 1) + { + // next range overlaps with the inserted one - merge them + if(iterRange->second > iterInsertedRange->second) + iterInsertedRange->second = iterRange->second; + iterRange = m_mapRanges.erase(iterRange); + } + else + break; + } +} + +size_t TSparseRangeMap::GetRangeCount() const +{ + return m_mapRanges.size(); +} + +void TSparseRangeMap::GetRangeAt(size_t stIndex, file_size_t& rfsRangeStart, file_size_t& rfsRangeEnd) const +{ + if (stIndex >= m_mapRanges.size()) + THROW_CORE_EXCEPTION(eErr_BoundsExceeded); + + RangeMap::const_iterator iterMap = m_mapRanges.begin(); + std::advance(iterMap, stIndex); + + rfsRangeStart = iterMap->first; + rfsRangeEnd = iterMap->second; +} + +bool TSparseRangeMap::OverlapsRange(file_size_t fsRangeStart, file_size_t fsRangeEnd) const +{ + if (fsRangeEnd < fsRangeStart) + std::swap(fsRangeStart, fsRangeEnd); + + RangeMap::const_iterator iterStart = m_mapRanges.lower_bound(fsRangeStart); + if (iterStart != m_mapRanges.begin()) + iterStart = std::prev(iterStart); + + RangeMap::const_iterator iterEnd = m_mapRanges.upper_bound(fsRangeEnd); + while (iterStart != iterEnd) + { + if (fsRangeStart <= iterStart->second && iterStart->first <= fsRangeEnd) + return true; + ++iterStart; + } + + return false; +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TSparseRangeMap.h =================================================================== diff -u -N --- src/libchcore/TSparseRangeMap.h (revision 0) +++ src/libchcore/TSparseRangeMap.h (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,52 @@ +// ============================================================================ +// Copyright (C) 2001-2015 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 __TSparseRangeMap_H__ +#define __TSparseRangeMap_H__ + +#include "libchcore.h" +#include "CommonDataTypes.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TSparseRangeMap +{ +public: + TSparseRangeMap(); + ~TSparseRangeMap(); + + void Insert(file_size_t fsRangeStart, file_size_t fsRangeEnd); + + size_t GetRangeCount() const; + void GetRangeAt(size_t stIndex, file_size_t& rfsRangeStart, file_size_t& rfsRangeEnd) const; + + bool OverlapsRange(file_size_t fsRangeStart, file_size_t fsRangeEnd) const; + +private: + using RangePair = std::pair; + using RangeMap = std::map; + +#pragma warning(push) +#pragma warning(disable: 4251) + RangeMap m_mapRanges; +#pragma warning(pop) +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/Tests/TestsTSparseRangeMap.cpp =================================================================== diff -u -N --- src/libchcore/Tests/TestsTSparseRangeMap.cpp (revision 0) +++ src/libchcore/Tests/TestsTSparseRangeMap.cpp (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -0,0 +1,89 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "../TSparseRangeMap.h" + +using namespace chcore; + +TEST(TestsTSparseRangeMap, DefaultConstructor) +{ + TSparseRangeMap map; + EXPECT_EQ(0, map.GetRangeCount()); + EXPECT_EQ(false, map.OverlapsRange(0, 0)); +} + +TEST(TestsTSparseRangeMap, SingleRange) +{ + TSparseRangeMap map; + map.Insert(45, 59); + + file_size_t fsStart = 0; + file_size_t fsEnd = 0; + + EXPECT_EQ(1, map.GetRangeCount()); + map.GetRangeAt(0, fsStart, fsEnd); + EXPECT_EQ(45, fsStart); + EXPECT_EQ(59, fsEnd); + + EXPECT_EQ(false, map.OverlapsRange(44, 44)); + EXPECT_EQ(false, map.OverlapsRange(60, 60)); + EXPECT_EQ(true, map.OverlapsRange(45, 45)); + EXPECT_EQ(true, map.OverlapsRange(59, 59)); +} + +TEST(TestsTSparseRangeMap, MultipleUnrelatedRanges) +{ + TSparseRangeMap map; + map.Insert(45, 59); + map.Insert(63, 85); + map.Insert(92, 87); + + file_size_t fsStart = 0; + file_size_t fsEnd = 0; + + EXPECT_EQ(3, map.GetRangeCount()); + map.GetRangeAt(0, fsStart, fsEnd); + EXPECT_EQ(45, fsStart); + EXPECT_EQ(59, fsEnd); + map.GetRangeAt(1, fsStart, fsEnd); + EXPECT_EQ(63, fsStart); + EXPECT_EQ(85, fsEnd); + map.GetRangeAt(2, fsStart, fsEnd); + EXPECT_EQ(87, fsStart); + EXPECT_EQ(92, fsEnd); + + EXPECT_EQ(false, map.OverlapsRange(44, 44)); + EXPECT_EQ(false, map.OverlapsRange(60, 60)); + EXPECT_EQ(true, map.OverlapsRange(45, 45)); + EXPECT_EQ(true, map.OverlapsRange(59, 59)); + + EXPECT_EQ(false, map.OverlapsRange(62, 62)); + EXPECT_EQ(false, map.OverlapsRange(86, 86)); + EXPECT_EQ(true, map.OverlapsRange(63, 63)); + EXPECT_EQ(true, map.OverlapsRange(85, 85)); + + EXPECT_EQ(false, map.OverlapsRange(86, 86)); + EXPECT_EQ(false, map.OverlapsRange(93, 93)); + EXPECT_EQ(true, map.OverlapsRange(87, 87)); + EXPECT_EQ(true, map.OverlapsRange(92, 92)); +} + +TEST(TestsTSparseRangeMap, MultipleRelatedRanges) +{ + TSparseRangeMap map; + map.Insert(45, 59); + map.Insert(60, 85); + map.Insert(36, 50); + + file_size_t fsStart = 0; + file_size_t fsEnd = 0; + + EXPECT_EQ(1, map.GetRangeCount()); + map.GetRangeAt(0, fsStart, fsEnd); + EXPECT_EQ(36, fsStart); + EXPECT_EQ(85, fsEnd); + + EXPECT_EQ(false, map.OverlapsRange(35, 35)); + EXPECT_EQ(false, map.OverlapsRange(86, 86)); + EXPECT_EQ(true, map.OverlapsRange(36, 36)); + EXPECT_EQ(true, map.OverlapsRange(85, 85)); +} Index: src/libchcore/libchcore.vc140.vcxproj =================================================================== diff -u -N -r9ebcc7abf1e0e70f0db2d08b2691351a26ef259b -r5efb534fc5440a7ab779d2514a00486ecb58e845 --- src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision 9ebcc7abf1e0e70f0db2d08b2691351a26ef259b) +++ src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -518,7 +518,11 @@ + + + + @@ -541,6 +545,7 @@ + @@ -682,6 +687,12 @@ true true + + true + true + true + true + true true @@ -737,7 +748,11 @@ true + + + + @@ -757,6 +772,7 @@ + Index: src/libchcore/libchcore.vc140.vcxproj.filters =================================================================== diff -u -N -r9ebcc7abf1e0e70f0db2d08b2691351a26ef259b -r5efb534fc5440a7ab779d2514a00486ecb58e845 --- src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision 9ebcc7abf1e0e70f0db2d08b2691351a26ef259b) +++ src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision 5efb534fc5440a7ab779d2514a00486ecb58e845) @@ -72,6 +72,9 @@ {3de9b5f5-44fa-4e4b-9a63-f93d940d537a} + + {bb686013-810c-4180-9b23-c5fe52df7c93} + @@ -419,6 +422,21 @@ Source Files\Filesystems\Local + + Source Files\Filesystems\Fake + + + Source Files\Filesystems\Fake + + + Source Files\Filesystems\Fake + + + Source Files\Filesystems\Fake + + + Source Files\Tools + @@ -775,5 +793,23 @@ Source Files\Filesystems\Local + + Source Files\Filesystems\Fake + + + Source Files\Filesystems\Fake + + + Source Files\Filesystems\Fake + + + Source Files\Filesystems\Fake + + + Source Files\Tools + + + Tests + \ No newline at end of file