2012-11-06 14:17:32 +00:00
|
|
|
/*
|
2012-12-03 05:56:17 +00:00
|
|
|
* Copyright (c) 2012 Glen Joseph Fernandes
|
2012-11-06 14:17:32 +00:00
|
|
|
* glenfe at live dot com
|
|
|
|
*
|
2012-12-03 05:56:17 +00:00
|
|
|
* Distributed under the Boost Software License,
|
|
|
|
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
2012-11-06 14:17:32 +00:00
|
|
|
* or copy at http://boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP
|
|
|
|
#define BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP
|
|
|
|
|
2012-12-07 01:53:35 +00:00
|
|
|
#include <boost/smart_ptr/detail/array_utility.hpp>
|
|
|
|
#include <boost/smart_ptr/detail/sp_forward.hpp>
|
2012-11-06 14:17:32 +00:00
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
2012-11-28 07:32:30 +00:00
|
|
|
class array_deleter;
|
|
|
|
template<typename T>
|
|
|
|
class array_deleter<T[]> {
|
2012-11-06 14:17:32 +00:00
|
|
|
public:
|
2012-12-03 05:56:17 +00:00
|
|
|
array_deleter(std::size_t size)
|
2012-12-02 22:05:31 +00:00
|
|
|
: size(size),
|
|
|
|
object(0) {
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
~array_deleter() {
|
2012-12-07 01:53:35 +00:00
|
|
|
if (object) {
|
|
|
|
array_destroy(object, size);
|
|
|
|
}
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
2012-12-02 22:05:31 +00:00
|
|
|
void construct(T* memory) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct(memory, size);
|
|
|
|
object = memory;
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
2012-12-04 06:06:23 +00:00
|
|
|
#if defined(BOOST_HAS_RVALUE_REFS)
|
|
|
|
void construct(T* memory, T&& value) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct(memory, size, value);
|
|
|
|
object = memory;
|
2012-12-04 06:06:23 +00:00
|
|
|
}
|
|
|
|
#if defined(BOOST_HAS_VARIADIC_TMPL)
|
2012-11-06 14:17:32 +00:00
|
|
|
template<typename... Args>
|
2012-12-02 22:05:31 +00:00
|
|
|
void construct(T* memory, Args&&... args) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct(memory, size, args...);
|
|
|
|
object = memory;
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
2012-12-04 06:06:23 +00:00
|
|
|
#endif
|
2012-11-09 06:17:05 +00:00
|
|
|
#endif
|
2012-12-02 22:05:31 +00:00
|
|
|
void construct_list(T* memory, const T* list) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct_list(memory, size, list);
|
|
|
|
object = memory;
|
2012-11-09 06:17:05 +00:00
|
|
|
}
|
2012-12-02 22:05:31 +00:00
|
|
|
void construct_list(T* memory, const T* list, std::size_t n) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct_list(memory, size, list, n);
|
|
|
|
object = memory;
|
2012-11-10 01:33:29 +00:00
|
|
|
}
|
2012-12-02 22:05:31 +00:00
|
|
|
void construct_noinit(T* memory) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct_noinit(memory, size);
|
|
|
|
object = memory;
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
2012-11-07 18:37:17 +00:00
|
|
|
void operator()(const void*) {
|
2012-12-02 22:05:31 +00:00
|
|
|
if (object) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_destroy(object, size);
|
2012-12-02 22:05:31 +00:00
|
|
|
object = 0;
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-07 01:53:35 +00:00
|
|
|
private:
|
2012-11-06 14:17:32 +00:00
|
|
|
std::size_t size;
|
|
|
|
T* object;
|
|
|
|
};
|
2012-11-28 06:07:45 +00:00
|
|
|
template<typename T, std::size_t N>
|
|
|
|
class array_deleter<T[N]> {
|
|
|
|
public:
|
2012-12-03 05:56:17 +00:00
|
|
|
array_deleter()
|
2012-11-28 06:07:45 +00:00
|
|
|
: object(0) {
|
|
|
|
}
|
|
|
|
~array_deleter() {
|
2012-12-07 01:53:35 +00:00
|
|
|
if (object) {
|
|
|
|
array_destroy(object, N);
|
|
|
|
}
|
2012-11-28 06:07:45 +00:00
|
|
|
}
|
|
|
|
void construct(T* memory) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct(memory, N);
|
|
|
|
object = memory;
|
2012-11-28 06:07:45 +00:00
|
|
|
}
|
2012-12-04 06:06:23 +00:00
|
|
|
#if defined(BOOST_HAS_RVALUE_REFS)
|
|
|
|
void construct(T* memory, T&& value) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct(memory, N, value);
|
|
|
|
object = memory;
|
2012-12-04 06:06:23 +00:00
|
|
|
}
|
|
|
|
#if defined(BOOST_HAS_VARIADIC_TMPL)
|
2012-11-28 06:07:45 +00:00
|
|
|
template<typename... Args>
|
|
|
|
void construct(T* memory, Args&&... args) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct(memory, N, args...);
|
|
|
|
object = memory;
|
2012-11-28 06:07:45 +00:00
|
|
|
}
|
2012-12-04 06:06:23 +00:00
|
|
|
#endif
|
2012-11-28 06:07:45 +00:00
|
|
|
#endif
|
|
|
|
void construct_list(T* memory, const T* list) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct_list(memory, N, list);
|
|
|
|
object = memory;
|
2012-11-28 06:07:45 +00:00
|
|
|
}
|
|
|
|
void construct_list(T* memory, const T* list, std::size_t n) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct_list(memory, N, list, n);
|
|
|
|
object = memory;
|
2012-11-28 06:07:45 +00:00
|
|
|
}
|
|
|
|
void construct_noinit(T* memory) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_construct_noinit(memory, N);
|
|
|
|
object = memory;
|
2012-11-28 06:07:45 +00:00
|
|
|
}
|
|
|
|
void operator()(const void*) {
|
|
|
|
if (object) {
|
2012-12-07 01:53:35 +00:00
|
|
|
array_destroy(object, N);
|
2012-11-28 06:07:45 +00:00
|
|
|
object = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-12-07 01:53:35 +00:00
|
|
|
private:
|
2012-11-28 06:07:45 +00:00
|
|
|
T* object;
|
|
|
|
};
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|