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/c_dll.h | 131 --------------------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 shared/c_dll.h (limited to 'shared/c_dll.h') diff --git a/shared/c_dll.h b/shared/c_dll.h deleted file mode 100644 index 15597a9c..00000000 --- a/shared/c_dll.h +++ /dev/null @@ -1,131 +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 C_DLL_HEADER -#define C_DLL_HEADER - -#include -#include -#include - - -namespace c_dll -{ -void writeString(const std::wstring& input, wchar_t* output, size_t outputLen); - - -//Convert handles to objects and vice versa -template //T: prefer managed object to ensure cleanup if remove() is not called -class HandleProvider -{ -public: - static HandleProvider& instance(); - S insert(T object); - void remove(S handle); - T& retrieve(S handle); //return default-constructed object if not found - -private: - HandleProvider() {} - HandleProvider(const HandleProvider&); - HandleProvider& operator=(const HandleProvider&); - S generate(); - - std::map handleMap; -}; -/* -Example: - typedef HandleProvider > HandleTaskbarMap; - HandleTaskbarMap::instance().insert(xyz); -*/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//########################## inline implementation ############################# -inline -void writeString(const std::wstring& input, wchar_t* output, size_t outputLen) -{ - if (outputLen > 0) - { - const size_t maxSize = std::min(input.length(), outputLen - 1); - std::copy(input.begin(), input.begin() + maxSize, output); - output[maxSize] = 0; - } -} - - -template -inline -HandleProvider& HandleProvider::instance() -{ - static HandleProvider inst; //external linkage!!! :) - return inst; -} - - -//convert handles to objects and vice versa -template -inline -S HandleProvider::insert(T object) -{ - S newHandle = generate(); - handleMap.insert(std::make_pair(newHandle, object)); - return newHandle; -} - - -template -inline -void HandleProvider::remove(S handle) -{ - handleMap.erase(handle); -} - - -template -inline -T& HandleProvider::retrieve(S handle) //return default-constructed object if not found -{ - return handleMap[handle]; -} - - -template -inline -S HandleProvider::generate() -{ - static S handle = 0; - return ++handle; //don't return 0! 0 is reserved for indicating failure -} - - -} - -#endif //C_DLL_HEADER \ No newline at end of file -- cgit