icedb
version 0.5.1
Snow particle scattering database API
lib
icedb
util.hpp
Go to the documentation of this file.
1
#pragma once
2
#include "
defs.h
"
3
#include <memory>
4
#include <type_traits>
5
#include <new>
6
//#include <gsl/gsl>
7
8
namespace
icedb
{
10
DL_ICEDB
void
*
_malloc
(
size_t
numBytes);
11
12
template
<
class
T>
13
T*
malloc
(
size_t
numBytes) {
14
T* res =
static_cast<
T*
>
(
_malloc
(numBytes));
15
return
res;
16
}
17
19
DL_ICEDB
void
_free
(
void
* obj);
20
template
<
class
T>
21
void
free
(T* obj) {
22
_free
(static_cast<void*>(obj));
23
}
24
namespace
mem {
25
26
/*
27
void delete_single(gsl::owner<void *>ptr) noexcept;
28
void delete_array(gsl::owner<void *> ptr) noexcept;
29
30
template <class _Ty>
31
struct icedb_delete
32
{
33
constexpr icedb_delete() noexcept = default;
34
35
template<
36
class _Ty2,
37
class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value>::type
38
>
39
icedb_delete(const icedb_delete<_Ty2>&) noexcept
40
{} // construct from another icedb_delete
41
42
void operator()(_Ty *_Ptr) const noexcept
43
{ // delete a pointer
44
static_assert(0 < sizeof(_Ty),
45
"can't delete an incomplete type");
46
//delete _Ptr;
47
::icedb::mem::delete_single(_Ptr);
48
}
49
};
50
51
template<class _Ty>
52
struct icedb_delete<_Ty[]>
53
{ // default deleter for unique_ptr to array of unknown size
54
constexpr icedb_delete() noexcept = default;
55
56
template<class _Uty,
57
class = typename std::enable_if<std::is_convertible<_Uty(*)[], _Ty(*)[]>::value>::type>
58
icedb_delete(const icedb_delete<_Uty[]>&) noexcept
59
{ // construct from another icedb_delete
60
}
61
62
template<class _Uty,
63
class = typename std::enable_if<std::is_convertible<_Uty(*)[], _Ty(*)[]>::value>::type>
64
void operator()(_Uty *_Ptr) const noexcept
65
{ // delete a pointer
66
static_assert(0 < sizeof(_Uty),
67
"can't delete an incomplete type");
68
::icedb::mem::delete_array(_Ptr);
69
}
70
};
71
*/
72
}
73
}
icedb::free
void free(T *obj)
Definition:
util.hpp:21
DL_ICEDB
#define DL_ICEDB
Definition:
defs.h:124
defs.h
icedb::_free
ICEDB_SYMBOL_SHARED void _free(void *obj)
Definition:
util.cpp:130
icedb::malloc
T * malloc(size_t numBytes)
Definition:
util.hpp:13
icedb
Definition:
Attributes.cpp:8
icedb::_malloc
ICEDB_SYMBOL_SHARED void * _malloc(size_t numBytes)
Definition:
util.cpp:129
Generated by
1.8.13