diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:18:53 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:18:53 +0200 |
commit | 32cb97237e7691d31977ab503c6ea4511e8eb3a8 (patch) | |
tree | 4e97b53e9f7b74e8cc5d7548507d9e82ae38e36f /zen | |
parent | 4.6 (diff) | |
download | FreeFileSync-32cb97237e7691d31977ab503c6ea4511e8eb3a8.tar.gz FreeFileSync-32cb97237e7691d31977ab503c6ea4511e8eb3a8.tar.bz2 FreeFileSync-32cb97237e7691d31977ab503c6ea4511e8eb3a8.zip |
5.0
Diffstat (limited to 'zen')
59 files changed, 274 insertions, 109 deletions
diff --git a/zen/FindFilePlus/dll_main.cpp b/zen/FindFilePlus/dll_main.cpp index 5d64181b..02755010 100644 --- a/zen/FindFilePlus/dll_main.cpp +++ b/zen/FindFilePlus/dll_main.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** diff --git a/zen/FindFilePlus/find_file_plus.cpp b/zen/FindFilePlus/find_file_plus.cpp index 876d0c0f..70076aa2 100644 --- a/zen/FindFilePlus/find_file_plus.cpp +++ b/zen/FindFilePlus/find_file_plus.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "find_file_plus.h" diff --git a/zen/FindFilePlus/find_file_plus.h b/zen/FindFilePlus/find_file_plus.h index 2ef5affe..cf1174eb 100644 --- a/zen/FindFilePlus/find_file_plus.h +++ b/zen/FindFilePlus/find_file_plus.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FIND_FIRST_FILE_PLUS_HEADER_087483434 diff --git a/zen/FindFilePlus/init_dll_binding.h b/zen/FindFilePlus/init_dll_binding.h index 51b32c99..5f2c9fa9 100644 --- a/zen/FindFilePlus/init_dll_binding.h +++ b/zen/FindFilePlus/init_dll_binding.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef INIT_DLL_BINDING_HEADER_ß018356031467832145 diff --git a/zen/FindFilePlus/load_dll.cpp b/zen/FindFilePlus/load_dll.cpp index 20d9a5fe..9e8dbf17 100644 --- a/zen/FindFilePlus/load_dll.cpp +++ b/zen/FindFilePlus/load_dll.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "load_dll.h" diff --git a/zen/FindFilePlus/load_dll.h b/zen/FindFilePlus/load_dll.h index 24ce7174..2dde5d70 100644 --- a/zen/FindFilePlus/load_dll.h +++ b/zen/FindFilePlus/load_dll.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef LOAD_DLL_HEADER_0312463214872163832174 diff --git a/zen/assert_static.h b/zen/assert_static.h index 5a2dc4a6..b96b5909 100644 --- a/zen/assert_static.h +++ b/zen/assert_static.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef ASSERTSTATIC_H_INCLUDED diff --git a/zen/base64.h b/zen/base64.h index 4a81787c..273f6c00 100644 --- a/zen/base64.h +++ b/zen/base64.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef BASE64_HEADER_08473021856321840873021487213453214 #define BASE64_HEADER_08473021856321840873021487213453214 diff --git a/zen/basic_math.h b/zen/basic_math.h index f4f46ce0..e9ab1a2f 100644 --- a/zen/basic_math.h +++ b/zen/basic_math.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef BASIC_MATH_HEADER_34726398432 @@ -32,7 +32,7 @@ template <class T> const T& max(const T& a, const T& b, const T& c); template <class T> -void confine(T& val, const T& minVal, const T& maxVal); //make sure minVal <= val && val <= maxVal +void restrict(T& val, const T& minVal, const T& maxVal); //make sure minVal <= val && val <= maxVal template <class InputIterator> std::pair<InputIterator, InputIterator> minMaxElement(InputIterator first, InputIterator last); @@ -131,7 +131,7 @@ const T& max(const T& a, const T& b, const T& c) template <class T> inline -void confine(T& val, const T& minVal, const T& maxVal) +void restrict(T& val, const T& minVal, const T& maxVal) { assert(minVal <= maxVal); if (val < minVal) @@ -260,19 +260,6 @@ double median(RandomAccessIterator first, RandomAccessIterator last) //note: inv } -class LessMinusMedAbs : public std::binary_function<double, double, bool> -{ -public: - LessMinusMedAbs(double median) : median_(median) {} - bool operator()(double lhs, double rhs) const - { - return abs(lhs - median_) < abs(rhs - median_); - } -private: - double median_; -}; - - template <class RandomAccessIterator> inline double mad(RandomAccessIterator first, RandomAccessIterator last) //note: invalidates input range! { @@ -285,14 +272,16 @@ double mad(RandomAccessIterator first, RandomAccessIterator last) //note: invali //the second median needs to operate on absolute residuals => avoid transforming input range as it may decrease precision! - std::nth_element(first, first + n / 2, last, LessMinusMedAbs(m)); //complexity: O(n) + auto lessMedAbs = [m](double lhs, double rhs) { return abs(lhs - m) < abs(rhs - m); }; + + std::nth_element(first, first + n / 2, last, lessMedAbs); //complexity: O(n) const double midVal = abs(*(first + n / 2) - m); if (n % 2 != 0) return midVal; else //n is even and >= 2 in this context: return mean of two middle values { - const double midVal2 = abs(*std::max_element(first, first + n / 2, LessMinusMedAbs(m)) - m); + const double midVal2 = abs(*std::max_element(first, first + n / 2, lessMedAbs) - m); return 0.5 * (midVal2 + midVal); } } diff --git a/zen/build_info.h b/zen/build_info.h index e57d0c77..6857a855 100644 --- a/zen/build_info.h +++ b/zen/build_info.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef BUILDINFO_H_INCLUDED diff --git a/zen/com_error.h b/zen/com_error.h index 4546bd8a..7f967f7c 100644 --- a/zen/com_error.h +++ b/zen/com_error.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef COM_ERROR_HEADER diff --git a/zen/com_ptr.h b/zen/com_ptr.h index de8dbe64..b55d873e 100644 --- a/zen/com_ptr.h +++ b/zen/com_ptr.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef SMART_COM_PTR_H @@ -117,5 +117,4 @@ ComPtr<S> com_dynamic_cast(const ComPtr<T>& other) //throw() } } - #endif //SMART_COM_PTR_H
\ No newline at end of file diff --git a/zen/com_util.h b/zen/com_util.h index db51404b..2845e352 100644 --- a/zen/com_util.h +++ b/zen/com_util.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef COM_UTILITY_HEADER diff --git a/zen/debug_log.h b/zen/debug_log.h index e7116156c..43b2fea3 100644 --- a/zen/debug_log.h +++ b/zen/debug_log.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef DEBUG_LOG_HEADER_017324601673246392184621895740256342 diff --git a/zen/debug_new.cpp b/zen/debug_new.cpp index 2017dcd2..9992f0b3 100644 --- a/zen/debug_new.cpp +++ b/zen/debug_new.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "debug_new.h" diff --git a/zen/debug_new.h b/zen/debug_new.h index 2976d3d7..ca46cc8e 100644 --- a/zen/debug_new.h +++ b/zen/debug_new.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef DEBUGNEW_H_INCLUDED diff --git a/zen/deprecate.h b/zen/deprecate.h index b045d3c0..33130710 100644 --- a/zen/deprecate.h +++ b/zen/deprecate.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef DEPRECATE_HEADER_2348970348 diff --git a/zen/dir_watcher.cpp b/zen/dir_watcher.cpp index c980c715..6ab56100 100644 --- a/zen/dir_watcher.cpp +++ b/zen/dir_watcher.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "dir_watcher.h" diff --git a/zen/dir_watcher.h b/zen/dir_watcher.h index a9898abb..67f2bce0 100644 --- a/zen/dir_watcher.h +++ b/zen/dir_watcher.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef DIR_WATCHER_348577025748023458 @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef DLLLOADER_H_INCLUDED @@ -20,7 +20,7 @@ Manage DLL function and library ownership - full value semantics Usage: - typedef BOOL (WINAPI *IsWow64ProcessFun)(HANDLE hProcess, PBOOL Wow64Process); + typedef BOOL (WINAPI* IsWow64ProcessFun)(HANDLE hProcess, PBOOL Wow64Process); const zen::DllFun<IsWow64ProcessFun> isWow64Process(L"kernel32.dll", "IsWow64Process"); if (isWow64Process) ... use function ptr ... */ diff --git a/zen/dst_hack.cpp b/zen/dst_hack.cpp index ac5774d0..9fe3a550 100644 --- a/zen/dst_hack.cpp +++ b/zen/dst_hack.cpp @@ -85,7 +85,7 @@ bool dst::isFatDrive(const Zstring& fileName) //throw() bool dst::isFatDrive(HANDLE hFile) //throw() { //dynamically load windows API function - typedef BOOL (WINAPI *GetVolumeInformationByHandleWFunc)(HANDLE hFile, + typedef BOOL (WINAPI* GetVolumeInformationByHandleWFunc)(HANDLE hFile, LPWSTR lpVolumeNameBuffer, DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber, diff --git a/zen/file_error.h b/zen/file_error.h index 2992fbbe..853267d4 100644 --- a/zen/file_error.h +++ b/zen/file_error.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FILEERROR_H_INCLUDED diff --git a/zen/file_handling.cpp b/zen/file_handling.cpp index 334128d9..dd5276a4 100644 --- a/zen/file_handling.cpp +++ b/zen/file_handling.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "file_handling.h" @@ -910,6 +910,53 @@ void zen::setFileTime(const Zstring& filename, const Int64& modificationTime, Pr } +bool zen::supportsPermissions(const Zstring& dirname) //throw FileError +{ +#ifdef FFS_WIN + const HANDLE hDir = ::CreateFile(zen::applyLongPathPrefix(dirname).c_str(), + 0, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, // | FILE_FLAG_OPEN_REPARSE_POINT -> follow symlinks + NULL); + if (hDir == INVALID_HANDLE_VALUE) + throw FileError(_("Error reading file attributes:") + L"\n\"" + dirname + L"\"" + L"\n\n" + getLastErrorFormatted()); + ZEN_ON_BLOCK_EXIT(::CloseHandle(hDir)); + + //dynamically load windows API function (existing since Windows XP) + typedef BOOL (WINAPI* GetVolumeInformationByHandleWFun)(HANDLE hFile, + LPWSTR lpVolumeNameBuffer, + DWORD nVolumeNameSize, + LPDWORD lpVolumeSerialNumber, + LPDWORD lpMaximumComponentLength, + LPDWORD lpFileSystemFlags, + LPWSTR lpFileSystemNameBuffer, + DWORD nFileSystemNameSize); + + const SysDllFun<GetVolumeInformationByHandleWFun> getVolumeInformationByHandleW(L"kernel32.dll", "GetVolumeInformationByHandleW"); + if (!getVolumeInformationByHandleW) + throw FileError(_("Error loading library function:") + L"\n\"" + L"GetVolumeInformationByHandleW" + L"\""); + + DWORD fileSystemFlags = 0; + if (!getVolumeInformationByHandleW(hDir, //__in HANDLE hFile, + NULL, //__out_opt LPTSTR lpVolumeNameBuffer, + 0, //__in DWORD nVolumeNameSize, + NULL, //__out_opt LPDWORD lpVolumeSerialNumber, + NULL, //__out_opt LPDWORD lpMaximumComponentLength, + &fileSystemFlags, //__out_opt LPDWORD lpFileSystemFlags, + NULL, //__out LPTSTR lpFileSystemNameBuffer, + 0)) //__in DWORD nFileSystemNameSize + throw FileError(_("Error reading file attributes:") + L"\n\"" + dirname + L"\"" + L"\n\n" + getLastErrorFormatted()); + + return (fileSystemFlags & FILE_PERSISTENT_ACLS) != 0; + +#elif defined FFS_LINUX + return true; +#endif +} + + namespace { #ifdef FFS_WIN @@ -928,7 +975,7 @@ Zstring getSymlinkTargetPath(const Zstring& symlink) //throw FileError ZEN_ON_BLOCK_EXIT(::CloseHandle(hDir)); //dynamically load windows API function - typedef DWORD (WINAPI *GetFinalPathNameByHandleWFunc)(HANDLE hFile, + typedef DWORD (WINAPI* GetFinalPathNameByHandleWFunc)(HANDLE hFile, LPTSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); @@ -1026,6 +1073,7 @@ void copyObjectPermissions(const Zstring& source, const Zstring& target, ProcSym } //in contrast to ::SetSecurityInfo(), ::SetFileSecurity() seems to honor the "inherit DACL/SACL" flags + //CAVEAT: if a file system does not support ACLs, GetFileSecurity() will return successfully with a *valid* security descriptor containing *no* ACL entries! //NOTE: ::GetFileSecurity()/::SetFileSecurity() do NOT follow Symlinks! const Zstring sourceResolved = procSl == SYMLINK_FOLLOW && symlinkExists(source) ? getSymlinkTargetPath(source) : source; @@ -1336,7 +1384,7 @@ void zen::copySymlink(const Zstring& sourceLink, const Zstring& targetLink, bool }(); //dynamically load windows API function - typedef BOOLEAN (WINAPI *CreateSymbolicLinkFunc)(LPCTSTR lpSymlinkFileName, LPCTSTR lpTargetFileName, DWORD dwFlags); + typedef BOOLEAN (WINAPI* CreateSymbolicLinkFunc)(LPCTSTR lpSymlinkFileName, LPCTSTR lpTargetFileName, DWORD dwFlags); const SysDllFun<CreateSymbolicLinkFunc> createSymbolicLink(L"kernel32.dll", "CreateSymbolicLinkW"); if (!createSymbolicLink) diff --git a/zen/file_handling.h b/zen/file_handling.h index e6819322..80350731 100644 --- a/zen/file_handling.h +++ b/zen/file_handling.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FILE_HANDLING_H_INCLUDED @@ -62,6 +62,8 @@ void moveFile(const Zstring& sourceFile, const Zstring& targetFile, bool ignoreE //"ignoreExisting": existing directories and files will be enriched void moveDirectory(const Zstring& sourceDir, const Zstring& targetDir, bool ignoreExisting, CallbackMoveFile* callback); //throw FileError; +bool supportsPermissions(const Zstring& dirname); //throw FileError, derefernces symlinks + //creates superdirectories automatically: void createDirectory(const Zstring& directory, const Zstring& templateDir, bool copyFilePermissions); //throw FileError; void createDirectory(const Zstring& directory); //throw FileError; -> function overload avoids default parameter ambiguity issues! @@ -88,7 +90,6 @@ void copySymlink(const Zstring& sourceLink, const Zstring& targetLink, bool copy - //----------- callbacks --------------- struct CallbackRemoveDir { diff --git a/zen/file_id.cpp b/zen/file_id.cpp index fa05a142..4f9e3600 100644 --- a/zen/file_id.cpp +++ b/zen/file_id.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "file_id.h" diff --git a/zen/file_id.h b/zen/file_id.h index 3fd4c6bb..1170c2a2 100644 --- a/zen/file_id.h +++ b/zen/file_id.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FILEID_H_INCLUDED diff --git a/zen/file_id_def.h b/zen/file_id_def.h index 7e729eb1..b65496be 100644 --- a/zen/file_id_def.h +++ b/zen/file_id_def.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FILE_ID_INTERNAL_HEADER_013287632486321493 diff --git a/zen/file_io.cpp b/zen/file_io.cpp index ba8ab955..ad1ecd6b 100644 --- a/zen/file_io.cpp +++ b/zen/file_io.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "file_io.h" diff --git a/zen/file_io.h b/zen/file_io.h index 7ce6d901..eb797b7b 100644 --- a/zen/file_io.h +++ b/zen/file_io.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FILEIO_H_INCLUDED diff --git a/zen/file_traverser.cpp b/zen/file_traverser.cpp index 0fb8a332..a0979c49 100644 --- a/zen/file_traverser.cpp +++ b/zen/file_traverser.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "file_traverser.h" @@ -93,7 +93,7 @@ DWORD retrieveVolumeSerial(const Zstring& pathName) //returns 0 on error or if s // -> GetVolumePathName() on the other hand resolves "S:\Desktop\somedir" to "S:\Desktop\" - nice try... //dynamically load windows API function (existing since Windows XP) - typedef BOOL (WINAPI *GetFileInformationByHandleFunc)(HANDLE hFile, + typedef BOOL (WINAPI* GetFileInformationByHandleFunc)(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation); const SysDllFun<GetFileInformationByHandleFunc> getFileInformationByHandle(L"kernel32.dll", "GetFileInformationByHandle"); @@ -335,7 +335,7 @@ struct FilePlusTraverser template <class FindData> static void extractFileInfo(const FindData& fileInfo, DWORD volumeSerial, TraverseCallback::FileInfo& output) { - output.fileSize = UInt64(fileInfo.fileSize.QuadPart); + output.fileSize = fileInfo.fileSize.QuadPart; output.lastWriteTimeRaw = getModTime(fileInfo); output.id = extractFileID(volumeSerial, fileInfo.fileId); } diff --git a/zen/file_traverser.h b/zen/file_traverser.h index b277b6ab..d6b69f86 100644 --- a/zen/file_traverser.h +++ b/zen/file_traverser.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FILETRAVERSER_H_INCLUDED diff --git a/zen/fixed_list.h b/zen/fixed_list.h index f08a4815..1b2af5bf 100644 --- a/zen/fixed_list.h +++ b/zen/fixed_list.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef PTR_WRAP_012384670856841394535 @@ -36,7 +36,16 @@ public: lastInsert(NULL), sz(0) {} - ~FixedList() { clear(); } + ~FixedList() + { + Node* ptr = first; + while (ptr) + { + Node* tmp = ptr; + ptr = ptr->next; + delete tmp; + } + } template <class NodeT, class U> class ListIterator : public std::iterator<std::forward_iterator_tag, U> @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef GUID_H_INCLUDED @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef I18_N_HEADER_3843489325045 diff --git a/zen/int64.h b/zen/int64.h index 31c278ca..a5140ffd 100644 --- a/zen/int64.h +++ b/zen/int64.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef FFS_LARGE_64_BIT_INTEGER_H_INCLUDED @@ -14,6 +14,7 @@ #include <ostream> #include "assert_static.h" #include "type_tools.h" +#include "type_traits.h" #ifdef FFS_WIN #include "win.h" @@ -46,18 +47,15 @@ void checkRange(U value) class Int64 { - struct DummyClass { operator int() { return 0; } }; public: //safe implicit conversions Int64() : value(0) {} Int64(const Int64& rhs) : value(rhs.value) {} - Int64(int rhs) : value(rhs) {} //ambiguity intentional for types other than these - Int64(long rhs) : value(rhs) {} - Int64(SelectIf<IsSameType<std::int64_t, long>::result, DummyClass, std::int64_t>::Result rhs) : - value(rhs) {} //-> std::int64_t equals long int on x64 Linux! Still we want implicit behavior for all other systems! + template <class T> + Int64(T rhs, typename EnableIf<IsSignedInt<T>::result && sizeof(T) <= sizeof(std::int64_t)>::Result* = NULL) : value(static_cast<std::int64_t>(rhs)) {} - //unsafe explicit but checked conversion from arbitrary integer type - template <class T> explicit Int64(T rhs) : value(static_cast<std::int64_t>(rhs)) { checkRange<std::int64_t>(rhs); } + //unsafe explicit but checked conversion for all other integer types + template <class T> explicit Int64(T rhs, typename EnableIf<!(IsSignedInt<T>::result && sizeof(T) <= sizeof(std::int64_t))>::Result* = NULL) : value(static_cast<std::int64_t>(rhs)) { checkRange<std::int64_t>(rhs); } Int64& operator=(const Int64& rhs) { value = rhs.value; return *this; } @@ -126,18 +124,15 @@ inline Int64 operator>>(const Int64& lhs, int rhs) { return Int64(lhs) >>= rhs; class UInt64 { - struct DummyClass { operator size_t() { return 0U; } }; public: //safe implicit conversions UInt64() : value(0) {} UInt64(const UInt64& rhs) : value(rhs.value) {} - UInt64(unsigned int rhs) : value(rhs) {} //ambiguity intentional for types other than these - UInt64(unsigned long rhs) : value(rhs) {} - UInt64(SelectIf<IsSameType<std::uint64_t, unsigned long>::result, DummyClass, std::uint64_t>::Result rhs) : - value(rhs) {} //-> std::uint64_t equals unsigned long int on x64 Linux! Still we want implicit behavior for all other systems! + template <class T> + UInt64(T rhs, typename EnableIf<IsUnsignedInt<T>::result && sizeof(T) <= sizeof(std::uint64_t)>::Result* = NULL) : value(static_cast<std::uint64_t>(rhs)) {} - //unsafe explicit but checked conversion from arbitrary integer type - template <class T> explicit UInt64(T rhs) : value(static_cast<std::uint64_t>(rhs)) { checkRange<std::uint64_t>(rhs); } + //unsafe explicit but checked conversion for all other integer types + template <class T> explicit UInt64(T rhs, typename EnableIf<!(IsUnsignedInt<T>::result && sizeof(T) <= sizeof(std::uint64_t))>::Result* = NULL) : value(static_cast<std::uint64_t>(rhs)) { checkRange<std::uint64_t>(rhs); } UInt64& operator=(const UInt64& rhs) { value = rhs.value; return *this; } diff --git a/zen/last_error.h b/zen/last_error.h index d2eaebfc..6f701992 100644 --- a/zen/last_error.h +++ b/zen/last_error.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef SYSTEMFUNCTIONS_H_INCLUDED diff --git a/zen/long_path_prefix.h b/zen/long_path_prefix.h index d03409e1..d6255b85 100644 --- a/zen/long_path_prefix.h +++ b/zen/long_path_prefix.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef LONGPATHPREFIX_H_INCLUDED @@ -55,6 +55,7 @@ template <size_t max_path> inline Zstring applyLongPathPrefixImpl(const Zstring& path) { assert(!path.empty()); //nicely check almost all WinAPI accesses! + assert(!zen::cStringIsWhiteSpace(path[0])); if (path.length() >= max_path && //maximum allowed path length without prefix is (MAX_PATH - 1) !zen::startsWith(path, LONG_PATH_PREFIX)) diff --git a/zen/notify_removal.cpp b/zen/notify_removal.cpp index 2b6b9003..661822cb 100644 --- a/zen/notify_removal.cpp +++ b/zen/notify_removal.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "notify_removal.h" diff --git a/zen/notify_removal.h b/zen/notify_removal.h index bd47684e..613d5357 100644 --- a/zen/notify_removal.h +++ b/zen/notify_removal.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef NOTIFY_H_INCLUDED diff --git a/zen/optional.h b/zen/optional.h new file mode 100644 index 00000000..1e04f52c --- /dev/null +++ b/zen/optional.h @@ -0,0 +1,62 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * +// ************************************************************************** + +#ifndef OPTIONAL_H_2857428578342203589 +#define OPTIONAL_H_2857428578342203589 + +namespace zen +{ +/* +Optional return value with static memory allocation! + -> interface like a pointer, performance like a value + + Usage: + ------ + Opt<MyEnum> someFunction(); +{ + if (allIsWell) + return enumVal; + else + return NoValue(); +} + + Opt<MyEnum> optValue = someFunction(); + if (optValue) + ... use *optValue ... +*/ + +struct NoValue {}; + +template <class T> +class Opt +{ +public: + Opt() : valid(false), value() {} + Opt(NoValue) : valid(false), value() {} + Opt(const T& val) : valid(true ), value(val) {} + +#ifdef _MSC_VER +private: + struct ConversionToBool { int dummy; }; +public: + operator int ConversionToBool::* () const { return valid ? &ConversionToBool::dummy : nullptr; } +#else + explicit operator bool() const { return valid; } //thank you C++11!!! +#endif + + const T& operator*() const { return value; } + /**/ T& operator*() { return value; } + + const T* operator->() const { return &value; } + /**/ T* operator->() { return &value; } +private: + const bool valid; + T value; +}; + +} + +#endif //OPTIONAL_H_2857428578342203589 @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef DEBUG_PERF_HEADER diff --git a/zen/privilege.h b/zen/privilege.h index 88fc8992..97d0d201 100644 --- a/zen/privilege.h +++ b/zen/privilege.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef PRIVILEGE_H_INCLUDED diff --git a/zen/read_txt.h b/zen/read_txt.h index 479f950e..d0e3f4dc 100644 --- a/zen/read_txt.h +++ b/zen/read_txt.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef PARSE_TXT_H_INCLUDED diff --git a/zen/scope_guard.h b/zen/scope_guard.h index d3633284..cc2f31e6 100644 --- a/zen/scope_guard.h +++ b/zen/scope_guard.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef ZEN_SCOPEGUARD_8971632487321434 diff --git a/zen/stl_tools.h b/zen/stl_tools.h index 96101821..03a10f96 100644 --- a/zen/stl_tools.h +++ b/zen/stl_tools.h @@ -2,13 +2,21 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef STL_TOOLS_HEADER_84567184321434 #define STL_TOOLS_HEADER_84567184321434 -//no need to drag in any STL includes +#include <memory> +#if defined _MSC_VER && _MSC_VER <= 1600 +#include <set> +#include <map> +#else +#include <unordered_set> +#include <unordered_map> +#endif + //enhancements for <algorithm> @@ -36,8 +44,12 @@ template <class BidirectionalIterator1, class BidirectionalIterator2> BidirectionalIterator1 search_last(BidirectionalIterator1 first1, BidirectionalIterator1 last1, BidirectionalIterator2 first2, BidirectionalIterator2 last2); +//hash container: proper name + mitigate MSVC performance bug +template <class T> class hash_set; +template <class K, class V> class hash_map; - +template<typename T, typename Arg1> +std::unique_ptr<T> make_unique(Arg1&& arg1); //should eventually make it into the std at some time @@ -138,6 +150,28 @@ BidirectionalIterator1 search_last(const BidirectionalIterator1 first1, Bidirect --last1; } } + + +#if defined _MSC_VER && _MSC_VER <= 1600 //VS2010 performance bug in std::unordered_set<>: http://drdobbs.com/blogs/cpp/232200410 -> should be fixed in VS11 +template <class T> class hash_set : public std::set<T> {}; +template <class K, class V> class hash_map : public std::map<K, V> {}; +#else +template <class T> class hash_set : public std::unordered_set<T> {}; +template <class K, class V> class hash_map : public std::unordered_map<K, V> {}; +#endif + +//as long as variadic templates are not available in MSVC +template<class T, class Arg1> inline std::unique_ptr<T> make_unique(Arg1&& arg1) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1))); } +template<class T, class Arg1, class Arg2> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2))); } +template<class T, class Arg1, class Arg2, class Arg3> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3))); } +template<class T, class Arg1, class Arg2, class Arg3, class Arg4> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3), std::forward<Arg4>(arg4))); } +template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5> inline std::unique_ptr<T> make_unique(Arg1&& arg1, Arg2&& arg2, Arg3&& arg3, Arg4&& arg4, Arg5&& arg5) { return std::unique_ptr<T>(new T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2), std::forward<Arg3>(arg3), std::forward<Arg4>(arg4), std::forward<Arg5>(arg5))); } + +//template<typename T, typename ...Args> inline +//std::unique_ptr<T> make_unique(Args&& ...args) +//{ +// return std::unique_ptr<T>(new T( std::forward<Args>(args)... )); +//} } #endif //STL_TOOLS_HEADER_84567184321434 diff --git a/zen/string_base.h b/zen/string_base.h index 88da13bf..ef0d9059 100644 --- a/zen/string_base.h +++ b/zen/string_base.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef Z_BASE_H_INCLUDED diff --git a/zen/string_tools.h b/zen/string_tools.h index 5f20a2de..602c4258 100644 --- a/zen/string_tools.h +++ b/zen/string_tools.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef STRING_TOOLS_HEADER_213458973046 diff --git a/zen/string_traits.h b/zen/string_traits.h index 6c51f6dd..c06aa6e3 100644 --- a/zen/string_traits.h +++ b/zen/string_traits.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef STRING_TRAITS_HEADER_813274321443234 diff --git a/zen/symlink_target.h b/zen/symlink_target.h index b66d5c0e..20433b43 100644 --- a/zen/symlink_target.h +++ b/zen/symlink_target.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef SYMLINK_WIN_H_INCLUDED diff --git a/zen/thread.h b/zen/thread.h index 4db1e613..4598ea99 100644 --- a/zen/thread.h +++ b/zen/thread.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef BOOST_THREAD_WRAP_H @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef ZEN_TIME_HEADER_845709281432434 diff --git a/zen/type_tools.h b/zen/type_tools.h index 03ccb5f2..03105ac8 100644 --- a/zen/type_tools.h +++ b/zen/type_tools.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef TYPE_TOOLS_HEADER_45237590734254545 @@ -78,6 +78,36 @@ struct RemoveArray { typedef T Result; }; template <class T, int N> struct RemoveArray<T[N]> { typedef T Result; }; + +//########## Sorting ############################## +/* +Generate a descending binary predicate at compile time! + +Usage: + static const bool ascending = ... + makeSortDirection(old binary predicate, Int2Type<ascending>()) -> new binary predicate + +or directly; + makeDescending(old binary predicate) -> new binary predicate +*/ + +template <class Predicate> +struct LessDescending +{ + LessDescending(Predicate lessThan) : lessThan_(lessThan) {} + template <class T> bool operator()(const T& lhs, const T& rhs) const { return lessThan_(rhs, lhs); } +private: + Predicate lessThan_; +}; + +template <class Predicate> inline +/**/ Predicate makeSortDirection(Predicate pred, Int2Type<true>) { return pred; } + +template <class Predicate> inline +LessDescending<Predicate> makeSortDirection(Predicate pred, Int2Type<false>) { return pred; } + +template <class Predicate> inline +LessDescending<Predicate> makeDescending(Predicate pred) { return pred; } } #endif //TYPE_TOOLS_HEADER_45237590734254545 diff --git a/zen/type_traits.h b/zen/type_traits.h index 0dacbb9a..d9b28525 100644 --- a/zen/type_traits.h +++ b/zen/type_traits.h @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef TYPE_TRAITS_HEADER_3425628658765467 @@ -2,7 +2,7 @@ // * This file is part of the zenXML project. It is distributed under the * // * Boost Software License, Version 1.0. See accompanying file * // * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef STRING_UTF8_HEADER_01832479146991573473545 diff --git a/zen/warn_static.h b/zen/warn_static.h index db472ccd..a71308bb 100644 --- a/zen/warn_static.h +++ b/zen/warn_static.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef WARN_STATIC_HEADER_08724567834560832745 @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef YAWFWH_YET_ANOTHER_WRAPPER_FOR_WINDOWS_H diff --git a/zen/win_ver.h b/zen/win_ver.h index 6f2639c6..464b7264 100644 --- a/zen/win_ver.h +++ b/zen/win_ver.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef WINDOWS_VERSION_HEADER_238470348254325 diff --git a/zen/zstring.cpp b/zen/zstring.cpp index 38d9b4c4..d17e860c 100644 --- a/zen/zstring.cpp +++ b/zen/zstring.cpp @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "zstring.h" @@ -24,15 +24,13 @@ using namespace zen; #ifndef NDEBUG LeakChecker::~LeakChecker() { - if (activeStrings.size() > 0) + if (!activeStrings.empty()) { - int rowCount = 0; std::string leakingStrings; - for (VoidPtrSizeMap::const_iterator i = activeStrings.begin(); - i != activeStrings.end() && ++rowCount <= 20; - ++i) - leakingStrings += "\"" + rawMemToString(i->first, i->second) + "\"\n"; + int items = 0; + for (auto iter = activeStrings.begin(); iter != activeStrings.end() && items < 20; ++iter, ++items) + leakingStrings += "\"" + rawMemToString(iter->first, iter->second) + "\"\n"; const std::string message = std::string("Memory leak detected!") + "\n\n" + "Candidates:\n" + leakingStrings; diff --git a/zen/zstring.h b/zen/zstring.h index ca5d99c8..a53c1bb0 100644 --- a/zen/zstring.h +++ b/zen/zstring.h @@ -1,7 +1,7 @@ // ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #ifndef ZSTRING_H_INCLUDED @@ -24,7 +24,7 @@ public: { boost::lock_guard<boost::mutex> dummy(lockActStrings); if (activeStrings.find(ptr) != activeStrings.end()) - reportProblem(std::string("Fatal Error: New memory points into occupied space: ") + rawMemToString(ptr, size)); + reportProblem("Fatal Error: New memory points into occupied space: " + rawMemToString(ptr, size)); activeStrings[ptr] = size; } @@ -33,7 +33,7 @@ public: { boost::lock_guard<boost::mutex> dummy(lockActStrings); if (activeStrings.find(ptr) == activeStrings.end()) - reportProblem(std::string("Fatal Error: No memory available for deallocation at this location!")); + reportProblem("Fatal Error: No memory available for deallocation at this location!"); activeStrings.erase(ptr); } @@ -50,8 +50,7 @@ private: void reportProblem(const std::string& message); //throw (std::logic_error) boost::mutex lockActStrings; - typedef std::map<const void*, size_t> VoidPtrSizeMap; - VoidPtrSizeMap activeStrings; + zen::hash_map<const void*, size_t> activeStrings; }; #endif //NDEBUG |