00001 #ifndef guard_unbounded_reference_allocation_traits_hpp 00002 #define guard_unbounded_reference_allocation_traits_hpp 00003 /** 00004 * @file 00005 * 00006 * @brief Details can be found in the documentation for 00007 * TAO::details::generic_sequence 00008 * 00009 * $Id: Unbounded_Reference_Allocation_Traits_T.h 72136 2006-04-19 09:10:19Z jwillemsen $ 00010 * 00011 * @author Carlos O'Ryan 00012 */ 00013 00014 #include "tao/Basic_Types.h" 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace TAO 00019 { 00020 namespace details 00021 { 00022 00023 template<typename T, class ref_traits, bool dummy> 00024 struct unbounded_reference_allocation_traits 00025 { 00026 typedef T value_type; 00027 typedef ref_traits reference_traits; 00028 00029 inline static CORBA::ULong default_maximum() 00030 { 00031 return 0; 00032 } 00033 00034 inline static value_type * default_buffer_allocation() 00035 { 00036 return 0; 00037 } 00038 00039 inline static value_type * allocbuf(CORBA::ULong maximum) 00040 { 00041 value_type * buffer = new value_type[maximum + 1]; 00042 reinterpret_cast<value_type**>(buffer)[0] = buffer + maximum + 1; 00043 00044 // no throw 00045 reference_traits::zero_range(buffer + 1, buffer + maximum + 1); 00046 00047 return buffer + 1; 00048 } 00049 00050 inline static void freebuf(value_type * buffer) 00051 { 00052 if(buffer != 0) 00053 { 00054 value_type * begin = buffer - 1; 00055 value_type * end = reinterpret_cast<value_type*>(*begin); 00056 reference_traits::release_range(buffer, end); 00057 00058 buffer = begin; 00059 } 00060 delete[] buffer; 00061 } 00062 }; 00063 00064 } // namespace details 00065 } // namespace TAO 00066 00067 TAO_END_VERSIONED_NAMESPACE_DECL 00068 00069 #endif // guard_unbounded_reference_allocation_traits_hpp