blob: be46e593cae833473c8da0194fab8ff42b715b91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#ifndef guard_unbounded_reference_allocation_traits_hpp
#define guard_unbounded_reference_allocation_traits_hpp
/**
* @file
*
* @brief Details can be found in the documentation for
* TAO::details::generic_sequence
*
* @author Carlos O'Ryan
*/
#include "tao/Basic_Types.h"
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
namespace TAO
{
namespace details
{
template<typename T, class ref_traits, bool dummy>
struct unbounded_reference_allocation_traits
{
typedef T value_type;
typedef ref_traits reference_traits;
inline static CORBA::ULong default_maximum()
{
return 0;
}
inline static value_type * default_buffer_allocation()
{
return 0;
}
inline static value_type * allocbuf(CORBA::ULong maximum)
{
if (maximum == ACE_UINT32_MAX)
{
return 0;
}
value_type * buffer = new value_type[maximum + 1];
reinterpret_cast<value_type**>(buffer)[0] = buffer + maximum + 1;
// no throw
reference_traits::initialize_range(buffer + 1, buffer + maximum + 1);
return buffer + 1;
}
inline static value_type * allocbuf_noinit(CORBA::ULong maximum)
{
if (maximum == ACE_UINT32_MAX)
{
return 0;
}
value_type * buffer = new value_type[maximum + 1];
reinterpret_cast<value_type**>(buffer)[0] = buffer + maximum + 1;
// no throw
reference_traits::zero_range(buffer + 1, buffer + maximum + 1);
return buffer + 1;
}
inline static void freebuf(value_type * buffer)
{
if(buffer != 0)
{
value_type * begin = buffer - 1;
value_type * end = reinterpret_cast<value_type*>(*begin);
reference_traits::release_range(buffer, end);
buffer = begin;
}
delete[] buffer;
}
};
} // namespace details
} // namespace TAO
TAO_END_VERSIONED_NAMESPACE_DECL
#endif // guard_unbounded_reference_allocation_traits_hpp
|