/home/ntakagi/work/STLport-5.1.5/stlport/stl/_new.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Boris Fomitchev
00004  *
00005  * This material is provided "as is", with absolutely no warranty expressed
00006  * or implied. Any use is at your own risk.
00007  *
00008  * Permission to use or copy this software for any purpose is hereby granted
00009  * without fee, provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  *
00014  */
00015 
00016 #ifndef _STLP_INTERNAL_NEW
00017 #define _STLP_INTERNAL_NEW
00018 
00019 #ifndef _STLP_INTERNAL_CSTDDEF
00020 // size_t
00021 #  include <stl/_cstddef.h>
00022 #endif
00023 
00024 #if defined (__BORLANDC__) && (__BORLANDC__ < 0x580)
00025 // new.h uses ::malloc ;(
00026 #  include _STLP_NATIVE_CPP_C_HEADER(cstdlib)
00027 using _STLP_VENDOR_CSTD::malloc;
00028 #endif
00029 
00030 #if !defined (_STLP_NO_NEW_NEW_HEADER)
00031 #  if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
00032 #    define bad_alloc _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
00033 #    define nothrow_t _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
00034 #    define nothrow _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
00035 #  endif
00036 
00037 // eMbedded Visual C++ .NET unfortunately uses _INC_NEW for both <new.h> and <new>
00038 // we undefine the symbol to get the stuff in the SDK's <new>
00039 #  if defined (_STLP_WCE_NET) && defined (_INC_NEW)
00040 #    undef _INC_NEW
00041 #  endif
00042 
00043 #  if defined (new)
00044 /* STLport cannot replace native Std library new header if new is a macro,
00045  * please define new macro after <new> header inclusion.
00046  */
00047 #    error Cannot include native new header as new is a macro.
00048 #  endif
00049 
00050 #  include _STLP_NATIVE_CPP_RUNTIME_HEADER(new)
00051 
00052 #  if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
00053 #    undef bad_alloc
00054 #    undef nothrow_t
00055 #    undef nothrow
00056 #    undef _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
00057 #    undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
00058 #    undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
00059 #  endif
00060 #else
00061 #  include <new.h>
00062 #endif
00063 
00064 #if defined (_STLP_NO_BAD_ALLOC) && !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
00065 #  define _STLP_NEW_DONT_THROW_BAD_ALLOC 1
00066 #endif
00067 
00068 #if defined (_STLP_USE_EXCEPTIONS) && defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
00069 
00070 #  ifndef _STLP_INTERNAL_EXCEPTION
00071 #    include <stl/_exception.h>
00072 #  endif
00073 
00074 _STLP_BEGIN_NAMESPACE
00075 
00076 #  if defined (_STLP_NO_BAD_ALLOC)
00077 struct nothrow_t {};
00078 #    define nothrow nothrow_t()
00079 #  endif
00080 
00081 /*
00082  * STLport own bad_alloc exception to be used if the native C++ library
00083  * do not define it or when the new operator do not throw it to avoid
00084  * a useless library dependency.
00085  */
00086 class bad_alloc : public exception {
00087 public:
00088   bad_alloc () _STLP_NOTHROW_INHERENTLY { }
00089   bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
00090   bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
00091   ~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
00092   const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
00093 };
00094 
00095 _STLP_END_NAMESPACE
00096 
00097 #endif /* _STLP_USE_EXCEPTIONS && (_STLP_NO_BAD_ALLOC || _STLP_NEW_DONT_THROW_BAD_ALLOC) */
00098 
00099 #if defined (_STLP_RTTI_BUG)
00100 _STLP_BEGIN_NAMESPACE
00101 
00102 inline void* _STLP_CALL __stl_new(size_t __n)
00103 { return ::malloc(__n); }
00104 
00105 inline void _STLP_CALL __stl_delete(void* __p)
00106 { ::free(__p); }
00107 _STLP_END_NAMESPACE
00108 
00109 #else /* _STLP_RTTI_BUG */
00110 
00111 #  if defined (_STLP_USE_OWN_NAMESPACE)
00112 
00113 _STLP_BEGIN_NAMESPACE
00114 
00115 #    if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
00116 using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
00117 #    endif
00118 
00119 #    if !defined (_STLP_NO_BAD_ALLOC)
00120 using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
00121 using _STLP_VENDOR_EXCEPT_STD::nothrow;
00122 #      if defined (_STLP_GLOBAL_NEW_HANDLER)
00123 using ::new_handler;
00124 using ::set_new_handler;
00125 #      else
00126 using _STLP_VENDOR_EXCEPT_STD::new_handler;
00127 using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
00128 #      endif
00129 #    endif /* !_STLP_NO_BAD_ALLOC */
00130 
00131 _STLP_END_NAMESPACE
00132 #  endif /* _STLP_USE_OWN_NAMESPACE */
00133 
00134 #  if defined (_STLP_USE_EXCEPTIONS) && \
00135      (defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW_BAD_ALLOC))
00136 #    define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x; if (__y == 0) { _STLP_THROW(_STLP_STD::bad_alloc()); } return __y
00137 #  else
00138 #    define _STLP_CHECK_NULL_ALLOC(__x) return __x
00139 #  endif
00140 
00141 _STLP_BEGIN_NAMESPACE
00142 
00143 #  if ((defined (__IBMCPP__) || defined (__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined (__DEBUG_ALLOC__))
00144 inline void* _STLP_CALL __stl_new(size_t __n)   { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n, __FILE__, __LINE__)); }
00145 inline void  _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
00146 #  else
00147 inline void* _STLP_CALL __stl_new(size_t __n)   { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n)); }
00148 inline void  _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
00149 #  endif
00150 _STLP_END_NAMESPACE
00151 
00152 #endif /* _STLP_RTTI_BUG */
00153 
00154 #endif /* _STLP_INTERNAL_NEW */
00155 
00156 
00157 /*
00158  * Local Variables:
00159  * mode:C++
00160  * End:
00161  */



Generated on Mon Mar 10 15:32:31 2008 by  doxygen 1.5.1