summaryrefslogtreecommitdiff
path: root/file_hierarchy.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:13:35 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:13:35 +0200
commit801e8b43b13f1cb67d9e9ba4aae5acb274ccdfbc (patch)
tree473f4a9ea5016f146fb2ff6085807bc91a84c84e /file_hierarchy.cpp
parent3.20 (diff)
downloadFreeFileSync-801e8b43b13f1cb67d9e9ba4aae5acb274ccdfbc.tar.gz
FreeFileSync-801e8b43b13f1cb67d9e9ba4aae5acb274ccdfbc.tar.bz2
FreeFileSync-801e8b43b13f1cb67d9e9ba4aae5acb274ccdfbc.zip
3.21
Diffstat (limited to 'file_hierarchy.cpp')
-rw-r--r--file_hierarchy.cpp29
1 files changed, 10 insertions, 19 deletions
diff --git a/file_hierarchy.cpp b/file_hierarchy.cpp
index c1aa97ae..3b0f5a04 100644
--- a/file_hierarchy.cpp
+++ b/file_hierarchy.cpp
@@ -75,36 +75,27 @@ const FileSystemObject* HierarchyObject::retrieveById(ObjectID id) const //retur
}
-struct IsInvalid
+template <class V, class Predicate> inline
+void vector_remove_if(V& vec, Predicate p)
{
- bool operator()(const FileSystemObject& fsObj) const
- {
- return fsObj.isEmpty();
- }
-};
-
-
-void FileSystemObject::removeEmptyNonRec(HierarchyObject& hierObj)
-{
- //remove invalid files:
- hierObj.useSubFiles().erase(std::remove_if(hierObj.useSubFiles().begin(), hierObj.useSubFiles().end(), IsInvalid()), hierObj.useSubFiles().end());
- //remove invalid symlinks:
- hierObj.useSubLinks().erase(std::remove_if(hierObj.useSubLinks().begin(), hierObj.useSubLinks().end(), IsInvalid()), hierObj.useSubLinks().end());
- //remove invalid directories:
- hierObj.useSubDirs(). erase(std::remove_if(hierObj.useSubDirs(). begin(), hierObj.useSubDirs(). end(), IsInvalid()), hierObj.useSubDirs(). end());
+ vec.erase(std::remove_if(vec.begin(), vec.end(), p), vec.end());
}
void removeEmptyRec(HierarchyObject& hierObj)
{
- FileSystemObject::removeEmptyNonRec(hierObj);
+ auto isEmpty = [](const FileSystemObject& fsObj) { return fsObj.isEmpty(); };
+
+ vector_remove_if(hierObj.refSubFiles(), isEmpty);
+ vector_remove_if(hierObj.refSubLinks(), isEmpty);
+ vector_remove_if(hierObj.refSubDirs (), isEmpty);
//recurse
- std::for_each(hierObj.useSubDirs().begin(), hierObj.useSubDirs().end(), removeEmptyRec);
+ std::for_each(hierObj.refSubDirs().begin(), hierObj.refSubDirs().end(), removeEmptyRec);
}
-void FileSystemObject::removeEmpty(BaseDirMapping& baseDir)
+void BaseDirMapping::removeEmpty(BaseDirMapping& baseDir)
{
removeEmptyRec(baseDir);
}
bgstack15