From bd6336c629841c6db3a6ca53a936d629d34db53b Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:15:16 +0200 Subject: 4.1 --- shared/check_exist.h | 88 ---------------------------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 shared/check_exist.h (limited to 'shared/check_exist.h') diff --git a/shared/check_exist.h b/shared/check_exist.h deleted file mode 100644 index 8078d388..00000000 --- a/shared/check_exist.h +++ /dev/null @@ -1,88 +0,0 @@ -// ************************************************************************** -// * 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) * -// ************************************************************************** - -#ifndef CHECKEXIST_H_INCLUDED -#define CHECKEXIST_H_INCLUDED - -#include "zstring.h" -#include "boost_thread_wrap.h" //include -#include "file_handling.h" - - -namespace util -{ -//check for file or folder existence asynchronously -boost::unique_future somethingExistsAsync(const Zstring& somename); -boost::unique_future fileExistsAsync(const Zstring& filename); -boost::unique_future dirExistsAsync(const Zstring& dirname); - -//some syntactic sugar: -enum ResultExist -{ - EXISTING_TRUE, - EXISTING_FALSE, - EXISTING_NOT_READY -}; - -ResultExist somethingExists(const Zstring& somename, size_t timeout); -ResultExist fileExists(const Zstring& filename, size_t timeout); -ResultExist dirExists(const Zstring& dirname, size_t timeout); - - - - - - - - - - - - -//################## implementation ########################## -template -boost::unique_future objExistsAsync(const Zstring& objname) -{ - //thread safety: make it a pure value type for use in the thread! - const Zstring objnameVal = objname; //atomic ref-count => binary value-type semantics! - boost::packaged_task pt([ = ] { return (*fun)(objnameVal); }); - auto fut = pt.get_future(); - boost::thread(std::move(pt)); - return std::move(fut); -} - - -inline -boost::unique_future somethingExistsAsync(const Zstring& somename) { return objExistsAsync<&zen::somethingExists>(somename); } - -inline -boost::unique_future fileExistsAsync(const Zstring& filename) { return objExistsAsync<&zen::fileExists>(filename); } - -inline -boost::unique_future dirExistsAsync(const Zstring& dirname) { return objExistsAsync<&zen::dirExists>(dirname); } - - -template inline -ResultExist objExists(const Zstring& objname, size_t timeout) -{ - auto ft = objExistsAsync(objname); - if (!ft.timed_wait(boost::posix_time::milliseconds(timeout))) - return EXISTING_NOT_READY; - return ft.get() ? EXISTING_TRUE : EXISTING_FALSE; -} - - -inline -ResultExist somethingExists(const Zstring& somename, size_t timeout) { return objExists<&zen::somethingExists>(somename, timeout); } - -inline -ResultExist fileExists(const Zstring& filename, size_t timeout) { return objExists<&zen::fileExists>(filename, timeout); } - -inline -ResultExist dirExists(const Zstring& dirname, size_t timeout) { return objExists<&zen::dirExists>(dirname, timeout); } -} - -#endif // CHECKEXIST_H_INCLUDED -- cgit