epoc32/include/tools/stlport/stl/_new.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 * Copyright (c) 1999
williamr@4
     3
 * Boris Fomitchev
williamr@4
     4
 *
williamr@4
     5
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
     6
 * or implied. Any use is at your own risk.
williamr@4
     7
 *
williamr@4
     8
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
     9
 * without fee, provided the above notices are retained on all copies.
williamr@4
    10
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    11
 * provided the above notices are retained, and a notice that the code was
williamr@4
    12
 * modified is included with the above copyright notice.
williamr@4
    13
 *
williamr@4
    14
 */
williamr@4
    15
williamr@4
    16
#ifndef _STLP_INTERNAL_NEW
williamr@4
    17
#define _STLP_INTERNAL_NEW
williamr@4
    18
williamr@4
    19
#ifndef _STLP_INTERNAL_CSTDDEF
williamr@4
    20
// size_t
williamr@4
    21
#  include <stl/_cstddef.h>
williamr@4
    22
#endif
williamr@4
    23
williamr@4
    24
#if defined (__BORLANDC__) && (__BORLANDC__ < 0x580)
williamr@4
    25
// new.h uses ::malloc ;(
williamr@4
    26
#  include _STLP_NATIVE_CPP_C_HEADER(cstdlib)
williamr@4
    27
using _STLP_VENDOR_CSTD::malloc;
williamr@4
    28
#endif
williamr@4
    29
williamr@4
    30
#if !defined (_STLP_NO_NEW_NEW_HEADER)
williamr@4
    31
#  if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
williamr@4
    32
#    define bad_alloc _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
williamr@4
    33
#    define nothrow_t _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
williamr@4
    34
#    define nothrow _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
williamr@4
    35
#  endif
williamr@4
    36
williamr@4
    37
// eMbedded Visual C++ .NET unfortunately uses _INC_NEW for both <new.h> and <new>
williamr@4
    38
// we undefine the symbol to get the stuff in the SDK's <new>
williamr@4
    39
#  if defined (_STLP_WCE_NET) && defined (_INC_NEW)
williamr@4
    40
#    undef _INC_NEW
williamr@4
    41
#  endif
williamr@4
    42
williamr@4
    43
#  if defined (new)
williamr@4
    44
/* STLport cannot replace native Std library new header if new is a macro,
williamr@4
    45
 * please define new macro after <new> header inclusion.
williamr@4
    46
 */
williamr@4
    47
#    error Cannot include native new header as new is a macro.
williamr@4
    48
#  endif
williamr@4
    49
williamr@4
    50
#  include _STLP_NATIVE_CPP_RUNTIME_HEADER(new)
williamr@4
    51
williamr@4
    52
#  if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
williamr@4
    53
#    undef bad_alloc
williamr@4
    54
#    undef nothrow_t
williamr@4
    55
#    undef nothrow
williamr@4
    56
#    undef _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
williamr@4
    57
#    undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
williamr@4
    58
#    undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
williamr@4
    59
#  endif
williamr@4
    60
#else
williamr@4
    61
#  include <new.h>
williamr@4
    62
#endif
williamr@4
    63
williamr@4
    64
#if defined (_STLP_NO_BAD_ALLOC) && !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
williamr@4
    65
#  define _STLP_NEW_DONT_THROW_BAD_ALLOC 1
williamr@4
    66
#endif
williamr@4
    67
williamr@4
    68
#if defined (_STLP_USE_EXCEPTIONS) && defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
williamr@4
    69
williamr@4
    70
#  ifndef _STLP_INTERNAL_EXCEPTION
williamr@4
    71
#    include <stl/_exception.h>
williamr@4
    72
#  endif
williamr@4
    73
williamr@4
    74
_STLP_BEGIN_NAMESPACE
williamr@4
    75
williamr@4
    76
#  if defined (_STLP_NO_BAD_ALLOC)
williamr@4
    77
struct nothrow_t {};
williamr@4
    78
#    define nothrow nothrow_t()
williamr@4
    79
#  endif
williamr@4
    80
williamr@4
    81
/*
williamr@4
    82
 * STLport own bad_alloc exception to be used if the native C++ library
williamr@4
    83
 * do not define it or when the new operator do not throw it to avoid
williamr@4
    84
 * a useless library dependency.
williamr@4
    85
 */
williamr@4
    86
class bad_alloc : public exception {
williamr@4
    87
public:
williamr@4
    88
  bad_alloc () _STLP_NOTHROW_INHERENTLY { }
williamr@4
    89
  bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
williamr@4
    90
  bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
williamr@4
    91
  ~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
williamr@4
    92
  const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
williamr@4
    93
};
williamr@4
    94
williamr@4
    95
_STLP_END_NAMESPACE
williamr@4
    96
williamr@4
    97
#endif /* _STLP_USE_EXCEPTIONS && (_STLP_NO_BAD_ALLOC || _STLP_NEW_DONT_THROW_BAD_ALLOC) */
williamr@4
    98
williamr@4
    99
#if defined (_STLP_RTTI_BUG)
williamr@4
   100
_STLP_BEGIN_NAMESPACE
williamr@4
   101
williamr@4
   102
inline void* _STLP_CALL __stl_new(size_t __n)
williamr@4
   103
{ return ::malloc(__n); }
williamr@4
   104
williamr@4
   105
inline void _STLP_CALL __stl_delete(void* __p)
williamr@4
   106
{ ::free(__p); }
williamr@4
   107
_STLP_END_NAMESPACE
williamr@4
   108
williamr@4
   109
#else /* _STLP_RTTI_BUG */
williamr@4
   110
williamr@4
   111
#  if defined (_STLP_USE_OWN_NAMESPACE)
williamr@4
   112
williamr@4
   113
_STLP_BEGIN_NAMESPACE
williamr@4
   114
williamr@4
   115
#    if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
williamr@4
   116
using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
williamr@4
   117
#    endif
williamr@4
   118
williamr@4
   119
#    if !defined (_STLP_NO_BAD_ALLOC)
williamr@4
   120
using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
williamr@4
   121
using _STLP_VENDOR_EXCEPT_STD::nothrow;
williamr@4
   122
#      if defined (_STLP_GLOBAL_NEW_HANDLER)
williamr@4
   123
using ::new_handler;
williamr@4
   124
using ::set_new_handler;
williamr@4
   125
#      else
williamr@4
   126
using _STLP_VENDOR_EXCEPT_STD::new_handler;
williamr@4
   127
using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
williamr@4
   128
#      endif
williamr@4
   129
#    endif /* !_STLP_NO_BAD_ALLOC */
williamr@4
   130
williamr@4
   131
_STLP_END_NAMESPACE
williamr@4
   132
#  endif /* _STLP_USE_OWN_NAMESPACE */
williamr@4
   133
williamr@4
   134
#  if defined (_STLP_USE_EXCEPTIONS) && \
williamr@4
   135
     (defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW_BAD_ALLOC))
williamr@4
   136
#    define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x; if (__y == 0) { _STLP_THROW(_STLP_STD::bad_alloc()); } return __y
williamr@4
   137
#  else
williamr@4
   138
#    define _STLP_CHECK_NULL_ALLOC(__x) return __x
williamr@4
   139
#  endif
williamr@4
   140
williamr@4
   141
_STLP_BEGIN_NAMESPACE
williamr@4
   142
williamr@4
   143
#  if ((defined (__IBMCPP__) || defined (__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined (__DEBUG_ALLOC__))
williamr@4
   144
inline void* _STLP_CALL __stl_new(size_t __n)   { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n, __FILE__, __LINE__)); }
williamr@4
   145
inline void  _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
williamr@4
   146
#  else
williamr@4
   147
inline void* _STLP_CALL __stl_new(size_t __n)   { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n)); }
williamr@4
   148
inline void  _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
williamr@4
   149
#  endif
williamr@4
   150
_STLP_END_NAMESPACE
williamr@4
   151
williamr@4
   152
#endif /* _STLP_RTTI_BUG */
williamr@4
   153
williamr@4
   154
#endif /* _STLP_INTERNAL_NEW */
williamr@4
   155
williamr@4
   156
williamr@4
   157
/*
williamr@4
   158
 * Local Variables:
williamr@4
   159
 * mode:C++
williamr@4
   160
 * End:
williamr@4
   161
 */