diff options
Diffstat (limited to 'Swiften/Base/SafeAllocator.h')
-rw-r--r-- | Swiften/Base/SafeAllocator.h | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/Swiften/Base/SafeAllocator.h b/Swiften/Base/SafeAllocator.h index b01d77d..d47bb02 100644 --- a/Swiften/Base/SafeAllocator.h +++ b/Swiften/Base/SafeAllocator.h @@ -1,34 +1,36 @@ /* - * Copyright (c) 2011-2013 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <vector> #include <algorithm> +#include <vector> + +#include <Swiften/Base/API.h> namespace Swift { - void secureZeroMemory(char* memory, size_t numberOfBytes); - - template<typename T> - class SafeAllocator : public std::allocator<T> { - public: - template <class U> struct rebind { - typedef SafeAllocator<U> other; - }; - - SafeAllocator() throw() {} - SafeAllocator(const SafeAllocator&) throw() : std::allocator<T>() {} - template <class U> SafeAllocator(const SafeAllocator<U>&) throw() {} - ~SafeAllocator() throw() {} - - void deallocate (T* p, size_t num) { - secureZeroMemory(reinterpret_cast<char*>(p), num); - std::allocator<T>::deallocate(p, num); - } - - private: - }; + SWIFTEN_API void secureZeroMemory(char* memory, size_t numberOfBytes); + + template<typename T> + class SWIFTEN_API SafeAllocator : public std::allocator<T> { + public: + template <class U> struct rebind { + typedef SafeAllocator<U> other; + }; + + SafeAllocator() SWIFTEN_NOEXCEPT {} + SafeAllocator(const SafeAllocator&) SWIFTEN_NOEXCEPT : std::allocator<T>() {} + template <class U> SafeAllocator(const SafeAllocator<U>&) SWIFTEN_NOEXCEPT {} + ~SafeAllocator() SWIFTEN_NOEXCEPT {} + + void deallocate (T* p, size_t num) { + secureZeroMemory(reinterpret_cast<char*>(p), num); + std::allocator<T>::deallocate(p, num); + } + + SWIFTEN_DEFAULT_COPY_ASSIGMNENT_OPERATOR(SafeAllocator) + }; } |