Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Unbounded_Reference_Allocation_Traits_T.h
blobcd0a1e650cfec75fe0e49847b5b54626ea519d5f
1 #ifndef guard_unbounded_reference_allocation_traits_hpp
2 #define guard_unbounded_reference_allocation_traits_hpp
3 /**
4 * @file
6 * @brief Details can be found in the documentation for
7 * TAO::details::generic_sequence
9 * @author Carlos O'Ryan
12 #include "tao/Basic_Types.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 namespace TAO
18 namespace details
20 template<typename T, class ref_traits, bool dummy>
21 struct unbounded_reference_allocation_traits
23 typedef T value_type;
24 typedef ref_traits reference_traits;
26 inline static CORBA::ULong default_maximum()
28 return 0;
31 inline static value_type * default_buffer_allocation()
33 return 0;
36 inline static value_type * allocbuf(CORBA::ULong maximum)
38 if (maximum == ACE_UINT32_MAX)
40 return 0;
42 value_type * buffer = new value_type[maximum + 1];
43 reinterpret_cast<value_type**>(buffer)[0] = buffer + maximum + 1;
45 // no throw
46 reference_traits::initialize_range(buffer + 1, buffer + maximum + 1);
48 return buffer + 1;
51 inline static value_type * allocbuf_noinit(CORBA::ULong maximum)
53 if (maximum == ACE_UINT32_MAX)
55 return 0;
57 value_type * buffer = new value_type[maximum + 1];
58 reinterpret_cast<value_type**>(buffer)[0] = buffer + maximum + 1;
60 // no throw
61 reference_traits::zero_range(buffer + 1, buffer + maximum + 1);
63 return buffer + 1;
66 inline static void freebuf(value_type * buffer)
68 if(buffer != 0)
70 value_type * begin = buffer - 1;
71 value_type * end = reinterpret_cast<value_type*>(*begin);
72 reference_traits::release_range(buffer, end);
74 buffer = begin;
76 delete[] buffer;
79 } // namespace details
80 } // namespace TAO
82 TAO_END_VERSIONED_NAMESPACE_DECL
84 #endif // guard_unbounded_reference_allocation_traits_hpp